Class: Decoder::Country
- Inherits:
-
Object
- Object
- Decoder::Country
- Includes:
- CommonMethods
- Defined in:
- lib/decoder/country.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #[](_code) ⇒ Object
- #by_fips(fips) ⇒ Object
-
#initialize(args) ⇒ Country
constructor
A new instance of Country.
- #states ⇒ Object (also: #counties, #provinces, #territories)
- #states=(_states) ⇒ Object
Methods included from CommonMethods
Constructor Details
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/decoder/country.rb', line 6 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/decoder/country.rb', line 6 def name @name end |
Instance Method Details
#[](_code) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/decoder/country.rb', line 26 def [](_code) _code = _code.to_s.upcase state = states[_code] if state.is_a?(Array) fips = state.last state = state.first end Decoder::State.new(:code => _code, :name => state, :fips => fips) end |
#by_fips(fips) ⇒ Object
36 37 38 39 40 |
# File 'lib/decoder/country.rb', line 36 def by_fips(fips) fips = fips.to_s state = states.detect { |k,v| v.include?(fips) if v.is_a?(Array) } self[state.first] end |
#states ⇒ Object Also known as: counties, provinces, territories
14 15 16 |
# File 'lib/decoder/country.rb', line 14 def states @states end |
#states=(_states) ⇒ Object
18 19 20 |
# File 'lib/decoder/country.rb', line 18 def states=(_states) @states = _states end |