class CSVImporter::Header
The CSV Header
Public Instance Methods
column_name_for_model_attribute(attribute)
click to toggle source
# File lib/csv_importer/header.rb, line 19 def column_name_for_model_attribute(attribute) if column = columns.find { |column| column.definition.attribute == attribute if column.definition } column.name end end
columns()
click to toggle source
# File lib/csv_importer/header.rb, line 10 def columns column_names.map do |column_name| Column.new( name: column_name, definition: find_column_definition(column_name) ) end end
extra_columns()
click to toggle source
Returns Array
# File lib/csv_importer/header.rb, line 35 def extra_columns columns.reject(&:definition).map(&:name).map(&:to_s) end
missing_columns()
click to toggle source
Returns Array
# File lib/csv_importer/header.rb, line 45 def missing_columns (column_definitions - columns.map(&:definition)).map(&:name).map(&:to_s) end
missing_required_columns()
click to toggle source
Returns Array
# File lib/csv_importer/header.rb, line 40 def missing_required_columns (column_definitions.select(&:required?) - columns.map(&:definition)).map(&:name).map(&:to_s) end
required_columns()
click to toggle source
Returns Array
# File lib/csv_importer/header.rb, line 30 def required_columns column_definitions.select(&:required?).map(&:name) end
valid?()
click to toggle source
# File lib/csv_importer/header.rb, line 25 def valid? missing_required_columns.empty? end
Private Instance Methods
column_definition_names()
click to toggle source
# File lib/csv_importer/header.rb, line 57 def column_definition_names column_definitions.map(&:name).map(&:to_s) end
find_column_definition(name)
click to toggle source
# File lib/csv_importer/header.rb, line 51 def find_column_definition(name) column_definitions.find do |column_definition| column_definition.match?(name) end end