Class: SequencescapeExcel::Column

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

Overview

Column creates a particular column with all the information about this column (name, heading, value, type, attribute, should it be locked or unlocked, position of the column, validation, conditional formatting rules) A column is only valid if it has a name and heading.

Defined Under Namespace

Classes: ArgumentBuilder

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Attributes

#<=>, #to_a

Constructor Details

#initialize(attributes = {}) ⇒ Column

Returns a new instance of Column.


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

def initialize(attributes = {})
  super(default_attributes.merge(attributes))
end

Class Method Details

.build_arguments(args, key, conditional_formattings) ⇒ Object


136
137
138
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 136

def self.build_arguments(args, key, conditional_formattings)
  ArgumentBuilder.new(args, key, conditional_formattings).to_h
end

.sample_metadata_modelObject

TODO: Because of the way Sample::Metadata is autoloaded we can't check instance_methods. creating a new instance of Sample::Metadata even at startup is incredibly slow. Can't do it as a constant due to Travis failure.


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

def self.
  @sample_metadata_model ||= Sample::Metadata.new
end

Instance Method Details

#attribute_value(detail) ⇒ Object


89
90
91
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 89

def attribute_value(detail)
  detail[attribute] || value
end

#conditional_formattings=(conditional_formattings) ⇒ Object

If argument is a conditional formatting list copy it otherwise create a new conditional formatting list


56
57
58
59
60
61
62
63
64
65
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 56

def conditional_formattings=(conditional_formattings)
  return if conditional_formattings.nil?

  @conditional_formattings =
    if conditional_formattings.is_a?(Hash)
      ConditionalFormattingList.new(conditional_formattings)
    else
      conditional_formattings.dup
    end
end

#initialize_dup(source) ⇒ Object


129
130
131
132
133
134
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 129

def initialize_dup(source)
  self.range = {}
  self.validation = source.validation
  self.conditional_formattings = source.conditional_formattings
  super
end

#metadata_field?Boolean

Returns:

  • (Boolean)

81
82
83
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 81

def 
  @metadata_field ||= Column..respond_to?(name) unless specialised_field?
end

#range=(attributes) ⇒ Object

Creates a new Range object.


69
70
71
72
73
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 69

def range=(attributes)
  return if attributes.nil?

  @range = attributes.empty? ? NullRange.new : Range.new(attributes)
end

#specialised_fieldObject


97
98
99
100
101
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 97

def specialised_field
  @specialised_field ||= SequencescapeExcel.const_get(classify_name, false)
rescue NameError
  nil
end

#specialised_field?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 93

def specialised_field?
  specialised_field.present?
end

#unlocked?Boolean

Some columns need to be unlocked so data can be entered.

Returns:

  • (Boolean)

77
78
79
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 77

def unlocked?
  unlocked
end

#update(first_row, last_row, ranges, worksheet) ⇒ Object

Create a column range based on the first column, first row and last low If the column has a validation range return it or return a NullRange. Update the column validation using the passed worksheet and found range. Update the conditional formatting based on a range and worksheet.


114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 114

def update(first_row, last_row, ranges, worksheet)
  self.range = { first_column: number, first_row: first_row, last_row: last_row }

  range = ranges.find_by(range_name) || NullRange.new
  validation.update(range: range, reference: self.range.reference, worksheet: worksheet)

  conditional_formattings.update(
    self.range.references.merge(absolute_reference: range.absolute_reference, worksheet: worksheet)
  )

  @updated = true

  self
end

#update_metadata(metadata, value) ⇒ Object


85
86
87
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 85

def (, value)
  .send("#{name}=", value) if 
end

#updated?Boolean

Check whether a column has been updated with all of the references, validations etc.

Returns:

  • (Boolean)

105
106
107
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 105

def updated?
  @updated
end

#validation=(validation) ⇒ Object

If argument is a validation object copy it otherwise create a new validation object


47
48
49
50
51
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 47

def validation=(validation)
  return if validation.nil?

  @validation = validation.is_a?(Hash) ? Validation.new(validation) : validation.dup
end