Class: Sportradar::Api::Poll
- Inherits:
-
Object
- Object
- Sportradar::Api::Poll
- Defined in:
- lib/sportradar/api/poll.rb
Instance Method Summary collapse
-
#initialize(data) ⇒ Poll
constructor
A new instance of Poll.
- #update(data) ⇒ Object
Constructor Details
#initialize(data) ⇒ Poll
Returns a new instance of Poll.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sportradar/api/poll.rb', line 20 def initialize(data) @response = data @id = data.dig('poll', 'id') @name = data.dig('poll', 'name') @alias = data.dig('poll', 'alias') @week = data['week'] @year = data['year'] @time = data['effective_date'] update(data) end |
Instance Method Details
#update(data) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/sportradar/api/poll.rb', line 32 def update(data) @ranked = data['rankings'].map { |h| Rank.new(h) } if @alias == 'AP' || @alias == 'US' @votes = data['candidates'].map.with_index(@ranked.size + 1) { |h, i| Rank.new(h.merge('rank' => i)) } end end |