Class: ExcelAbstraction::CellReference
- Inherits:
-
Object
- Object
- ExcelAbstraction::CellReference
- Includes:
- Comparable
- Defined in:
- lib/excel_templating/excel_abstraction/cell_reference.rb
Constant Summary collapse
- COLS =
('A'..'ZZ').to_a
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#row ⇒ Object
Returns the value of attribute row.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(attrs = {}) ⇒ CellReference
constructor
A new instance of CellReference.
- #succ ⇒ Object
- #to_a ⇒ Object
- #to_ary ⇒ Object
- #to_cell_reference ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ CellReference
Returns a new instance of CellReference.
9 10 11 12 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 9 def initialize(attrs = {}) @row = attrs.fetch(:row) { 0 } @col = attrs.fetch(:col) { 0 } end |
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
7 8 9 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 7 def col @col end |
#row ⇒ Object
Returns the value of attribute row.
7 8 9 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 7 def row @row end |
Instance Method Details
#<=>(other) ⇒ Object
14 15 16 17 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 14 def <=>(other) other = other.to_cell_reference (self.row == other.row) ? (self.col <=> other.col) : (self.row <=> other.row) end |
#succ ⇒ Object
19 20 21 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 19 def succ self.class.new(row: self.row, col: self.col + 1) end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 35 def to_a to_ary end |
#to_ary ⇒ Object
31 32 33 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 31 def to_ary [row, col] end |
#to_cell_reference ⇒ Object
27 28 29 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 27 def to_cell_reference self end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 23 def to_s COLS[col] + (row + 1).to_s end |