Class: SwissMatch::Name

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

Overview

Adds a couple of properties to the String class. These properties are relevant to the naming of Cantons, Communities and ZipCodes. They provide information about the language in which the name is, and which sequence number that name has.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, language, sequence_number = 0) ⇒ Name

Returns a new instance of Name

Parameters:

  • name (String)

    The name (self)

  • language (Symbol)

    The language this name is in (:de, :fr, :it or :rt)

  • sequence_number (Integer) (defaults to: 0)

    The sequence number of this name



25
26
27
28
29
# File 'lib/swissmatch/name.rb', line 25

def initialize(name, language, sequence_number=0)
  @language         = language
  @sequence_number  = sequence_number
  super(name.to_s)
end

Instance Attribute Details

#languageSymbol (readonly)

Returns The language of this name (:de, :fr, :it or :rt)

Returns:

  • (Symbol)

    The language of this name (:de, :fr, :it or :rt)



17
18
19
# File 'lib/swissmatch/name.rb', line 17

def language
  @language
end

#sequence_numberInteger (readonly)

Returns The sequence number of this name

Returns:

  • (Integer)

    The sequence number of this name



14
15
16
# File 'lib/swissmatch/name.rb', line 14

def sequence_number
  @sequence_number
end

Instance Method Details

#inspectObject

See Also:

  • Object#inspect


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

def inspect
  "#{super}(#{@language}, #{@sequence_number})"
end

#to_aObject



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

def to_a
  [to_s, @language, @sequence_number]
end

#to_hashHash

Returns All properties of the name as a hash.

Returns:

  • (Hash)

    All properties of the name as a hash.



33
34
35
36
37
38
39
# File 'lib/swissmatch/name.rb', line 33

def to_hash
  {
    :name             => to_s,
    :language         => @language,
    :sequence_number  => @sequence_number,
  }
end