Class: LabwareCreators::CustomPooledTubes::CsvFile::Row

Inherits:
CommonFileHandling::CsvFile::RowBase
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb

Overview

Class CsvRow provides a simple wrapper for handling and validating individual CSV rows

Constant Summary collapse

MISSING_SOURCE =
'is blank in %s but a destination has been specified. ' \
'Either supply a source, or remove the destination.'
MISSING_VOLUME =
'is blank in %s but a destination has been specified. ' \
'Either supply a positive volume, or remove the destination.'
NEGATIVE_VOLUME =
'is %%{value} in %s but a destination has been specified. ' \
'Either supply a positive volume, or remove the destination.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, index, row_data) ⇒ Row

Returns a new instance of Row.



48
49
50
51
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 48

def initialize(header, index, row_data)
  @header = header
  super(index, row_data)
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



23
24
25
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 23

def destination
  @destination
end

#headerObject (readonly)

Returns the value of attribute header.



23
24
25
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 23

def header
  @header
end

#indexObject (readonly)

Returns the value of attribute index.



23
24
25
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 23

def index
  @index
end

#sourceObject (readonly)

Returns the value of attribute source.



23
24
25
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 23

def source
  @source
end

#volumeObject (readonly)

Returns the value of attribute volume.



23
24
25
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 23

def volume
  @volume
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 66

def empty?
  destination.blank?
end

#expected_number_of_columnsObject



70
71
72
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 70

def expected_number_of_columns
  3
end

#initialize_context_specific_fieldsObject



53
54
55
56
57
58
59
60
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 53

def initialize_context_specific_fields
  @source = (@row_data[source_column] || '').strip.upcase
  @destination = (@row_data[destination_column] || '').strip.upcase

  # We use %.to_i to avoid converting nil to 0. This allows us to write less
  # confusing validation error messages.
  @volume = @row_data[volume_column]&.to_i
end

#to_sObject



62
63
64
# File 'app/models/labware_creators/custom_pooled_tubes/csv_file/row.rb', line 62

def to_s
  source.present? ? "row #{index} [#{source}]" : "row #{index}"
end