Class: SwissMatch::Canton
- Inherits:
-
Object
- Object
- SwissMatch::Canton
- Defined in:
- lib/swissmatch/canton.rb
Overview
Represents a swiss canton.
Instance Attribute Summary collapse
-
#license_tag ⇒ String
readonly
The two letter abbreviation of the cantons name as used on license plates.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(license_tag, name, name_de, name_fr, name_it, name_rt) ⇒ Canton
constructor
A new instance of Canton.
- #inspect ⇒ String
-
#name(language = nil) ⇒ Object
(also: #to_s)
The name of the canton.
-
#names ⇒ Array<String>
The name of this zip code in all languages (only unique names).
-
#to_hash ⇒ Hash
All properties of the canton as a hash.
Constructor Details
#initialize(license_tag, name, name_de, name_fr, name_it, name_rt) ⇒ Canton
Returns a new instance of Canton.
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
#license_tag ⇒ String (readonly)
Returns The two letter abbreviation of the cantons name as used on license plates.
12 13 14 |
# File 'lib/swissmatch/canton.rb', line 12 def license_tag @license_tag end |
Instance Method Details
#eql?(other) ⇒ Boolean
74 75 76 |
# File 'lib/swissmatch/canton.rb', line 74 def eql?(other) self.class == other.class && @license_tag == other.license_tag end |
#hash ⇒ Object
68 69 70 |
# File 'lib/swissmatch/canton.rb', line 68 def hash [self.class, @license_tag].hash end |
#inspect ⇒ String
80 81 82 |
# File 'lib/swissmatch/canton.rb', line 80 def inspect sprintf "\#<%s:%014x %s>", self.class, object_id, self end |
#name(language = nil) ⇒ Object 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 |
#names ⇒ Array<String>
Returns The name of this zip code in all languages (only unique names).
47 48 49 |
# File 'lib/swissmatch/canton.rb', line 47 def names @names.values.uniq end |
#to_hash ⇒ Hash
Returns All properties of the canton as a 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 |