Class: Cricketer::Match

Inherits:
Object
  • Object
show all
Extended by:
FastAttributes
Defined in:
lib/match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#batted_firstObject (readonly)

Returns the value of attribute batted_first.



5
6
7
# File 'lib/match.rb', line 5

def batted_first
  @batted_first
end

#cancelledObject (readonly)

Returns the value of attribute cancelled.



5
6
7
# File 'lib/match.rb', line 5

def cancelled
  @cancelled
end

#current_statusObject (readonly)

Returns the value of attribute current_status.



5
6
7
# File 'lib/match.rb', line 5

def current_status
  @current_status
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/match.rb', line 5

def description
  @description
end

#floodlitObject (readonly)

Returns the value of attribute floodlit.



5
6
7
# File 'lib/match.rb', line 5

def floodlit
  @floodlit
end

#groundObject (readonly)

Returns the value of attribute ground.



5
6
7
# File 'lib/match.rb', line 5

def ground
  @ground
end

#inningsObject (readonly)

Returns the value of attribute innings.



5
6
7
# File 'lib/match.rb', line 5

def innings
  @innings
end

#match_dataObject (readonly)

Returns the value of attribute match_data.



5
6
7
# File 'lib/match.rb', line 5

def match_data
  @match_data
end

#match_idObject (readonly)

Returns the value of attribute match_id.



5
6
7
# File 'lib/match.rb', line 5

def match_id
  @match_id
end

#officialsObject (readonly)

Returns the value of attribute officials.



5
6
7
# File 'lib/match.rb', line 5

def officials
  @officials
end

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/match.rb', line 5

def result
  @result
end

#summaryObject (readonly)

Returns the value of attribute summary.



5
6
7
# File 'lib/match.rb', line 5

def summary
  @summary
end

#team1Object (readonly)

Returns the value of attribute team1.



5
6
7
# File 'lib/match.rb', line 5

def team1
  @team1
end

#team1_inningsObject (readonly)

Returns the value of attribute team1_innings.



5
6
7
# File 'lib/match.rb', line 5

def team1_innings
  @team1_innings
end

#team1_playersObject (readonly)

Returns the value of attribute team1_players.



5
6
7
# File 'lib/match.rb', line 5

def team1_players
  @team1_players
end

#team2Object (readonly)

Returns the value of attribute team2.



5
6
7
# File 'lib/match.rb', line 5

def team2
  @team2
end

#team2_inningsObject (readonly)

Returns the value of attribute team2_innings.



5
6
7
# File 'lib/match.rb', line 5

def team2_innings
  @team2_innings
end

#team2_playersObject (readonly)

Returns the value of attribute team2_players.



5
6
7
# File 'lib/match.rb', line 5

def team2_players
  @team2_players
end

#teams_dataObject

Returns the value of attribute teams_data.



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

def teams_data
  @teams_data
end

#winning_teamObject (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_matchesObject

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_dataObject



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

#followonObject



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

#playersObject



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_sObject



77
78
79
# File 'lib/match.rb', line 77

def to_s
  description
end