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.



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

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

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pokerstats/hand_history.rb', line 20

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

#parsed?Boolean

Returns:

  • (Boolean)


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

def parsed?
  @parsed
end

#reportsObject



33
34
35
36
# File 'lib/pokerstats/hand_history.rb', line 33

def reports
  parse unless parsed?
  @stats.reports
end