Class: LolesportsApi::Match

Inherits:
BaseApiObject show all
Defined in:
lib/lolesports-api/match.rb

Constant Summary collapse

API_URL =
'http://na.lolesports.com/api/match'

Constants inherited from BaseApiObject

BaseApiObject::SCHEDULE_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseApiObject

fail_by_status, #reload

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_teamObject (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_timeObject (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

#gamesObject (readonly)

Returns the value of attribute games.



3
4
5
# File 'lib/lolesports-api/match.rb', line 3

def games
  @games
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/lolesports-api/match.rb', line 3

def id
  @id
end

#is_finishedObject (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_liveObject (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_streamsObject (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_gamesObject (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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/lolesports-api/match.rb', line 3

def name
  @name
end

#polldaddy_idObject (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_teamObject (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

#roundObject (readonly)

Returns the value of attribute round.



3
4
5
# File 'lib/lolesports-api/match.rb', line 3

def round
  @round
end

#tournamentObject

Returns the value of attribute tournament.



8
9
10
# File 'lib/lolesports-api/match.rb', line 8

def tournament
  @tournament
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/lolesports-api/match.rb', line 3

def url
  @url
end

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