Class: SequencescapeExcel::ConditionalFormattingList

Inherits:
Object
  • Object
show all
Includes:
List
Defined in:
app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb

Overview

A list of conditional formattings for a single entity e.g. Column.

Instance Method Summary collapse

Methods included from List

#<=>, #add, #add_copy, #each, #find, #find_by, #inspect, #items, #reset!, #values

Constructor Details

#initialize(conditional_formattings = {}) {|_self| ... } ⇒ ConditionalFormattingList

Returns a new instance of ConditionalFormattingList.

Yields:

  • (_self)

Yield Parameters:


13
14
15
16
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 13

def initialize(conditional_formattings = {})
  create_conditional_formattings(conditional_formattings)
  yield self if block_given?
end

Instance Method Details

#create_conditional_formattings(conditional_formattings) ⇒ Object

create a new conditional formatting for each item in the passed hash for each key.


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

def create_conditional_formattings(conditional_formattings)
  conditional_formattings.each do |key, conditional_formatting|
    add(if conditional_formatting.is_a?(Hash)
          ConditionalFormatting.new(conditional_formatting.merge(name: key))
        else
          key.dup
        end)
  end
end

#initialize_dup(source) ⇒ Object

The conditional formattings instance variable needs to be reset to an empty hash otherwise the hash is still copied and will not duplicate correctly.


63
64
65
66
67
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 63

def initialize_dup(source)
  reset!
  create_conditional_formattings(source.conditional_formattings)
  super
end

#optionsObject

Collect all of the options for each item in the list.


37
38
39
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 37

def options
  collect(&:options)
end

#saved?Boolean

A list has been saved if the options have been passed to a worksheet.

Returns:

  • (Boolean)

56
57
58
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 56

def saved?
  @saved.present?
end

#update(attributes = {}) ⇒ Object

Forwarding method. Calls update on each conditional formatting. If the attributes contain a worksheet will add all of the options for the list to a reference in the worksheet.


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 22

def update(attributes = {})
  each do |conditional_formatting|
    conditional_formatting.update(attributes)
  end

  if attributes[:worksheet].present? && conditional_formattings.any?
    @saved = attributes[:worksheet].add_conditional_formatting(attributes[:reference],
                                                               options)
  end

  self
end