class FootballApi::Commentary

Attributes

match_id[RW]
commentaries[RW]
local_match_team[RW]
match_bench[RW]
match_id[RW]
match_info[RW]
match_stats[RW]
match_substitutions[RW]
match_summary[RW]
static_id[RW]
visitor_match_team[RW]

Public Class Methods

all_from_match(match) click to toggle source
# File lib/football_api/commentary.rb, line 10
def all_from_match(match)
  @match_id = match.is_a?(Match) ? match.id : match

  res = response
  res.map { |commentary| new(commentary) }.first
end
commentary_params() click to toggle source
# File lib/football_api/commentary.rb, line 17
def commentary_params
  { match_id: self.match_id }
end
new(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 26
def initialize(hash = {})
  @match_id            = hash[:comm_match_id]
  @static_id           = hash[:comm_static_id]
  @match_info          = parse_match_info(hash)
  @match_summary       = parse_match_summary(hash)
  @match_stats         = parse_match_stats(hash)
  @local_match_team    = parse_match_teams(hash, :localteam)
  @visitor_match_team  = parse_match_teams(hash, :visitorteam)
  @match_bench         = parse_match_bench(hash)
  @match_substitutions = parse_match_substitutions(hash)
  @commentaries        = parse_comments(hash[:comm_commentaries])
end

Public Instance Methods

parse_comments(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 59
def parse_comments(hash = {})
  return unless hash[:comment]

  Array(hash[:comment]).map{ |comment| FootballApi::Comment.new(comment) }
end
parse_match_bench(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 65
def parse_match_bench(hash = {})
  return unless hash[:comm_match_subs]

  FootballApi::MatchBench.new(hash[:comm_match_subs]
                              .merge(match_id: hash[:comm_match_id]))
end
parse_match_info(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 39
def parse_match_info(hash = {})
  hash = hash[:comm_match_info].merge(id: hash[:comm_match_id])
  FootballApi::MatchInfo.new(hash)
end
parse_match_stats(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 49
def parse_match_stats(hash = {})
  return unless hash[:comm_match_stats].is_a?(Hash)
  hash = hash[:comm_match_stats].merge(id: hash[:comm_match_id])
  FootballApi::MatchStats.new(hash)
end
parse_match_substitutions(hash) click to toggle source
# File lib/football_api/commentary.rb, line 72
def parse_match_substitutions(hash)
  return unless hash[:comm_match_substitutions]

  FootballApi::MatchSubstitutions.new(hash[:comm_match_substitutions]
                                      .merge(match_id: hash[:comm_match_id]))
end
parse_match_summary(hash = {}) click to toggle source
# File lib/football_api/commentary.rb, line 44
def parse_match_summary(hash = {})
  hash = hash[:comm_match_summary].merge(id: hash[:comm_match_id])
  FootballApi::MatchSummary.new(hash)
end
parse_match_teams(hash = {}, key) click to toggle source
# File lib/football_api/commentary.rb, line 55
def parse_match_teams(hash = {}, key)
  FootballApi::MatchTeam.new(hash, key)
end