Class: SequencescapeExcel::ConditionalFormatting

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

Overview

A single conditional formatting rule. This will consist of:

  • options: which relate to Excel options e.g. type: :cellIs

  • style: The style which will be added when conditional formatting applies.

  • formula: See Formula class.

Instance Method Summary collapse

Methods included from Helpers::Attributes

#<=>, #to_a

Constructor Details

#initialize(attributes = {}) ⇒ ConditionalFormatting

Returns a new instance of ConditionalFormatting


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

def initialize(attributes = {})
  super
end

Instance Method Details

#formula=(options) ⇒ Object

Create a new Formula object.


34
35
36
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 34

def formula=(options)
  @formula = Formula.new(options)
end

#initialize_dup(source) ⇒ Object


56
57
58
59
60
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 56

def initialize_dup(source)
  self.options = source.options.dup
  self.formula = source.formula.to_h if source.formula.present?
  super
end

#inspectObject


62
63
64
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 62

def inspect
  "<#{self.class}: @name=#{name}, @options=#{options}, @style=#{style}, @formula=#{formula}>"
end

#styled?Boolean

A conditional formatting is styled if the dxfId is present.

Returns:

  • (Boolean)

40
41
42
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 40

def styled?
  options['dxfId'].present?
end

#to_hObject

Return the options as a hash


52
53
54
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 52

def to_h
  options.to_hash
end

#update(attributes = {}) ⇒ Object

If a worksheet attribute is present then add the conditional formatting style to the workbook. If conditional formatting has a formula then update the formula option with the passed attributes.


26
27
28
29
30
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting.rb', line 26

def update(attributes = {})
  options['dxfId'] = attributes[:worksheet].workbook.styles.add_style(style) if attributes[:worksheet].present?
  options['formula'] = formula.update(attributes).to_s if formula.present?
  self
end