Class: Coder::Country
- Inherits:
-
Object
- Object
- Coder::Country
- Defined in:
- lib/countries/country.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#name ⇒ Object
Returns the value of attribute name.
-
#states ⇒ Object
Returns the value of attribute states.
Instance Method Summary collapse
- #[](_code) ⇒ Object
-
#initialize(args) ⇒ Country
constructor
A new instance of Country.
- #load_yaml ⇒ Object
- #to_s ⇒ Object
- #yaml_file_name ⇒ Object
Constructor Details
#initialize(args) ⇒ Country
5 6 7 8 9 10 |
# File 'lib/countries/country.rb', line 5 def initialize(args) self.code = args[:code].to_s self.name = args[:name] self.load_yaml end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
3 4 5 |
# File 'lib/countries/country.rb', line 3 def code @code end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/countries/country.rb', line 3 def name @name end |
#states ⇒ Object
Returns the value of attribute states.
3 4 5 |
# File 'lib/countries/country.rb', line 3 def states @states end |
Instance Method Details
#[](_code) ⇒ Object
20 21 22 23 24 |
# File 'lib/countries/country.rb', line 20 def [](_code) _code = _code.to_s.upcase.to_sym state = states[_code] Coder::State.new(:code => _code.to_s, :name => state) end |
#load_yaml ⇒ Object
12 13 14 |
# File 'lib/countries/country.rb', line 12 def load_yaml self.states = YAML.load_file(yaml_file_name) end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/countries/country.rb', line 26 def to_s name end |
#yaml_file_name ⇒ Object
16 17 18 |
# File 'lib/countries/country.rb', line 16 def yaml_file_name "#{File.dirname(__FILE__)}/../i18n/states/#{code.downcase}/#{Coder.i18n}.yml" end |