Class: LolesportsApi::Match
- Inherits:
-
BaseApiObject
- Object
- BaseApiObject
- LolesportsApi::Match
- Defined in:
- lib/lolesports-api/match.rb
Constant Summary collapse
- API_URL =
'http://na.lolesports.com/api/match'
Constants inherited from BaseApiObject
Instance Attribute Summary collapse
-
#blue_team ⇒ Object
readonly
Returns the value of attribute blue_team.
-
#date_time ⇒ Object
readonly
Returns the value of attribute date_time.
-
#games ⇒ Object
readonly
Returns the value of attribute games.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_finished ⇒ Object
readonly
Returns the value of attribute is_finished.
-
#is_live ⇒ Object
readonly
Returns the value of attribute is_live.
-
#live_streams ⇒ Object
readonly
Returns the value of attribute live_streams.
-
#max_games ⇒ Object
readonly
Returns the value of attribute max_games.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#polldaddy_id ⇒ Object
readonly
Returns the value of attribute polldaddy_id.
-
#red_team ⇒ Object
readonly
Returns the value of attribute red_team.
-
#round ⇒ Object
readonly
Returns the value of attribute round.
-
#tournament ⇒ Object
Returns the value of attribute tournament.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#winner_id ⇒ Object
readonly
Returns the value of attribute winner_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Match
constructor
A new instance of Match.
- #prepare_games(attrs) ⇒ Object
- #prepare_teams(teams) ⇒ Object
Methods inherited from BaseApiObject
Constructor Details
#initialize(attributes = {}) ⇒ Match
Returns a new instance of Match.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lolesports-api/match.rb', line 12 def initialize(attributes = {}) @id = (attributes['id'] || attributes['matchId']).to_i @date_time = parse_datetime(attributes['dateTime']) @is_finished = (attributes['isFinished'] == '1' ? true : false) @is_live = attributes['isLive'] @live_streams = attributes['liveStreams'] @max_games = attributes['maxGames'] @name = attributes['name'] @polldaddy_id = attributes['polldaddyId'] @tournament = LolesportsApi::Tournament.new(attributes['tournament']) @url = attributes['url'] @winner_id = attributes['winnerId'].to_i if attributes['tournament'] @round = attributes['tournament']['round'].to_i end prepare_teams(attributes['contestants']) prepare_games(attributes) self end |
Instance Attribute Details
#blue_team ⇒ Object (readonly)
Returns the value of attribute blue_team.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def blue_team @blue_team end |
#date_time ⇒ Object (readonly)
Returns the value of attribute date_time.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def date_time @date_time end |
#games ⇒ Object (readonly)
Returns the value of attribute games.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def games @games end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def id @id end |
#is_finished ⇒ Object (readonly)
Returns the value of attribute is_finished.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def is_finished @is_finished end |
#is_live ⇒ Object (readonly)
Returns the value of attribute is_live.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def is_live @is_live end |
#live_streams ⇒ Object (readonly)
Returns the value of attribute live_streams.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def live_streams @live_streams end |
#max_games ⇒ Object (readonly)
Returns the value of attribute max_games.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def max_games @max_games end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def name @name end |
#polldaddy_id ⇒ Object (readonly)
Returns the value of attribute polldaddy_id.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def polldaddy_id @polldaddy_id end |
#red_team ⇒ Object (readonly)
Returns the value of attribute red_team.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def red_team @red_team end |
#round ⇒ Object (readonly)
Returns the value of attribute round.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def round @round end |
#tournament ⇒ Object
Returns the value of attribute tournament.
8 9 10 |
# File 'lib/lolesports-api/match.rb', line 8 def tournament @tournament end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def url @url end |
#winner_id ⇒ Object (readonly)
Returns the value of attribute winner_id.
3 4 5 |
# File 'lib/lolesports-api/match.rb', line 3 def winner_id @winner_id end |
Class Method Details
.find(match_id) ⇒ Object
34 35 36 37 38 |
# File 'lib/lolesports-api/match.rb', line 34 def self.find(match_id) super @base_object.prepare_games(@attributes) @base_object end |
Instance Method Details
#prepare_games(attrs) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/lolesports-api/match.rb', line 40 def prepare_games(attrs) return unless attrs['games'] && attrs['games'].any? @games = [] attrs['games'].each_value do |game| @games << LolesportsApi::Game.new(game) end end |
#prepare_teams(teams) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/lolesports-api/match.rb', line 48 def prepare_teams(teams) return unless teams @blue_team = LolesportsApi::Team.new(teams['blue']) if teams['blue'] @red_team = LolesportsApi::Team.new(teams['red']) if teams['red'] end |