Class: Hotkey

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/hotkey.rb

Constant Summary

MIN_WAGER_LABEL =
'Min'
ALL_IN_WAGER_LABEL =
'All-in'
FOLD_LABEL =
'Fold'
PASS_LABEL =
'Check / Call'
WAGER_LABEL =
'Bet / Raise'
NEXT_HAND_LABEL =
'Next Hand'
LEAVE_MATCH_LABEL =
'Leave Match'
POT_LABEL =
'Pot'
MAX_POT_FRACTION_PRECISION =

Round to avoid unreasonably large strings

4
HOTKEY_LABELS_TO_ELEMENTS_TO_CLICK =
{
  FOLD_LABEL => ".fold",
  PASS_LABEL => ".pass",
  WAGER_LABEL => ".wager",
  NEXT_HAND_LABEL => ".next_state",
  LEAVE_MATCH_LABEL => ".leave"
}
DEFAULT_HOTKEYS =
{
  FOLD_LABEL => 'A',
  PASS_LABEL => 'S',
  WAGER_LABEL => 'D',
  NEXT_HAND_LABEL => 'F',
  LEAVE_MATCH_LABEL => 'Q',
  MIN_WAGER_LABEL => 'Z',
  ALL_IN_WAGER_LABEL => 'N',
  wager_hotkey_label(1/2.to_f) => 'X',
  wager_hotkey_label(3/4.to_f) => 'C',
  wager_hotkey_label(1) => 'V',
  wager_hotkey_label(2) => 'B'
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.include_actionObject



8
9
10
11
12
13
# File 'app/models/hotkey.rb', line 8

def self.include_action
  field :action, type: String
  validates_presence_of :action
  validates_format_of :action, without: /^\s*$/
  validates_uniqueness_of :action
end

.include_keyObject



17
18
19
20
21
22
# File 'app/models/hotkey.rb', line 17

def self.include_key
  field :key, type: String
  validates_presence_of :key
  validates_format_of :key, without: /^\s*$/
  validates_uniqueness_of :key
end

.wager_hotkey_label(pot_fraction) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'app/models/hotkey.rb', line 38

def self.wager_hotkey_label(pot_fraction)
  if pot_fraction == 1
    POT_LABEL
  elsif pot_fraction.to_i == pot_fraction
    "#{pot_fraction.to_i}xPot"
  else
    "#{pot_fraction.round(MAX_POT_FRACTION_PRECISION)}xPot"
  end
end

Instance Method Details

#hotkey_pot_fractionNumeric

Returns The pot fraction corresponding to this hotkey label, or zero if the hotkey doesn't correspond to a pot fraction wager.

Returns:

  • (Numeric)

    The pot fraction corresponding to this hotkey label, or zero if the hotkey doesn't correspond to a pot fraction wager.



70
71
72
# File 'app/models/hotkey.rb', line 70

def hotkey_pot_fraction
  (if POT_LABEL == action then 1 else action end).to_f
end

#wager_hotkey?Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'app/models/hotkey.rb', line 73

def wager_hotkey?
  (
    hotkey_pot_fraction > 0.0 ||
    action == MIN_WAGER_LABEL ||
    action == ALL_IN_WAGER_LABEL
  )
end