Class: Nobel::Prize
- Inherits:
-
Object
- Object
- Nobel::Prize
- Defined in:
- lib/nobel/prize.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#motivation ⇒ Object
readonly
Returns the value of attribute motivation.
-
#share ⇒ Object
readonly
Returns the value of attribute share.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Class Method Summary collapse
- .all(params = {}) ⇒ Object (also: query)
- .get_data(params = {}) ⇒ Object
Instance Method Summary collapse
- #affiliations ⇒ Object
-
#initialize(data) ⇒ Prize
constructor
A new instance of Prize.
- #laureates ⇒ Object
Constructor Details
#initialize(data) ⇒ Prize
Returns a new instance of Prize.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nobel/prize.rb', line 19 def initialize(data) @data = data || {} @data.tap do |d| @year = Integer(d['year']) @category = d['category'] @share = Integer(d['share']) if d['share'] @motivation = d['motivation'] end end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
17 18 19 |
# File 'lib/nobel/prize.rb', line 17 def category @category end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/nobel/prize.rb', line 17 def data @data end |
#motivation ⇒ Object (readonly)
Returns the value of attribute motivation.
17 18 19 |
# File 'lib/nobel/prize.rb', line 17 def motivation @motivation end |
#share ⇒ Object (readonly)
Returns the value of attribute share.
17 18 19 |
# File 'lib/nobel/prize.rb', line 17 def share @share end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
17 18 19 |
# File 'lib/nobel/prize.rb', line 17 def year @year end |
Class Method Details
.all(params = {}) ⇒ Object Also known as: query
6 7 8 |
# File 'lib/nobel/prize.rb', line 6 def all(params = {}) get_data(params).map { |c| new(c) } end |
Instance Method Details
#affiliations ⇒ Object
30 31 32 33 34 |
# File 'lib/nobel/prize.rb', line 30 def affiliations @affiliations ||= (data['affiliations'] || []).map do |a| Affiliation.new(a) if a.respond_to?(:has_key?) end.compact end |