Class: CricInfo::Game

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeGame

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

#inningsObject

Returns the value of attribute innings.



16
17
18
# File 'lib/cricinfo/game.rb', line 16

def innings
  @innings
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/cricinfo/game.rb', line 16

def name
  @name
end

#start_timeObject

Returns the value of attribute start_time.



16
17
18
# File 'lib/cricinfo/game.rb', line 16

def start_time
  @start_time
end

#team1Object

team1 is the team batting first (first innings)



18
19
20
# File 'lib/cricinfo/game.rb', line 18

def team1
  @team1
end

#team2Object

team1 is the team batting first (first innings)



18
19
20
# File 'lib/cricinfo/game.rb', line 18

def team2
  @team2
end

#typeObject

Returns the value of attribute type.



16
17
18
# File 'lib/cricinfo/game.rb', line 16

def type
  @type
end

Instance Method Details

#add_inningsObject



30
31
32
33
# File 'lib/cricinfo/game.rb', line 30

def add_innings
  @innings.push(Innings.new)
  @innings[-1]
end

#inns1Object



25
# File 'lib/cricinfo/game.rb', line 25

def inns1; @innings[0]; end

#inns2Object



26
# File 'lib/cricinfo/game.rb', line 26

def inns2; @innings[1]; end

#inns3Object



27
# File 'lib/cricinfo/game.rb', line 27

def inns3; @innings[2]; end

#inns4Object



28
# File 'lib/cricinfo/game.rb', line 28

def inns4; @innings[3]; end

#summaryObject

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_stringObject



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