Class: Pokerstats::HandHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/pokerstats/hand_history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines, source, position, parser_class = PokerstarsHandHistoryParser) ⇒ HandHistory

Returns a new instance of HandHistory.



8
9
10
11
12
13
14
15
# File 'lib/pokerstats/hand_history.rb', line 8

def initialize lines, source, position, parser_class = PokerstarsHandHistoryParser
  @lines = lines
  @source = source
  @position = position
  @parsed = false
  @parser_class = parser_class
  @stats = HandStatistics.new
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



6
7
8
# File 'lib/pokerstats/hand_history.rb', line 6

def lines
  @lines
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/pokerstats/hand_history.rb', line 6

def position
  @position
end

#sourceObject

Returns the value of attribute source.



6
7
8
# File 'lib/pokerstats/hand_history.rb', line 6

def source
  @source
end

#statsObject

Returns the value of attribute stats.



6
7
8
# File 'lib/pokerstats/hand_history.rb', line 6

def stats
  @stats
end

Instance Method Details

#gameObject



17
18
19
20
# File 'lib/pokerstats/hand_history.rb', line 17

def game
  return nil if lines.empty?
  @parser_class.game lines.first
end

#parseObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pokerstats/hand_history.rb', line 26

def parse
  @parser = @parser_class.new(@stats)
  @lines.each do |each_line| 
    begin
      @parser.parse(each_line)
    rescue => e
      raise HandHistoryParseError, "#{@source}:#{position}: #{e.message}"
    end
  end
  @stats.update_hand :session_filename => source, :starting_at => position
  @parsed = true
end

#parsed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pokerstats/hand_history.rb', line 22

def parsed?
  @parsed
end

#reportsObject



39
40
41
42
# File 'lib/pokerstats/hand_history.rb', line 39

def reports
  parse unless parsed?
  @stats.reports
end