pokerstats 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.3
1
+ 2.0.4
@@ -4,6 +4,8 @@ require File.expand_path(File.dirname(__FILE__) + '/hand_statistics')
4
4
  module Pokerstats
5
5
  CASH = "[0-9$,.]+"
6
6
 
7
+ class HandHistoryParseError < RuntimeError
8
+ end
7
9
  class PokerstarsHandHistoryParser
8
10
  def self.parse_lines(lines, stats=nil)
9
11
  parser = self.new(stats)
@@ -58,66 +60,62 @@ module Pokerstats
58
60
  end
59
61
 
60
62
  def parse(line)
61
- begin
62
- case line
63
- when /PokerStars Game #([0-9]+): Tournament #([0-9]+), (\$[0-9+$]+) ([^\-]*) - Level ([IVXL]+) \((#{CASH})\/(#{CASH})\) - (.*)$/
64
- @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
65
- when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH})\) - (.*)$/
66
- @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
67
- when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH}) USD\) - (.*)$/
68
- @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
69
- when /PokerStars Game #([0-9]+):/
70
- raise "invalid hand record: #{line}"
71
- when /\*\*\* HOLE CARDS \*\*\*/
72
- @stats.register_button(@stats.button)
73
- @stats.update_hand :street => :preflop
74
- when /\*\*\* FLOP \*\*\* \[(.*)\]/
75
- @stats.update_hand :street => :flop
76
- when /\*\*\* TURN \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
77
- @stats.update_hand :street => :turn
78
- when /\*\*\* RIVER \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
79
- @stats.update_hand :street => :river
80
- when /\*\*\* SHOW DOWN \*\*\*/
81
- @stats.update_hand :street => :showdown
82
- when /\*\*\* SUMMARY \*\*\*/
83
- @stats.update_hand :street => :summary
84
- when /Dealt to ([^)]+) \[([^\]]+)\]/
85
- @stats.register_action($1, 'dealt', :result => :cards, :data => $2)
86
- when /(.*): shows \[(.*)\]/
87
- @stats.register_action($1, 'shows', :result => :cards, :data => $2)
88
- when /Board \[(.*)\]/
89
- @stats.update_hand :board => $1
90
- when /Total pot (#{CASH}) (((Main)|(Side)) pot(-[0-9]+)? (#{CASH}). )*\| Rake (#{CASH})/
91
- @stats.update_hand(:total_pot => cash_to_d($1), :rake => cash_to_d($8))
92
- when /Total pot (#{CASH}) Main pot (#{CASH}).( Side pot-[0-9]+ (#{CASH}).)* | Rake (#{CASH})/
93
- raise "popo!"
94
- when /Seat ([0-9]+): (.+) \(#{CASH} in chips\)( is sitting out)?/
95
- @stats.register_player(:seat => $1.to_i, :screen_name => $2)
96
- when /(.*): posts ((small)|(big)|(small \& big)) blind(s)? (#{CASH})/
97
- @stats.register_action($1, 'posts', :result => :post, :amount => cash_to_d($7))
98
- when /(.*): posts the ante (#{CASH})/
99
- @stats.register_action($1, 'antes', :result => :post, :amount => cash_to_d($2))
100
- when /Table '([0-9]+) ([0-9]+)' (.*) Seat #([0-9]+) is the button/
101
- @stats.register_button($4.to_i)
102
- when /Table '(.*)' (.*) Seat #([0-9]+) is the button/
103
- @stats.register_button($3.to_i)
104
- when /Uncalled bet \((.*)\) returned to (.*)/
105
- @stats.register_action($2, 'return', :result => :win, :amount => cash_to_d($1))
106
- when /(.+): ((folds)|(checks))/
107
- @stats.register_action($1, $2, :result => :neutral)
108
- when /(.+): ((calls)|(bets)) ((#{CASH})( and is all-in)?)?$/
109
- @stats.register_action($1, $2, :result => :pay, :amount => cash_to_d($6))
110
- when /(.+): raises (#{CASH}) to (#{CASH})( and is all-in)?$/
111
- @stats.register_action($1, 'raises', :result => :pay_to, :amount => cash_to_d($3))
112
- when /(.*) collected (.*) from ((side )|(main ))?pot/
113
- @stats.register_action($1, "wins", :result => :win, :amount => cash_to_d($2))
114
- when /Seat [0-9]+: (.*) (\((small blind)|(big blind)|(button)\) )?showed \[([^\]]+)\] and ((won) \(#{CASH}\)|(lost)) with (.*)/
115
- when /Seat [0-9]+: (.*) mucked \[([^\]]+)\]/
116
- else
117
- raise "invalid line for parse: #{line}" unless ignorable?(line)
118
- end
119
- rescue => e
120
- raise e
63
+ case line
64
+ when /PokerStars Game #([0-9]+): Tournament #([0-9]+), (\$[0-9+$]+) ([^\-]*) - Level ([IVXL]+) \((#{CASH})\/(#{CASH})\) - (.*)$/
65
+ @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
66
+ when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH})\) - (.*)$/
67
+ @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
68
+ when /PokerStars Game #([0-9]+): +([^(]*) \((#{CASH})\/(#{CASH}) USD\) - (.*)$/
69
+ @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
70
+ when /PokerStars Game #([0-9]+):/
71
+ raise HandHistoryParseError, "invalid hand record: #{line}"
72
+ when /\*\*\* HOLE CARDS \*\*\*/
73
+ @stats.register_button(@stats.button)
74
+ @stats.update_hand :street => :preflop
75
+ when /\*\*\* FLOP \*\*\* \[(.*)\]/
76
+ @stats.update_hand :street => :flop
77
+ when /\*\*\* TURN \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
78
+ @stats.update_hand :street => :turn
79
+ when /\*\*\* RIVER \*\*\* \[([^\]]*)\] \[([^\]]*)\]/
80
+ @stats.update_hand :street => :river
81
+ when /\*\*\* SHOW DOWN \*\*\*/
82
+ @stats.update_hand :street => :showdown
83
+ when /\*\*\* SUMMARY \*\*\*/
84
+ @stats.update_hand :street => :summary
85
+ when /Dealt to ([^)]+) \[([^\]]+)\]/
86
+ @stats.register_action($1, 'dealt', :result => :cards, :data => $2)
87
+ when /(.*): shows \[(.*)\]/
88
+ @stats.register_action($1, 'shows', :result => :cards, :data => $2)
89
+ when /Board \[(.*)\]/
90
+ @stats.update_hand :board => $1
91
+ when /Total pot (#{CASH}) (((Main)|(Side)) pot(-[0-9]+)? (#{CASH}). )*\| Rake (#{CASH})/
92
+ @stats.update_hand(:total_pot => cash_to_d($1), :rake => cash_to_d($8))
93
+ when /Total pot (#{CASH}) Main pot (#{CASH}).( Side pot-[0-9]+ (#{CASH}).)* | Rake (#{CASH})/
94
+ raise HandHistoryParseError, "popo!"
95
+ when /Seat ([0-9]+): (.+) \(#{CASH} in chips\)( is sitting out)?/
96
+ @stats.register_player(:seat => $1.to_i, :screen_name => $2)
97
+ when /(.*): posts ((small)|(big)|(small \& big)) blind(s)? (#{CASH})/
98
+ @stats.register_action($1, 'posts', :result => :post, :amount => cash_to_d($7))
99
+ when /(.*): posts the ante (#{CASH})/
100
+ @stats.register_action($1, 'antes', :result => :post, :amount => cash_to_d($2))
101
+ when /Table '([0-9]+) ([0-9]+)' (.*) Seat #([0-9]+) is the button/
102
+ @stats.register_button($4.to_i)
103
+ when /Table '(.*)' (.*) Seat #([0-9]+) is the button/
104
+ @stats.register_button($3.to_i)
105
+ when /Uncalled bet \((.*)\) returned to (.*)/
106
+ @stats.register_action($2, 'return', :result => :win, :amount => cash_to_d($1))
107
+ when /(.+): ((folds)|(checks))/
108
+ @stats.register_action($1, $2, :result => :neutral)
109
+ when /(.+): ((calls)|(bets)) ((#{CASH})( and is all-in)?)?$/
110
+ @stats.register_action($1, $2, :result => :pay, :amount => cash_to_d($6))
111
+ when /(.+): raises (#{CASH}) to (#{CASH})( and is all-in)?$/
112
+ @stats.register_action($1, 'raises', :result => :pay_to, :amount => cash_to_d($3))
113
+ when /(.*) collected (.*) from ((side )|(main ))?pot/
114
+ @stats.register_action($1, "wins", :result => :win, :amount => cash_to_d($2))
115
+ when /Seat [0-9]+: (.*) (\((small blind)|(big blind)|(button)\) )?showed \[([^\]]+)\] and ((won) \(#{CASH}\)|(lost)) with (.*)/
116
+ when /Seat [0-9]+: (.*) mucked \[([^\]]+)\]/
117
+ else
118
+ raise HandHistoryParseError, "invalid line for parse: #{line}" unless ignorable?(line)
121
119
  end
122
120
  end
123
121
 
data/pokerstats.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pokerstats}
8
- s.version = "2.0.3"
8
+ s.version = "2.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew C. Greenberg"]
12
- s.date = %q{2009-10-30}
12
+ s.date = %q{2009-10-31}
13
13
  s.default_executable = %q{checkps}
14
14
  s.description = %q{a library for extracting, computing and reporting statistics of poker hands parsed from hand history files}
15
15
  s.email = %q{wizardwerdna@gmail.com}
@@ -8,7 +8,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../lib/pokerstats/hand_stati
8
8
  require File.expand_path(File.dirname(__FILE__) + '/../lib/pokerstats/pokerstars_file')
9
9
  require File.expand_path(File.dirname(__FILE__) + '/../lib/pokerstats/pokerstars_hand_history_parser')
10
10
  include Pokerstats
11
-
12
11
  include HandConstants
13
12
 
14
13
  describe PokerstarsHandHistoryParser, "recognizes valid hand history" do
@@ -21,7 +20,7 @@ describe PokerstarsHandHistoryParser, "recognizes valid hand history" do
21
20
  PokerstarsHandHistoryParser.game(first_line).should == "PS21650146783"
22
21
  end
23
22
  it "should reject an invalid hand history" do
24
- PokerstarsHandHistoryParser.game("an invalid hand history")
23
+ PokerstarsHandHistoryParser.game("an invalid hand history").should raise_error
25
24
  end
26
25
  end
27
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pokerstats
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew C. Greenberg
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-30 00:00:00 -07:00
12
+ date: 2009-10-31 00:00:00 -07:00
13
13
  default_executable: checkps
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency