56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/pokerstats/pokerstars_hand_history_parser.rb', line 56
def parse(line)
begin
case line
when /PokerStars Game #([0-9]+): Tournament #([0-9]+), (\$[0-9+$]+) ([^\-]*) - Level ([IVXL]+) \((#{CASH})\/(#{CASH})\) - (.*)$/
@stats.update_hand :name => "PS#{$1}", :description=> "#{$2}, #{$3} #{$4}", :tournament=> $2, :sb=> $6.to_d, :bb=> $7.to_d, :played_at=> Time.parse($8), :street => :prelude
when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH})\) - (.*)$/
@stats.update_hand :name => "PS#{$1}", :description=> "#{$2} (#{$3}/#{$4})", :tournament=> nil, :sb=> cash_to_d($3), :bb=> cash_to_d($4), :played_at=> Time.parse($5), :street => :prelude
when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH}) USD\) - (.*)$/
@stats.update_hand :name => "PS#{$1}", :description=> "#{$2} (#{$3}/#{$4})", :tournament=> nil, :sb=> cash_to_d($3), :bb=> cash_to_d($4), :played_at=> Time.parse($5), :street => :prelude
when /PokerStars Game #([0-9]+):/
raise "invalid hand record: #{line}"
when /\*\*\* HOLE CARDS \*\*\*/
@stats.register_button(@stats.button)
@stats.update_hand :street => :preflop
when /\*\*\* FLOP \*\*\* \[(.*)\]/
@stats.update_hand :street => :flop
when /\*\*\* TURN \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
@stats.update_hand :street => :turn
when /\*\*\* RIVER \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
@stats.update_hand :street => :river
when /\*\*\* SHOW DOWN \*\*\*/
@stats.update_hand :street => :showdown
when /\*\*\* SUMMARY \*\*\*/
@stats.update_hand :street => :summary
when /Dealt to ([^)]+) \[([^\]]+)\]/
@stats.register_action($1, 'dealt', :result => :cards, :data => $2)
when /(.*): shows \[(.*)\]/
@stats.register_action($1, 'shows', :result => :cards, :data => $2)
when /Board \[(.*)\]/
@stats.update_hand :board => $1
when /Total pot (#{CASH}) (((Main)|(Side)) pot(-[0-9]+)? (#{CASH}). )*\| Rake (#{CASH})/
@stats.update_hand(:total_pot => cash_to_d($1), :rake => cash_to_d($8))
when /Total pot (#{CASH}) Main pot (#{CASH}).( Side pot-[0-9]+ (#{CASH}).)* | Rake (#{CASH})/
raise "popo!"
when /Seat ([0-9]+): (.+) \(#{CASH} in chips\)( is sitting out)?/
@stats.register_player(:seat => $1.to_i, :screen_name => $2)
when /(.*): posts ((small)|(big)|(small \& big)) blind(s)? (#{CASH})/
@stats.register_action($1, 'posts', :result => :post, :amount => cash_to_d($7))
when /(.*): posts the ante (#{CASH})/
@stats.register_action($1, 'antes', :result => :post, :amount => cash_to_d($2))
when /Table '([0-9]+) ([0-9]+)' (.*) Seat #([0-9]+) is the button/
@stats.register_button($4.to_i)
when /Table '(.*)' (.*) Seat #([0-9]+) is the button/
@stats.register_button($3.to_i)
when /Uncalled bet \((.*)\) returned to (.*)/
@stats.register_action($2, 'return', :result => :win, :amount => cash_to_d($1))
when /(.+): ((folds)|(checks))/
@stats.register_action($1, $2, :result => :neutral)
when /(.+): ((calls)|(bets)) ((#{CASH})( and is all-in)?)?$/
@stats.register_action($1, $2, :result => :pay, :amount => cash_to_d($6))
when /(.+): raises (#{CASH}) to (#{CASH})( and is all-in)?$/
@stats.register_action($1, 'raises', :result => :pay_to, :amount => cash_to_d($3))
when /(.*) collected (.*) from ((side )|(main ))?pot/
@stats.register_action($1, "wins", :result => :win, :amount => cash_to_d($2))
when /Seat [0-9]+: (.*) (\((small blind)|(big blind)|(button)\) )?showed \[([^\]]+)\] and ((won) \(#{CASH}\)|(lost)) with (.*)/
when /Seat [0-9]+: (.*) mucked \[([^\]]+)\]/
else
raise "invalid line for parse: #{line}" unless ignorable?(line)
end
rescue => e
raise e
end
end
|