Class: Sangi::Board
- Inherits:
-
Object
- Object
- Sangi::Board
- Defined in:
- lib/sangi/board.rb
Instance Attribute Summary collapse
-
#highlight ⇒ Object
Returns the value of attribute highlight.
-
#rows ⇒ Object
Returns the value of attribute rows.
Class Method Summary collapse
Instance Method Summary collapse
- #clone_deep ⇒ Object
-
#initialize(rows:, highlight: nil) ⇒ Board
constructor
A new instance of Board.
- #place_count ⇒ Object
- #row(name) ⇒ Object
Constructor Details
#initialize(rows:, highlight: nil) ⇒ Board
Returns a new instance of Board.
15 16 17 18 |
# File 'lib/sangi/board.rb', line 15 def initialize(rows:, highlight: nil) @rows = rows @highlight = highlight end |
Instance Attribute Details
#highlight ⇒ Object
Returns the value of attribute highlight.
3 4 5 |
# File 'lib/sangi/board.rb', line 3 def highlight @highlight end |
#rows ⇒ Object
Returns the value of attribute rows.
3 4 5 |
# File 'lib/sangi/board.rb', line 3 def rows @rows end |
Class Method Details
.from_numbers(a:, b:, work:, place_count:, rod_factory:) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/sangi/board.rb', line 5 def self.from_numbers(a:, b:, work:, place_count:, rod_factory:) new( rows: { a: Row.from_integer(name: :a, value: a, place_count: place_count, rod_factory: rod_factory), b: Row.from_integer(name: :b, value: b, place_count: place_count, rod_factory: rod_factory), work: Row.from_integer(name: :work, value: work, place_count: place_count, rod_factory: rod_factory) } ) end |
Instance Method Details
#clone_deep ⇒ Object
28 29 30 31 32 33 |
# File 'lib/sangi/board.rb', line 28 def clone_deep Board.new( rows: rows.transform_values(&:clone_deep), highlight: highlight&.dup ) end |
#place_count ⇒ Object
24 25 26 |
# File 'lib/sangi/board.rb', line 24 def place_count rows.values.map { |row| row.cells.size }.max || 0 end |
#row(name) ⇒ Object
20 21 22 |
# File 'lib/sangi/board.rb', line 20 def row(name) rows.fetch(name) end |