class Cricketer::Match

Attributes

batted_first[R]
cancelled[R]
current_status[R]
description[R]
floodlit[R]
ground[R]
innings[R]
match_data[R]
match_id[R]
officials[R]
result[R]
summary[R]
team1[R]
team1_innings[R]
team1_players[R]
team2[R]
team2_innings[R]
team2_players[R]
teams_data[RW]
winning_team[R]

Public Class Methods

create(match_id) click to toggle source
# 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() click to toggle source

check for live matches

# 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

Public Instance Methods

extract_teams_data() click to toggle source
# 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() click to toggle source
# File lib/match.rb, line 117
def followon
  to_boolean summary.followon
end
innings_by_team_id(id) click to toggle source
# File lib/match.rb, line 97
def innings_by_team_id(id)
  innings.select {|i| i.batting_team_id == id }
end
players() click to toggle source
# File lib/match.rb, line 137
def players
  match_data.team
end
players_by_team_name(name) click to toggle source
# 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() click to toggle source
# File lib/match.rb, line 77
def to_s
  description
end

Private Instance Methods

to_boolean(value) click to toggle source
# File lib/match.rb, line 148
def to_boolean(value)
  case value
  when "1" then true
  when "N" then false
  else false
  end
end