Class: LolesportsApi::Game

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

Constant Summary collapse

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

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 = {}) ⇒ Game

Returns a new instance of Game.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lolesports-api/game.rb', line 13

def initialize(attributes = {})
  @id = attributes['id'].to_i
  @game_length = attributes['gameLength'].to_i
  @game_number = attributes['gameNumber'].to_i
  @legs_url = attributes['legsUrl']
  @match_id = attributes['matchId'].to_i
  @max_games = attributes['maxGames'].to_i
  @no_vods = (attributes['noVods'] == '1' ? true : false)
  @platform_game_id = attributes['platformGameId']
  @platform_id = attributes['platformId']
  @players = []
  @tournament = attributes['tournament'] || {}
  @vods = attributes['vods'] || {}
  @has_vod = attributes['hasVod']
  @winner_id = parse_winner_id(attributes['winnerId'])
  @date_time = parse_datetime(attributes['dateTime'])
  @youtube_url = parse_vods(attributes, 'youtube')

  prepare_teams(attributes)

  self
end

Instance Attribute Details

#blue_teamObject

Returns the value of attribute blue_team.



9
10
11
# File 'lib/lolesports-api/game.rb', line 9

def blue_team
  @blue_team
end

#date_timeObject (readonly)

Returns the value of attribute date_time.



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

def date_time
  @date_time
end

#game_lengthObject (readonly)

Returns the value of attribute game_length.



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

def game_length
  @game_length
end

#game_numberObject (readonly)

Returns the value of attribute game_number.



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

def game_number
  @game_number
end

#has_vodObject (readonly)

Returns the value of attribute has_vod.



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

def has_vod
  @has_vod
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#legs_urlObject (readonly)

Returns the value of attribute legs_url.



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

def legs_url
  @legs_url
end

#match_idObject (readonly)

Returns the value of attribute match_id.



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

def match_id
  @match_id
end

#max_gamesObject (readonly)

Returns the value of attribute max_games.



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

def max_games
  @max_games
end

#no_vodsObject (readonly)

Returns the value of attribute no_vods.



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

def no_vods
  @no_vods
end

#platform_game_idObject (readonly)

Returns the value of attribute platform_game_id.



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

def platform_game_id
  @platform_game_id
end

#platform_idObject (readonly)

Returns the value of attribute platform_id.



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

def platform_id
  @platform_id
end

#playersObject (readonly)

Returns the value of attribute players.



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

def players
  @players
end

#red_teamObject

Returns the value of attribute red_team.



9
10
11
# File 'lib/lolesports-api/game.rb', line 9

def red_team
  @red_team
end

#tournamentObject (readonly)

Returns the value of attribute tournament.



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

def tournament
  @tournament
end

#vodsObject (readonly)

Returns the value of attribute vods.



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

def vods
  @vods
end

#winner_idObject (readonly)

Returns the value of attribute winner_id.



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

def winner_id
  @winner_id
end

#youtube_urlObject (readonly)

Returns the value of attribute youtube_url.



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

def youtube_url
  @youtube_url
end

Class Method Details

.find(game_id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/lolesports-api/game.rb', line 36

def self.find(game_id)
  super
  @base_object.prepare_teams(@attributes)
  if @attributes['players'] && @attributes['players'].any?
    @attributes['players'].each_value do |player|
      @base_object.players << LolesportsApi::Play.new(player)
    end
  end
  @base_object
end

Instance Method Details

#prepare_teams(attrs) ⇒ Object



47
48
49
50
51
# File 'lib/lolesports-api/game.rb', line 47

def prepare_teams(attrs)
  return unless attrs['contestants']
  @blue_team = LolesportsApi::Team.new(attrs['contestants']['blue'])
  @red_team = LolesportsApi::Team.new(attrs['contestants']['red'])
end