Class: Decoder::Country

Inherits:
Object
  • Object
show all
Includes:
CommonMethods
Defined in:
lib/decoder/country.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommonMethods

#inspect, #to_s

Constructor Details

#initialize(args) ⇒ Country

Returns a new instance of Country.



6
7
8
9
10
# File 'lib/decoder/country.rb', line 6

def initialize(args)
  self.code   = args[:code].to_s
  self.name   = args[:name]
  self.states = Decoder.locale[Decoder.i18n][self.code][:states]
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/decoder/country.rb', line 4

def code
  @code
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/decoder/country.rb', line 4

def name
  @name
end

Instance Method Details

#[](_code) ⇒ Object



24
25
26
27
28
# File 'lib/decoder/country.rb', line 24

def [](_code)
  _code = _code.to_s.upcase
  state = states[_code]
  Decoder::State.new(:code => _code, :name => state)
end

#statesObject Also known as: counties, provinces, territories



12
13
14
# File 'lib/decoder/country.rb', line 12

def states
  @states
end

#states=(_states) ⇒ Object



16
17
18
# File 'lib/decoder/country.rb', line 16

def states=(_states)
  @states = _states
end