Class: CricInfo::Game
- Inherits:
-
Object
- Object
- CricInfo::Game
- Includes:
- GameTypes
- Defined in:
- lib/cricinfo/game.rb
Constant Summary collapse
- OVERS_ODI =
50
Constants included from GameTypes
CricInfo::GameTypes::GAMETYPE_ODI, CricInfo::GameTypes::GAMETYPE_T20, CricInfo::GameTypes::GAMETYPE_TEST, CricInfo::GameTypes::GAMETYPE_UNKNOWN
Instance Attribute Summary collapse
-
#innings ⇒ Object
Returns the value of attribute innings.
-
#name ⇒ Object
Returns the value of attribute name.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#team1 ⇒ Object
team1 is the team batting first (first innings).
-
#team2 ⇒ Object
team1 is the team batting first (first innings).
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_innings ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
- #inns1 ⇒ Object
- #inns2 ⇒ Object
- #inns3 ⇒ Object
- #inns4 ⇒ Object
-
#summary ⇒ Object
returns a string summarising the game data.
- #type_string ⇒ Object
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
20 21 22 23 |
# File 'lib/cricinfo/game.rb', line 20 def initialize @innings = [] @type = GAMETYPE_ODI # assume ODI by default end |
Instance Attribute Details
#innings ⇒ Object
Returns the value of attribute innings.
16 17 18 |
# File 'lib/cricinfo/game.rb', line 16 def innings @innings end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/cricinfo/game.rb', line 16 def name @name end |
#start_time ⇒ Object
Returns the value of attribute start_time.
16 17 18 |
# File 'lib/cricinfo/game.rb', line 16 def start_time @start_time end |
#team1 ⇒ Object
team1 is the team batting first (first innings)
18 19 20 |
# File 'lib/cricinfo/game.rb', line 18 def team1 @team1 end |
#team2 ⇒ Object
team1 is the team batting first (first innings)
18 19 20 |
# File 'lib/cricinfo/game.rb', line 18 def team2 @team2 end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'lib/cricinfo/game.rb', line 16 def type @type end |
Instance Method Details
#add_innings ⇒ Object
30 31 32 33 |
# File 'lib/cricinfo/game.rb', line 30 def add_innings @innings.push(Innings.new) @innings[-1] end |
#inns1 ⇒ Object
25 |
# File 'lib/cricinfo/game.rb', line 25 def inns1; @innings[0]; end |
#inns2 ⇒ Object
26 |
# File 'lib/cricinfo/game.rb', line 26 def inns2; @innings[1]; end |
#inns3 ⇒ Object
27 |
# File 'lib/cricinfo/game.rb', line 27 def inns3; @innings[2]; end |
#inns4 ⇒ Object
28 |
# File 'lib/cricinfo/game.rb', line 28 def inns4; @innings[3]; end |
#summary ⇒ Object
returns a string summarising the game data
41 42 43 44 45 46 |
# File 'lib/cricinfo/game.rb', line 41 def summary out = '' out += "%s: %s v %s (%s)\n" % [name, team1, team2, type_string] out += innings.collect { |i| i.summary }.join out end |
#type_string ⇒ Object
35 36 37 38 |
# File 'lib/cricinfo/game.rb', line 35 def type_string gtype = ["Unknown game type", "Test match", "ODI", "T20"] type >= 0 && type <= GAMETYPE_T20 ? gtype[type] : gtype[0] end |