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 22 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| # ensure column name escapes invisible characters column_name = column_name.gsub(/[^[:print:]]/, '') 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 38 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 48 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 43 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 33 def required_columns column_definitions.select(&:required?).map(&:name) end
valid?()
click to toggle source
# File lib/csv_importer/header.rb, line 28 def valid? missing_required_columns.empty? end
Private Instance Methods
column_definition_names()
click to toggle source
# File lib/csv_importer/header.rb, line 60 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 54 def find_column_definition(name) column_definitions.find do |column_definition| column_definition.match?(name) end end