Class: Pokerstats::CashStatistics
- Inherits:
-
HandStatistics::Plugin
- Object
- HandStatistics::Plugin
- Pokerstats::CashStatistics
- Defined in:
- lib/pokerstats/plugins/cash_statistics.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply_action(action, street) ⇒ Object
- #cards(player) ⇒ Object
-
#initialize(handstatistics) ⇒ CashStatistics
constructor
A new instance of CashStatistics.
- #paid(player) ⇒ Object
- #paid_this_round(player) ⇒ Object
- #posted(player) ⇒ Object
- #register_player(screen_name, street) ⇒ Object
-
#stats(player = nil) ⇒ Object
def report(screen_name) { :posted => posted(screen_name), :paid => paid(screen_name), :won => won(screen_name), :cards => cards(screen_name) } end.
- #street_transition_for_player(street, player) ⇒ Object
- #won(player) ⇒ Object
Constructor Details
#initialize(handstatistics) ⇒ CashStatistics
Returns a new instance of CashStatistics.
3 4 5 6 7 8 9 10 11 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 3 def initialize handstatistics super handstatistics @posted = {} @paid = {} @paid_this_round = {} @won = {} @cards = {} @stats = {:posted => @posted, :paid => @paid, :won => @won, :cards => @cards} end |
Class Method Details
.report_specification ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 33 def self.report_specification [ # [key, sql_type, function] [:posted, 'decimal', :posted], [:paid, 'decimal', :paid], [:won, 'decimal', :won], [:cards, 'string', :cards] ] end |
Instance Method Details
#apply_action(action, street) ⇒ Object
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 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 67 def apply_action action, street player = action[:screen_name] description = action[:description] result = action[:result] amount = action[:amount] data = action[:data] case result when :post @posted[player] += amount @paid_this_round[player] += amount unless description == "antes" when :pay @paid[player] ||= 0 @paid[player] += amount @paid_this_round[player] += amount when :pay_to net_amount_paid = amount - @paid_this_round[player] action[:net_amount_paid] = net_amount_paid @paid[player] += net_amount_paid @paid_this_round[player] += net_amount_paid when :win @won[player] += amount when :neutral when :cards @cards[player] = data else raise "invalid action result: #{result.inspect}" end end |
#cards(player) ⇒ Object
29 30 31 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 29 def cards(player) @cards[player] end |
#paid(player) ⇒ Object
17 18 19 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 17 def paid(player) @paid[player] end |
#paid_this_round(player) ⇒ Object
21 22 23 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 21 def paid_this_round(player) @paid_this_round[player] end |
#posted(player) ⇒ Object
13 14 15 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 13 def posted(player) @posted[player] end |
#register_player(screen_name, street) ⇒ Object
57 58 59 60 61 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 57 def register_player(screen_name, street) @posted[screen_name] = 0 @paid[screen_name] = 0 @won[screen_name] = 0 end |
#stats(player = nil) ⇒ Object
def report(screen_name)
{
:posted => posted(screen_name),
:paid => paid(screen_name),
:won => won(screen_name),
:cards => cards(screen_name)
}
end
52 53 54 55 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 52 def stats(player=nil) return @stats unless player # @stats.inject({}){|last, pair| last.merge(pair[0] => pair[1][player])} end |
#street_transition_for_player(street, player) ⇒ Object
63 64 65 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 63 def street_transition_for_player street, player @paid_this_round[player] = 0 unless street == :preflop end |
#won(player) ⇒ Object
25 26 27 |
# File 'lib/pokerstats/plugins/cash_statistics.rb', line 25 def won(player) @won[player] end |