Class: CardNine::Table
- Inherits:
-
Object
- Object
- CardNine::Table
- Defined in:
- lib/card_nine/table.rb
Instance Attribute Summary collapse
-
#discards ⇒ Object
readonly
Returns the value of attribute discards.
-
#shoe ⇒ Object
readonly
Returns the value of attribute shoe.
-
#stages ⇒ Object
readonly
Returns the value of attribute stages.
Instance Method Summary collapse
- #cards_for(loc) ⇒ Object
- #deal(count = 1, from: :shoe, to:) ⇒ Object
- #deal_each_matching(count = 1, &blk) ⇒ Object
-
#initialize(shoe, locations, stages: {}) ⇒ Table
constructor
A new instance of Table.
- #locations ⇒ Object
- #match_locations(&blk) ⇒ Object
- #register_location(loc_name, loc_container) ⇒ Object
Constructor Details
#initialize(shoe, locations, stages: {}) ⇒ Table
Returns a new instance of Table.
5 6 7 8 9 10 11 12 |
# File 'lib/card_nine/table.rb', line 5 def initialize(shoe, locations, stages: {}) @shoe = shoe @discards = [] @locations = locations @stages = stages register_location(:shoe, shoe) register_location(:discards, @discards) end |
Instance Attribute Details
#discards ⇒ Object (readonly)
Returns the value of attribute discards.
3 4 5 |
# File 'lib/card_nine/table.rb', line 3 def discards @discards end |
#shoe ⇒ Object (readonly)
Returns the value of attribute shoe.
3 4 5 |
# File 'lib/card_nine/table.rb', line 3 def shoe @shoe end |
#stages ⇒ Object (readonly)
Returns the value of attribute stages.
3 4 5 |
# File 'lib/card_nine/table.rb', line 3 def stages @stages end |
Instance Method Details
#cards_for(loc) ⇒ Object
24 25 26 |
# File 'lib/card_nine/table.rb', line 24 def cards_for(loc) @locations[loc] end |
#deal(count = 1, from: :shoe, to:) ⇒ Object
28 29 30 |
# File 'lib/card_nine/table.rb', line 28 def deal(count = 1, from: :shoe, to:) cards_for(to).push(*cards_for(from).pop(count)) end |
#deal_each_matching(count = 1, &blk) ⇒ Object
32 33 34 |
# File 'lib/card_nine/table.rb', line 32 def deal_each_matching(count = 1, &blk) count.times { match_locations(&blk).each { |p| deal(to: p) } } end |
#locations ⇒ Object
18 19 20 |
# File 'lib/card_nine/table.rb', line 18 def locations @locations.keys end |
#match_locations(&blk) ⇒ Object
36 37 38 |
# File 'lib/card_nine/table.rb', line 36 def match_locations(&blk) locations.select { |e| blk.call(e, cards_for(e)) } end |
#register_location(loc_name, loc_container) ⇒ Object
14 15 16 |
# File 'lib/card_nine/table.rb', line 14 def register_location(loc_name, loc_container) @locations[loc_name] = loc_container end |