class LolesportsApi::Game

Constants

API_URL

Attributes

blue_team[RW]
date_time[R]
game_length[R]
game_number[R]
has_vod[R]
id[R]
legs_url[R]
match_id[R]
max_games[R]
no_vods[R]
platform_game_id[R]
platform_id[R]
players[R]
red_team[RW]
tournament[R]
vods[R]
winner_id[R]
youtube_url[R]

Public Class Methods

find(game_id) click to toggle source
Calls superclass method LolesportsApi::BaseApiObject::find
# 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
new(attributes = {}) click to toggle source
# 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

Public Instance Methods

prepare_teams(attrs) click to toggle source
# 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

Private Instance Methods

parse_vods(attrs, type) click to toggle source
# File lib/lolesports-api/game.rb, line 55
def parse_vods(attrs, type)
  return nil if attrs['hasVod'] == 0 || attrs['vods'].nil?
  return attrs['vods']['vod']['URL'] if attrs['vods']['vod']['type'] == type
end
parse_winner_id(attr) click to toggle source
# File lib/lolesports-api/game.rb, line 60
def parse_winner_id(attr)
  attr =~ /^\d+$/ ? attr : nil
end