Class: SequencescapeExcel::Formula
- Inherits:
-
Object
- Object
- SequencescapeExcel::Formula
- 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
-
#initialize(attributes = {}) ⇒ Formula
constructor
A new instance of Formula.
- #inspect ⇒ Object
- #to_h ⇒ Object
-
#to_s ⇒ Object
Returns a string representation of the formula.
- #type=(type) ⇒ Object
- #update(attributes = {}) ⇒ Object
Methods included from Helpers::Attributes
Constructor Details
#initialize(attributes = {}) ⇒ Formula
Returns a new instance of Formula.
27 28 29 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 27 def initialize(attributes = {}) super(default_attributes.merge(attributes.slice(*self.attributes))) end |
Instance Method Details
#inspect ⇒ Object
59 60 61 62 63 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 59 def inspect # rubocop:todo Layout/LineLength "<#{self.class}: @type=#{type}, @first_cell_reference=#{first_cell_reference}, @absolute_reference=#{absolute_reference}, @operator=#{operator}, @operand#{operand}>" # rubocop:enable Layout/LineLength end |
#to_h ⇒ Object
55 56 57 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 55 def to_h { type:, first_cell_reference:, absolute_reference:, operator:, operand: } end |
#to_s ⇒ Object
Returns a string representation of the formula.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 42 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
36 37 38 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 36 def type=(type) @type = type.to_sym end |
#update(attributes = {}) ⇒ Object
31 32 33 34 |
# File 'app/sequencescape_excel/sequencescape_excel/formula.rb', line 31 def update(attributes = {}) assign_attributes(attributes.with_indifferent_access.slice(*self.attributes)) self end |