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.



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

def initialize(attributes = {})
  super(default_attributes.merge(attributes))
  self.updates ||= name
end

Class Method Details

.build_arguments(args, key, conditional_formattings) ⇒ Object



142
143
144
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 142

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.



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

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

Instance Method Details

#attribute_value(detail) ⇒ Object



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

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



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

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



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

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

#metadata_field?Boolean

Returns:

  • (Boolean)


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

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

#range=(attributes) ⇒ Object

Creates a new Range object.



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

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

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

#specialised_fieldObject



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

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

#specialised_field?Boolean

Returns:

  • (Boolean)


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

def specialised_field?
  # We can't use const_defined? here as we want to make sure we trigger rails class loading
  specialised_field.present?
end

#styleObject



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

def style
  [unlocked? ? :unlocked : :locked, type]
end

#unlocked?Boolean

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

Returns:

  • (Boolean)


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

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.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 120

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



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

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

#updated?Boolean

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

Returns:

  • (Boolean)


111
112
113
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 111

def updated?
  @updated
end

#validation=(validation) ⇒ Object

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



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

def validation=(validation)
  return if validation.nil?
  @validation = validation.is_a?(Hash) ? Validation.new(validation) : validation.dup
end