Method: FieldMapper::Custom::Field#load_values

Defined in:
lib/field_mapper/custom/field.rb

#load_values(path_to_csv) ⇒ Object

Adds values to a Field instance that are defined in a CSV file.

Intended use is from within a Plat class declaration. The format of the CSV file should contain a two columns with a header row. NOTE: An optional priority column can also be included.

Examples:

class ExamplePlat < FieldMapper::Standard::Plat
  field :example do
    load_values "/path/to/file.csv"
  end
end
custom_value,standard_value,priority
"A",1,
"B",2,true
"C",2,


74
75
76
77
78
79
80
81
82
# File 'lib/field_mapper/custom/field.rb', line 74

def load_values(path_to_csv)
  CSV.foreach(path_to_csv, :headers => true) do |row|
    value(
      row["custom_value"],
      standard: row["standard_value"],
      priority: FieldMapper::Types::Boolean.parse(row["priority"])
    )
  end
end