Class: FootballApi::Commentary

Inherits:
BaseRequest show all
Includes:
Requestable
Defined in:
lib/football_api/commentary.rb

Constant Summary

Constants inherited from BaseRequest

BaseRequest::RETRIES

Constants included from Symbolizer

Symbolizer::HASH_OR_ARRAY_KEYS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Requestable

included

Methods inherited from BaseRequest

action_query, get!, get_parameters, response

Methods included from Symbolizer

included

Constructor Details

#initialize(hash = {}) ⇒ Commentary

Returns a new instance of Commentary.



26
27
28
29
30
31
32
33
34
35
36
37
# 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

Class Attribute Details

.match_idObject

Returns the value of attribute match_id.



8
9
10
# File 'lib/football_api/commentary.rb', line 8

def match_id
  @match_id
end

Instance Attribute Details

#commentariesObject

Returns the value of attribute commentaries.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def commentaries
  @commentaries
end

#local_match_teamObject

Returns the value of attribute local_match_team.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def local_match_team
  @local_match_team
end

#match_benchObject

Returns the value of attribute match_bench.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_bench
  @match_bench
end

#match_idObject

Returns the value of attribute match_id.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_id
  @match_id
end

#match_infoObject

Returns the value of attribute match_info.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_info
  @match_info
end

#match_statsObject

Returns the value of attribute match_stats.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_stats
  @match_stats
end

#match_substitutionsObject

Returns the value of attribute match_substitutions.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_substitutions
  @match_substitutions
end

#match_summaryObject

Returns the value of attribute match_summary.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def match_summary
  @match_summary
end

#static_idObject

Returns the value of attribute static_id.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def static_id
  @static_id
end

#visitor_match_teamObject

Returns the value of attribute visitor_match_team.



22
23
24
# File 'lib/football_api/commentary.rb', line 22

def visitor_match_team
  @visitor_match_team
end

Class Method Details

.all_from_match(match) ⇒ Object



10
11
12
13
14
15
# 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_paramsObject



17
18
19
# File 'lib/football_api/commentary.rb', line 17

def commentary_params
  { match_id: self.match_id }
end

Instance Method Details

#parse_comments(hash = {}) ⇒ Object



59
60
61
62
63
# 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 = {}) ⇒ Object



65
66
67
68
69
70
# 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 = {}) ⇒ Object



39
40
41
42
# 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 = {}) ⇒ Object



49
50
51
52
53
# 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) ⇒ Object



72
73
74
75
76
77
# 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 = {}) ⇒ Object



44
45
46
47
# 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) ⇒ Object



55
56
57
# File 'lib/football_api/commentary.rb', line 55

def parse_match_teams(hash = {}, key)
  FootballApi::MatchTeam.new(hash, key)
end