Class: FootballApi::Commentary
- Inherits:
-
BaseRequest
- Object
- BaseRequest
- FootballApi::Commentary
- Includes:
- Requestable
- Defined in:
- lib/football_api/commentary.rb
Constant Summary
Constants inherited from BaseRequest
Constants included from Symbolizer
Symbolizer::HASH_OR_ARRAY_KEYS
Class Attribute Summary collapse
-
.match_id ⇒ Object
Returns the value of attribute match_id.
Instance Attribute Summary collapse
-
#commentaries ⇒ Object
Returns the value of attribute commentaries.
-
#local_match_team ⇒ Object
Returns the value of attribute local_match_team.
-
#match_bench ⇒ Object
Returns the value of attribute match_bench.
-
#match_id ⇒ Object
Returns the value of attribute match_id.
-
#match_info ⇒ Object
Returns the value of attribute match_info.
-
#match_stats ⇒ Object
Returns the value of attribute match_stats.
-
#match_substitutions ⇒ Object
Returns the value of attribute match_substitutions.
-
#match_summary ⇒ Object
Returns the value of attribute match_summary.
-
#static_id ⇒ Object
Returns the value of attribute static_id.
-
#visitor_match_team ⇒ Object
Returns the value of attribute visitor_match_team.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Commentary
constructor
A new instance of Commentary.
- #parse_comments(hash = {}) ⇒ Object
- #parse_match_bench(hash = {}) ⇒ Object
- #parse_match_info(hash = {}) ⇒ Object
- #parse_match_stats(hash = {}) ⇒ Object
- #parse_match_substitutions(hash) ⇒ Object
- #parse_match_summary(hash = {}) ⇒ Object
- #parse_match_teams(hash = {}, key) ⇒ Object
Methods included from Requestable
Methods inherited from BaseRequest
action_query, get!, get_parameters, response
Methods included from Symbolizer
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_id ⇒ Object
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
#commentaries ⇒ Object
Returns the value of attribute commentaries.
22 23 24 |
# File 'lib/football_api/commentary.rb', line 22 def commentaries @commentaries end |
#local_match_team ⇒ Object
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_bench ⇒ Object
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_id ⇒ Object
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_info ⇒ Object
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_stats ⇒ Object
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_substitutions ⇒ Object
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_summary ⇒ Object
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_id ⇒ Object
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_team ⇒ Object
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_params ⇒ Object
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 |