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.



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

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.



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

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.



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

def options
  collect(&:options)
end

#saved?Boolean

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

Returns:

  • (Boolean)


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

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
# File 'app/sequencescape_excel/sequencescape_excel/conditional_formatting_list.rb', line 22

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

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

  self
end