Class: Gobstones::Runner::Cell
- Inherits:
-
Object
- Object
- Gobstones::Runner::Cell
- Defined in:
- lib/gobstones/runner/cell.rb
Instance Method Summary collapse
- #are_there_balls?(color) ⇒ Boolean
- #clone ⇒ Object
- #empty! ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Cell
constructor
A new instance of Cell.
- #number_of_balls(color) ⇒ Object
- #put(color) ⇒ Object
- #take_out(color) ⇒ Object
Constructor Details
Instance Method Details
#are_there_balls?(color) ⇒ Boolean
22 23 24 25 |
# File 'lib/gobstones/runner/cell.rb', line 22 def are_there_balls?(color) check(color) number_of_balls(color).positive? end |
#clone ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/gobstones/runner/cell.rb', line 40 def clone self.class.new.tap do |copy| Color.all.map(&:new).each do |color| number_of_balls(color).times { copy.put(color) } end end end |
#empty! ⇒ Object
32 33 34 |
# File 'lib/gobstones/runner/cell.rb', line 32 def empty! initialize end |
#empty? ⇒ Boolean
36 37 38 |
# File 'lib/gobstones/runner/cell.rb', line 36 def empty? @values.values.all?(&:zero?) end |
#number_of_balls(color) ⇒ Object
27 28 29 30 |
# File 'lib/gobstones/runner/cell.rb', line 27 def number_of_balls(color) check(color) lookup(color) end |
#put(color) ⇒ Object
10 11 12 13 |
# File 'lib/gobstones/runner/cell.rb', line 10 def put(color) check(color) lookup(color) { |value| value + 1 } end |
#take_out(color) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/gobstones/runner/cell.rb', line 15 def take_out(color) check(color) raise EmptyCellError unless are_there_balls?(color) lookup(color) { |value| value - 1 } end |