Class: Nobel::Prize

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#categoryObject (readonly)

Returns the value of attribute category.



17
18
19
# File 'lib/nobel/prize.rb', line 17

def category
  @category
end

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/nobel/prize.rb', line 17

def data
  @data
end

#motivationObject (readonly)

Returns the value of attribute motivation.



17
18
19
# File 'lib/nobel/prize.rb', line 17

def motivation
  @motivation
end

#shareObject (readonly)

Returns the value of attribute share.



17
18
19
# File 'lib/nobel/prize.rb', line 17

def share
  @share
end

#yearObject (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

.get_data(params = {}) ⇒ Object



12
13
14
# File 'lib/nobel/prize.rb', line 12

def get_data(params = {})
  Nobel.api.prize(params)['prizes'] || []
end

Instance Method Details

#affiliationsObject



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

#laureatesObject



36
37
38
39
40
# File 'lib/nobel/prize.rb', line 36

def laureates
  @laureates ||= (data['laureates'] || []).map do |l|
    Laureate.new(l)
  end
end