Class: ExcelAbstraction::CellReference

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/excel_templating/excel_abstraction/cell_reference.rb

Constant Summary collapse

COLS =
('A'..'ZZ').to_a

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colObject

Returns the value of attribute col.



7
8
9
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 7

def col
  @col
end

#rowObject

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

#succObject



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_aObject



35
36
37
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 35

def to_a
  to_ary
end

#to_aryObject



31
32
33
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 31

def to_ary
  [row, col]
end

#to_cell_referenceObject



27
28
29
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 27

def to_cell_reference
  self
end

#to_sObject



23
24
25
# File 'lib/excel_templating/excel_abstraction/cell_reference.rb', line 23

def to_s
  COLS[col] + (row + 1).to_s
end