Class: SequencescapeExcel::Cell

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#columnObject (readonly)

Returns the value of attribute column


7
8
9
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 7

def column
  @column
end

#rowObject (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
39
# 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

#fixedObject

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

#inspectObject


41
42
43
# File 'app/sequencescape_excel/sequencescape_excel/cell.rb', line 41

def inspect
  "<#{self.class}: @row=#{row}, @column=#{column}>"
end

#referenceObject

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