Class: SwissMatch::Canton

Inherits:
Object
  • Object
show all
Defined in:
lib/swissmatch/canton.rb

Overview

Represents a swiss canton.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Canton) initialize(license_tag, name, name_de, name_fr, name_it, name_rt)



26
27
28
29
30
31
32
33
34
35
# File 'lib/swissmatch/canton.rb', line 26

def initialize(license_tag, name, name_de, name_fr, name_it, name_rt)
  @license_tag  = license_tag
  @name         = name
  @names        = {
    :de => name_de,
    :fr => name_fr,
    :it => name_it,
    :rt => name_rt,
  }
end

Instance Attribute Details

- (String) license_tag (readonly)



12
13
14
# File 'lib/swissmatch/canton.rb', line 12

def license_tag
  @license_tag
end

Instance Method Details

- (Boolean) eql?(other)

See Also:

  • Object#eql?


74
75
76
# File 'lib/swissmatch/canton.rb', line 74

def eql?(other)
  self.class == other.class && @license_tag == other.license_tag
end

- (Object) hash

See Also:

  • Object#hash


68
69
70
# File 'lib/swissmatch/canton.rb', line 68

def hash
  [self.class, @license_tag].hash
end

- (String) inspect

See Also:

  • Object#inspect


80
81
82
# File 'lib/swissmatch/canton.rb', line 80

def inspect
  sprintf "\#<%s:%014x %s>", self.class, object_id, self
end

- (Object) name(language = nil) Also known as: to_s

The name of the canton. If no language is passed, the local language is used.



41
42
43
# File 'lib/swissmatch/canton.rb', line 41

def name(language=nil)
  language ? @names[language] : @name
end

- (Array<String>) names



47
48
49
# File 'lib/swissmatch/canton.rb', line 47

def names
  @names.values.uniq
end

- (Hash) to_hash



53
54
55
56
57
58
59
60
61
62
# File 'lib/swissmatch/canton.rb', line 53

def to_hash
  {
    :name         => @name,
    :name_de      => @names[:de],
    :name_fr      => @names[:fr],
    :name_it      => @names[:it],
    :name_rt      => @names[:rt],
    :license_tag  => @license_tag
  }
end