Class: SequencescapeExcel::Validation

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

Overview

An Excel validation Holds the validation for each column which is added to each column when the spreadsheet is created. Consists of:

  • A list of options which relate to options recognised by Excel e.g. errorMessage.

  • A range name (optional) which will be linked to a range when the spreadsheet is created.

Instance Method Summary collapse

Methods included from Helpers::Attributes

#<=>, #to_a

Constructor Details

#initialize(attributes = {}) ⇒ Validation

Returns a new instance of Validation


15
16
17
# File 'app/sequencescape_excel/sequencescape_excel/validation.rb', line 15

def initialize(attributes = {})
  super
end

Instance Method Details

#empty?Boolean

A validation object is never empty

Returns:

  • (Boolean)

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

def empty?
  false
end

#formula1Object

formula1 is defined within the options


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

def formula1
  options[:formula1]
end

#initialize_dup(source) ⇒ Object


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

def initialize_dup(source)
  self.options = source.options.dup
  super
end

#inspectObject


68
69
70
# File 'app/sequencescape_excel/sequencescape_excel/validation.rb', line 68

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

#range_required?Boolean

If the range name is present then a range is required for the validation

Returns:

  • (Boolean)

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

def range_required?
  range_name.present?
end

#saved?Boolean

If the worksheet has been updated then we can assume that the validation has been saved to a worksheet.

Returns:

  • (Boolean)

59
60
61
# File 'app/sequencescape_excel/sequencescape_excel/validation.rb', line 59

def saved?
  @worksheet_validation.present?
end

#update(attributes = {}) ⇒ Object

The range is updated when the measurements of a worksheet is defined. If a range is required the the formula1 is set to the absolute raference of the range. If a worksheet is passed then the data validation is added using the reference is passed and the options for the validation.


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

def update(attributes = {})
  options[:formula1] = attributes[:range].absolute_reference if range_required?
  return if attributes[:worksheet].blank?

  @worksheet_validation = attributes[:worksheet].add_data_validation(attributes[:reference], options)
end

#valid?Boolean

Validation is only valid if there are some options

Returns:

  • (Boolean)

46
47
48
# File 'app/sequencescape_excel/sequencescape_excel/validation.rb', line 46

def valid?
  options.present?
end