Class: CricInfo::Scores
- Inherits:
-
Object
- Object
- CricInfo::Scores
- Includes:
- GameTypes
- Defined in:
- lib/cricinfo/scores.rb
Constant Summary collapse
- DEBUG =
false
- SCORES_HOST =
"m.espncricinfo.com"
- SCORES_PATH =
"/s/2497/Scores"
- RE_MATCH =
match name, team1, team2, inningsdata, start_time
/matchId=.*?">([^:]+):<\/a>[^>]*>\s*(.*?)\s+v\s+(.*?)<\/a>.*?<\/tr>(.*?)<\/tr>(.*?Start time (.*?)\s*<\/b>)?/
- RE_INNINGS =
team1/2, i1runs, i1wickets, i1decl, i2wickets, i2decl, overs (overs optional)
/<b>\s*(.*?)\s*<\/b>\s*<b>\s*(\d+)(?:\/(\d+))?(d)?(?:\s*&\s*(\d+)\/(\d+)(d)?)?\s*(?:\(([\d\.]+))?/
- RE_START =
start_time (e.g. Start time 09:30 GMT)
/<b>\s*Start\s+time\s+(.*?)\s*<\/b>/
Constants included from GameTypes
GameTypes::GAMETYPE_ODI, GameTypes::GAMETYPE_T20, GameTypes::GAMETYPE_TEST, GameTypes::GAMETYPE_UNKNOWN
Instance Attribute Summary collapse
-
#games ⇒ Object
readonly
Returns the value of attribute games.
Instance Method Summary collapse
-
#initialize(html = nil) ⇒ Scores
constructor
create a new CricInfo::Scores object.
-
#reload(html = nil) ⇒ Object
reload score data.
Constructor Details
#initialize(html = nil) ⇒ Scores
create a new CricInfo::Scores object
23 24 25 |
# File 'lib/cricinfo/scores.rb', line 23 def initialize(html = nil) reload(html) end |
Instance Attribute Details
#games ⇒ Object (readonly)
Returns the value of attribute games.
20 21 22 |
# File 'lib/cricinfo/scores.rb', line 20 def games @games end |
Instance Method Details
#reload(html = nil) ⇒ Object
reload score data
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cricinfo/scores.rb', line 28 def reload(html = nil) @games = [] data = html || CricInfo::Scores.fetch_score_data data.gsub!(/<font.*?\/?>|<\/font>/, '') # blow away font tags ftw # extract matches data.scan(RE_MATCH) do |match_name, team1, team2, idata, junk, start| game = Game.new game.name = match_name game.type = GAMETYPE_TEST if match_name.match(/Test/) game.type = GAMETYPE_T20 if match_name.match(/^\d+.. Match/) game.team1 = team1 game.team2 = team2 game.start_time = start ? Time.parse(start) : nil # parse innings data idata.scan(RE_INNINGS) do |data| team, i1runs, i1wickets, i1decl, i2runs, i2wickets, i2decl, overs = *data game.type = GAMETYPE_TEST if overs && overs.to_f > Game::OVERS_ODI inns1 = add_innings(game, team, i1runs, i1wickets, i1decl) inns2 = add_innings(game, team, i2runs, i2wickets, i2decl) # overs given applies to the last innings inns = inns2 ? inns2 : inns1 inns.overs = overs ? overs : nil end # rorder innings: attempt to guess innings order. # find first valid permutation of innings order. list = game.innings.permutations.detect { |i| valid_innings_order(i) } game.innings = list if list @games.push(game) end end |