Class: EideticRML::Support::Grid
- Inherits:
-
Object
- Object
- EideticRML::Support::Grid
- Defined in:
- lib/erml_support.rb
Instance Attribute Summary collapse
-
#cols ⇒ Object
Returns the value of attribute cols.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
- #[](col, row) ⇒ Object
- #[]=(col, row, value) ⇒ Object
- #col(index) ⇒ Object
-
#initialize(cols, rows) ⇒ Grid
constructor
A new instance of Grid.
- #row(index) ⇒ Object
Constructor Details
#initialize(cols, rows) ⇒ Grid
Returns a new instance of Grid.
61 62 63 64 |
# File 'lib/erml_support.rb', line 61 def initialize(cols, rows) @cols, @rows = cols, rows @cells = Array.new(cols * rows) end |
Instance Attribute Details
#cols ⇒ Object
Returns the value of attribute cols.
58 59 60 |
# File 'lib/erml_support.rb', line 58 def cols @cols end |
#rows ⇒ Object
Returns the value of attribute rows.
59 60 61 |
# File 'lib/erml_support.rb', line 59 def rows @rows end |
Instance Method Details
#[](col, row) ⇒ Object
84 85 86 |
# File 'lib/erml_support.rb', line 84 def [](col, row) @cells[row * cols + col] end |
#[]=(col, row, value) ⇒ Object
88 89 90 91 92 |
# File 'lib/erml_support.rb', line 88 def []=(col, row, value) self.rows = row + 1 if row >= rows self.cols = col + 1 if col >= cols @cells[row * cols + col] = value end |
#col(index) ⇒ Object
94 95 96 97 98 |
# File 'lib/erml_support.rb', line 94 def col(index) result = [] rows.times { |row| result << self[index, row] } result end |
#row(index) ⇒ Object
100 101 102 |
# File 'lib/erml_support.rb', line 100 def row(index) @cells.slice(index * cols, cols) end |