Class: LabwareCreators::CustomPooledTubes::CsvFile::Row
- Inherits:
-
CommonFileHandling::CsvFile::RowBase
- Object
- CommonFileHandling::CsvFile::RowBase
- LabwareCreators::CustomPooledTubes::CsvFile::Row
- 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
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #expected_number_of_columns ⇒ Object
-
#initialize(header, index, row_data) ⇒ Row
constructor
A new instance of Row.
- #initialize_context_specific_fields ⇒ Object
- #to_s ⇒ Object
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
#destination ⇒ Object (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 |
#header ⇒ Object (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 |
#index ⇒ Object (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 |
#source ⇒ Object (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 |
#volume ⇒ Object (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
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_columns ⇒ Object
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_fields ⇒ Object
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_s ⇒ Object
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 |