Class: Nobel::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/nobel/country.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



31
32
33
# File 'lib/nobel/country.rb', line 31

def code
  @code
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/nobel/country.rb', line 31

def name
  @name
end

Class Method Details

.allObject



6
7
8
# File 'lib/nobel/country.rb', line 6

def all
  data.map { |c| new(c) }
end

.dataObject



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