Class: SequencescapeExcel::RangeList

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
app/sequencescape_excel/sequencescape_excel/range_list.rb

Overview

A list of ranges which can be added to a Worksheet and used by the validations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ranges_data = {}) ⇒ RangeList

Creates a hash of ranges. Each key is the range name and each value is a has of range options. The row that the range appears on is defined by the index of the range.



18
19
20
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 18

def initialize(ranges_data = {})
  @ranges = create(ranges_data)
end

Instance Attribute Details

#rangesObject (readonly)

Returns the value of attribute ranges.



11
12
13
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 11

def ranges
  @ranges
end

Instance Method Details

#<=>(other) ⇒ Object



46
47
48
49
50
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 46

def <=>(other)
  return unless other.is_a?(self.class)

  ranges <=> other.ranges
end

#eachObject



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

def each(&)
  ranges.each(&)
end

#find_by(key) ⇒ Object

Find a range by it’s key.



28
29
30
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 28

def find_by(key)
  ranges[key] || ranges[key.to_s]
end

#set_worksheet_names(worksheet_name) ⇒ Object

Each range needs a worksheet name to be used as an absolute reference. for when it is added to a validation on another worksheet.



35
36
37
38
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 35

def set_worksheet_names(worksheet_name) # rubocop:disable Naming/AccessorMethodName
  each { |_k, range| range.set_worksheet_name(worksheet_name) }
  self
end

#valid?Boolean

A RangeList is only valid if it contains at least one range object.

Returns:

  • (Boolean)


42
43
44
# File 'app/sequencescape_excel/sequencescape_excel/range_list.rb', line 42

def valid?
  ranges.any?
end