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


26
27
28
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 26

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

Class Method Details

.build_arguments(args, key, conditional_formattings) ⇒ Object


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

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.


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

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

Instance Method Details

#attribute_value(detail) ⇒ Object


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

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


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

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


122
123
124
125
126
127
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 122

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

#metadata_field?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 74

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

#range=(attributes) ⇒ Object

Creates a new Range object.


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

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

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

#specialised_fieldObject


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

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

#specialised_field?Boolean

Returns:

  • (Boolean)

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

def specialised_field?
  specialised_field.present?
end

#unlocked?Boolean

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

Returns:

  • (Boolean)

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

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.


107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 107

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


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

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)

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

def updated?
  @updated
end

#validation=(validation) ⇒ Object

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


33
34
35
36
37
38
39
40
41
# File 'app/sequencescape_excel/sequencescape_excel/column.rb', line 33

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

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