Class: SequencescapeExcel::Formula

Inherits:
Object
  • Object
show all
Includes:
Helpers::Attributes
Defined in:
app/sequencescape_excel/sequencescape_excel/formula.rb

Overview

Applied to conditional formatting to highlight important information in a spreadsheet. Used where built in formulae don't do the job. There are four types of special formulae:

  • ISTEXT - checks whether each value in the cell for a column is a text value.

  • ISNUMBER - checks whether each value in the cell for a column is a number.

  • LEN - checks how long each value in the cell for a column is depending on the operator and operand.

  • ISERROR - check whether each value in the cell for a column is within a range defined by the absolute reference of that range.

Instance Method Summary collapse

Methods included from Helpers::Attributes

#<=>, #to_a

Constructor Details

#initialize(attributes = {}) ⇒ Formula

Returns a new instance of Formula


17
18
19
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 17

def initialize(attributes = {})
  super(default_attributes.merge(attributes.slice(*self.attributes)))
end

Instance Method Details

#inspectObject


55
56
57
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 55

def inspect
  "<#{self.class}: @type=#{type}, @first_cell_reference=#{first_cell_reference}, @absolute_reference=#{absolute_reference}, @operator=#{operator}, @operand#{operand}>"
end

#to_hObject


45
46
47
48
49
50
51
52
53
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 45

def to_h
  {
    type: type,
    first_cell_reference: first_cell_reference,
    absolute_reference: absolute_reference,
    operator: operator,
    operand: operand
  }
end

#to_sObject

Returns a string representation of the formula.


32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 32

def to_s
  case type
  when :is_text
    "ISTEXT(#{first_cell_reference})"
  when :is_number
    "ISNUMBER(#{first_cell_reference})"
  when :len
    "LEN(#{first_cell_reference})#{operator}#{operand}"
  when :is_error
    "AND(NOT(ISBLANK(#{first_cell_reference})),ISERROR(MATCH(#{first_cell_reference},#{absolute_reference},0)>0))"
  end
end

#type=(type) ⇒ Object


26
27
28
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 26

def type=(type)
  @type = type.to_sym
end

#update(attributes = {}) ⇒ Object


21
22
23
24
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 21

def update(attributes = {})
  assign_attributes(attributes.with_indifferent_access.slice(*self.attributes))
  self
end