Class: CardNine::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/card_nine/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#discardsObject (readonly)

Returns the value of attribute discards.



3
4
5
# File 'lib/card_nine/table.rb', line 3

def discards
  @discards
end

#shoeObject (readonly)

Returns the value of attribute shoe.



3
4
5
# File 'lib/card_nine/table.rb', line 3

def shoe
  @shoe
end

#stagesObject (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

Parameters:

  • loc (String, Symbol)

    which location to see



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

#locationsObject



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