Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Phander::Parsers
- class Pokerstars < Base
- Stages = {
- :hole => 'HOLE CARDS',
- :flop => 'FLOP',
- :turn => 'TURN',
- :river => 'RIVER'}
- def self.this_parser?(string)
- string[0..9] == 'PokerStars'
- end
- def go
- @data[:title] = title
- @data[:seats] = seats
- @data[:title][:number_of_players] = @data[:seats].size
- @data[:blinds] = blinds
- @data[:stages] = stages
- @data[:summary] = summary
- @data
- end
- def title
- @s.scan(/PokerStars Game #(\d+): (.+) -/)
- {:hand_id => @s[1], :table_type => @s[2]}
- end
- def seats
- @s.skip_until(/is the button\s*\n/)
- seats = []
- while @s.check(/Seat/)
- @s.scan(/Seat (\d): (.+) \(\$([\d\.]+) in chips\)/)
- seats << {:seat_number => @s[1], :name => @s[2], :chips => @s[3].to_f}
- @s.skip_until(/\s*\n/)
- end
- seats
- end
- def blinds
- @s.scan(/(.+): posts small blind \$([\d\.]+)\s+/)
- small = {:name => @s[1], :amount => @s[2].to_f}
- @s.scan(/(.+): posts big blind \$([\d\.]+)\s+/)
- big = {:name => @s[1], :amount => @s[2].to_f}
- {:small => small, :big => big}
- end
- def stages
- stages_ar = Stages.map{|v| v[1]}
- @s.skip_until(/\*\*\* /)
- stages = []
- while @s.check(/[^\*]+/) && stages_ar.include?(@s.matched.strip)
- stage_name = @s.matched
- @s.pos += @s.matched_size
- @s.skip(/\*\*\*/)
- if @s.check(/ \[(.+?)\]/)
- stage_cards = @s[1]
- @s.pos += @s.matched_size
- if @s.check(/ \[(.+?)\]/)
- stage_cards << " #{@s[1]}"
- @s.pos += @s.matched_size
- end
- else
- stage_cards = nil
- end
- @s.skip_until(/\s*\n/)
- stage_actions = []
- while !@s.check(/\*\*\*/)
- unless @s.check(/Uncalled/)
- action = {:name => @s.scan(/[^:]+/)}
- @s.skip(/[\s:]+/)
- ActionParsers.detect do |k, v|
- if @s.check(v[:pattern])
- action[:type] = k
- v.reject{|k2, v2| k2 == :pattern}.each {|k2, v2| action[k2] = @s[v2].to_f}
- true
- else
- false
- end
- end
- stage_actions << action
- end
- @s.skip_until(/\s*\n/)
- end
- stages << {:name => stage_name, :cards => (stage_cards ? Phander.hand(stage_cards) : nil), :actions => stage_actions}
- @s.skip_until(/\*\*\* /)
- end
- stages
- end
- def summary
- @s.skip_until(/\*\*\* SUMMARY \*\*\*/)
- @s.skip_until(/\s*\n/)
- @s.scan(/Total pot \$([\d\.]+) \| Rake \$([\d\.]+)/)
- pot = @s[1].to_f
- rake = @s[2].to_f
- @s.skip_until(/\s*\n/)
- @s.scan(/Board \[(.+?)\]/)
- board = @s[1]
- winner = {}
- showers = []
- while @s.skip_until(/\s*\n/) && !@s.eos?
- N
- end
- {:pot => pot, :rake => rake, :board => Phander.hand(board), :winner => winner, :showers => showers}
- end
- end
- end
Add Comment
Please, Sign In to add comment