Class: Cricketer::Match
- Inherits:
-
Object
- Object
- Cricketer::Match
- Extended by:
- FastAttributes
- Defined in:
- lib/match.rb
Instance Attribute Summary collapse
-
#batted_first ⇒ Object
readonly
Returns the value of attribute batted_first.
-
#cancelled ⇒ Object
readonly
Returns the value of attribute cancelled.
-
#current_status ⇒ Object
readonly
Returns the value of attribute current_status.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#floodlit ⇒ Object
readonly
Returns the value of attribute floodlit.
-
#ground ⇒ Object
readonly
Returns the value of attribute ground.
-
#innings ⇒ Object
readonly
Returns the value of attribute innings.
-
#match_data ⇒ Object
readonly
Returns the value of attribute match_data.
-
#match_id ⇒ Object
readonly
Returns the value of attribute match_id.
-
#officials ⇒ Object
readonly
Returns the value of attribute officials.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#team1 ⇒ Object
readonly
Returns the value of attribute team1.
-
#team1_innings ⇒ Object
readonly
Returns the value of attribute team1_innings.
-
#team1_players ⇒ Object
readonly
Returns the value of attribute team1_players.
-
#team2 ⇒ Object
readonly
Returns the value of attribute team2.
-
#team2_innings ⇒ Object
readonly
Returns the value of attribute team2_innings.
-
#team2_players ⇒ Object
readonly
Returns the value of attribute team2_players.
-
#teams_data ⇒ Object
Returns the value of attribute teams_data.
-
#winning_team ⇒ Object
readonly
Returns the value of attribute winning_team.
Class Method Summary collapse
- .create(match_id) ⇒ Object
-
.live_matches ⇒ Object
check for live matches.
Instance Method Summary collapse
- #extract_teams_data ⇒ Object
- #followon ⇒ Object
- #innings_by_team_id(id) ⇒ Object
- #players ⇒ Object
- #players_by_team_name(name) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#batted_first ⇒ Object (readonly)
Returns the value of attribute batted_first.
5 6 7 |
# File 'lib/match.rb', line 5 def batted_first @batted_first end |
#cancelled ⇒ Object (readonly)
Returns the value of attribute cancelled.
5 6 7 |
# File 'lib/match.rb', line 5 def cancelled @cancelled end |
#current_status ⇒ Object (readonly)
Returns the value of attribute current_status.
5 6 7 |
# File 'lib/match.rb', line 5 def current_status @current_status end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/match.rb', line 5 def description @description end |
#floodlit ⇒ Object (readonly)
Returns the value of attribute floodlit.
5 6 7 |
# File 'lib/match.rb', line 5 def floodlit @floodlit end |
#ground ⇒ Object (readonly)
Returns the value of attribute ground.
5 6 7 |
# File 'lib/match.rb', line 5 def ground @ground end |
#innings ⇒ Object (readonly)
Returns the value of attribute innings.
5 6 7 |
# File 'lib/match.rb', line 5 def innings @innings end |
#match_data ⇒ Object (readonly)
Returns the value of attribute match_data.
5 6 7 |
# File 'lib/match.rb', line 5 def match_data @match_data end |
#match_id ⇒ Object (readonly)
Returns the value of attribute match_id.
5 6 7 |
# File 'lib/match.rb', line 5 def match_id @match_id end |
#officials ⇒ Object (readonly)
Returns the value of attribute officials.
5 6 7 |
# File 'lib/match.rb', line 5 def officials @officials end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/match.rb', line 5 def result @result end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
5 6 7 |
# File 'lib/match.rb', line 5 def summary @summary end |
#team1 ⇒ Object (readonly)
Returns the value of attribute team1.
5 6 7 |
# File 'lib/match.rb', line 5 def team1 @team1 end |
#team1_innings ⇒ Object (readonly)
Returns the value of attribute team1_innings.
5 6 7 |
# File 'lib/match.rb', line 5 def team1_innings @team1_innings end |
#team1_players ⇒ Object (readonly)
Returns the value of attribute team1_players.
5 6 7 |
# File 'lib/match.rb', line 5 def team1_players @team1_players end |
#team2 ⇒ Object (readonly)
Returns the value of attribute team2.
5 6 7 |
# File 'lib/match.rb', line 5 def team2 @team2 end |
#team2_innings ⇒ Object (readonly)
Returns the value of attribute team2_innings.
5 6 7 |
# File 'lib/match.rb', line 5 def team2_innings @team2_innings end |
#team2_players ⇒ Object (readonly)
Returns the value of attribute team2_players.
5 6 7 |
# File 'lib/match.rb', line 5 def team2_players @team2_players end |
#teams_data ⇒ Object
Returns the value of attribute teams_data.
8 9 10 |
# File 'lib/match.rb', line 8 def teams_data @teams_data end |
#winning_team ⇒ Object (readonly)
Returns the value of attribute winning_team.
5 6 7 |
# File 'lib/match.rb', line 5 def winning_team @winning_team end |
Class Method Details
.create(match_id) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/match.rb', line 25 def self.create(match_id) data = API.new(match_id: match_id).content description, summary, innings, official = data.values_at('description', 'match', 'innings', 'official') self.new(match_id: match_id, match_data: data, description: description, summary: summary, innings: innings, officials: official) end |
.live_matches ⇒ Object
check for live matches
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/match.rb', line 40 def self.live_matches results = [] url = 'http://static.cricinfo.com/rss/livescores.xml' open(url) do |rss| feed = RSS::Parser.parse(rss) feed.items.each do |item| match_id = item.guid.content.split('/').last.split('.').first.to_i results << OpenStruct.new(match_id: match_id, description: item.description, url: item.link) end end results end |
Instance Method Details
#extract_teams_data ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/match.rb', line 65 def extract_teams_data keys = [:name, :id, :abbrev] [1, 2].map do |n| values = ["team#{n}_name", "team#{n}_id", "team#{n}_abbreviation"].map do |m| summary.send(m.to_sym) end Hash[keys.zip(values)] end end |
#followon ⇒ Object
117 118 119 |
# File 'lib/match.rb', line 117 def followon to_boolean summary.followon end |
#innings_by_team_id(id) ⇒ Object
97 98 99 |
# File 'lib/match.rb', line 97 def innings_by_team_id(id) innings.select {|i| i.batting_team_id == id } end |
#players ⇒ Object
137 138 139 |
# File 'lib/match.rb', line 137 def players match_data.team end |
#players_by_team_name(name) ⇒ Object
141 142 143 144 |
# File 'lib/match.rb', line 141 def players_by_team_name(name) players.detect{ |t| t['team_name'] == name }['player'] .map{|p| Player.new(p) } end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/match.rb', line 77 def to_s description end |