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)

Returns a new instance of Canton

Parameters:

  • license_tag (String)

    The two letter abbreviation of the cantons name as used on license plates.

  • name (String)

    The official name of the canton in the local language.

  • name_de (String)

    The official name of the canton in german.

  • name_fr (String)

    The official name of the canton in french.

  • name_it (String)

    The official name of the canton in italian.

  • name_rt (String)

    The official name of the canton in rhaeto-romanic.



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)

Returns The two letter abbreviation of the cantons name as used on license plates.

Returns:

  • (String)

    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

- (Boolean) eql?(other)

Returns:

  • (Boolean)

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

Returns:

  • (String)

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.

Parameters:

  • language (Symbol, nil) (defaults to: nil)

    One of nil, :de, :fr, :it or :rt



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

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

- (Array<String>) names

Returns The name of this zip code in all languages (only unique names)

Returns:

  • (Array<String>)

    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

- (Hash) to_hash

Returns All properties of the canton as a hash.

Returns:

  • (Hash)

    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