Class: Nobel::Country
- Inherits:
-
Object
- Object
- Nobel::Country
- Defined in:
- lib/nobel/country.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Country
constructor
A new instance of Country.
Constructor Details
#initialize(data) ⇒ Country
Returns a new instance of Country.
33 34 35 36 37 38 |
# File 'lib/nobel/country.rb', line 33 def initialize(data) data ||= { 'code' => 'ZZ', 'name' => 'Unknown' } @name = data['name'] @code = data['code'] end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
31 32 33 |
# File 'lib/nobel/country.rb', line 31 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/nobel/country.rb', line 31 def name @name end |
Class Method Details
.all ⇒ Object
6 7 8 |
# File 'lib/nobel/country.rb', line 6 def all data.map { |c| new(c) } end |
.data ⇒ Object
15 16 17 |
# File 'lib/nobel/country.rb', line 15 def data @data ||= get_data end |
.find(value, key = 'code') ⇒ Object
10 11 12 13 |
# File 'lib/nobel/country.rb', line 10 def find(value, key = 'code') value = key == 'code' ? value.to_s.upcase : value.to_s new data.detect { |c| c[key.to_s] == value } end |
.reload! ⇒ Object
19 20 21 22 |
# File 'lib/nobel/country.rb', line 19 def reload! @data = get_data self end |