Class: Nobel::Laureate
- Inherits:
-
Object
- Object
- Nobel::Laureate
- Defined in:
- lib/nobel/laureate.rb
Instance Attribute Summary collapse
-
#born ⇒ Object
readonly
Returns the value of attribute born.
-
#born_city ⇒ Object
readonly
Returns the value of attribute born_city.
-
#born_country ⇒ Object
readonly
Returns the value of attribute born_country.
-
#born_country_code ⇒ Object
readonly
Returns the value of attribute born_country_code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#died ⇒ Object
readonly
Returns the value of attribute died.
-
#died_city ⇒ Object
readonly
Returns the value of attribute died_city.
-
#died_country ⇒ Object
readonly
Returns the value of attribute died_country.
-
#died_country_code ⇒ Object
readonly
Returns the value of attribute died_country_code.
-
#firstname ⇒ Object
readonly
Returns the value of attribute firstname.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#motivation ⇒ Object
readonly
Returns the value of attribute motivation.
-
#share ⇒ Object
readonly
Returns the value of attribute share.
-
#surname ⇒ Object
readonly
Returns the value of attribute surname.
Class Method Summary collapse
Instance Method Summary collapse
- #categories ⇒ Object
-
#initialize(data) ⇒ Laureate
constructor
A new instance of Laureate.
- #name ⇒ Object
- #prizes ⇒ Object
- #reload! ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize(data) ⇒ Laureate
Returns a new instance of Laureate.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nobel/laureate.rb', line 28 def initialize(data) @data = data || {} year_regex = /^\d{4}-[0-1][1-9]-\d{2}$/ @data.tap do |d| @id = Integer(d['id']) @firstname = d['firstname'] @surname = d['surname'] @share = Integer(d['share']) if d['share'] @motivation = d['motivation'] if d['motivation'] @born = Date.parse d['born'] if d['born'] =~ year_regex @born_city = d['bornCity'] if d['bornCity'] @born_country = d['bornCountry'] if d['bornCountry'] @born_country_code = d['bornCountryCode'] if d['bornCountryCode'] @died = Date.parse d['died'] if d['died'] =~ year_regex @died_city = d['diedCity'] if d['diedCity'] @died_country = d['diedCountry'] if d['diedCountry'] @died_country_code = d['diedCountryCode'] if d['diedCountryCode'] end end |
Instance Attribute Details
#born ⇒ Object (readonly)
Returns the value of attribute born.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def born @born end |
#born_city ⇒ Object (readonly)
Returns the value of attribute born_city.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def born_city @born_city end |
#born_country ⇒ Object (readonly)
Returns the value of attribute born_country.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def born_country @born_country end |
#born_country_code ⇒ Object (readonly)
Returns the value of attribute born_country_code.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def born_country_code @born_country_code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def data @data end |
#died ⇒ Object (readonly)
Returns the value of attribute died.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def died @died end |
#died_city ⇒ Object (readonly)
Returns the value of attribute died_city.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def died_city @died_city end |
#died_country ⇒ Object (readonly)
Returns the value of attribute died_country.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def died_country @died_country end |
#died_country_code ⇒ Object (readonly)
Returns the value of attribute died_country_code.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def died_country_code @died_country_code end |
#firstname ⇒ Object (readonly)
Returns the value of attribute firstname.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def firstname @firstname end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def id @id end |
#motivation ⇒ Object (readonly)
Returns the value of attribute motivation.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def motivation @motivation end |
#share ⇒ Object (readonly)
Returns the value of attribute share.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def share @share end |
#surname ⇒ Object (readonly)
Returns the value of attribute surname.
24 25 26 |
# File 'lib/nobel/laureate.rb', line 24 def surname @surname end |
Class Method Details
.all(params = {}) ⇒ Object Also known as: query
13 14 15 |
# File 'lib/nobel/laureate.rb', line 13 def all(params = {}) get_data(params).map { |c| new(c) } end |
.find(id) ⇒ Object
8 9 10 11 |
# File 'lib/nobel/laureate.rb', line 8 def find(id) data = get_data(id: id) new(data.first) if data.any? end |
Instance Method Details
#categories ⇒ Object
69 70 71 |
# File 'lib/nobel/laureate.rb', line 69 def categories won(:category) end |
#name ⇒ Object
59 60 61 |
# File 'lib/nobel/laureate.rb', line 59 def name "#{firstname} #{surname}".strip end |
#prizes ⇒ Object
63 64 65 66 67 |
# File 'lib/nobel/laureate.rb', line 63 def prizes @prizes ||= (data['prizes'] || []).map do |p| Prize.new(p) end end |
#reload! ⇒ Object
54 55 56 57 |
# File 'lib/nobel/laureate.rb', line 54 def reload! initialize self.class.get_data(id: id).first self end |
#years ⇒ Object
73 74 75 |
# File 'lib/nobel/laureate.rb', line 73 def years won(:year) end |