Class: SequencescapeExcel::Cell
- Inherits:
-
Object
- Object
- SequencescapeExcel::Cell
- Defined in:
- app/sequencescape_excel/sequencescape_excel/cell.rb
Overview
Holds the reference of a cell in an Excel spreadsheet based on its x (row) and y (column) position.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two cells are comparable if their row and column are the same.
-
#fixed ⇒ Object
Also known as absolute reference.
-
#initialize(x_row, y_col) ⇒ Cell
constructor
x and y position are required.
- #inspect ⇒ Object
-
#reference ⇒ Object
The column and the row which defines the reference e.g.
Constructor Details
#initialize(x_row, y_col) ⇒ Cell
x and y position are required. The row is held as is. The column is converted to an alphanumberic character e.g 1 = “A”, 27 = “AA”
13 14 15 16 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 13 def initialize(x_row, y_col) @row = x_row @column = to_alpha(y_col) end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
7 8 9 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 7 def column @column end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
7 8 9 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 7 def row @row end |
Instance Method Details
#==(other) ⇒ Object
Two cells are comparable if their row and column are the same.
34 35 36 37 38 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 34 def ==(other) return false unless other.is_a?(self.class) row == other.row && column == other.column end |
#fixed ⇒ Object
Also known as absolute reference. Used in Excel to ensure the reference does not change when copied or filled. Particularly useful for applying ranges. Designated by the addition of a dollar sign ($) e.g. $A$1
28 29 30 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 28 def fixed @fixed ||= "$#{column}$#{row}" end |
#inspect ⇒ Object
40 41 42 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 40 def inspect "<#{self.class}: @row=#{row}, @column=#{column}>" end |
#reference ⇒ Object
The column and the row which defines the reference e.g. “A1”
20 21 22 |
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 20 def reference @reference ||= "#{column}#{row}" end |