Method: CsvConfig#parse
- Defined in:
- lib/resources/csv.rb
#parse(content) ⇒ Object
override file load and parse hash from csv
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/resources/csv.rb', line 18 def parse(content) require 'csv' # convert empty field to nil CSV::Converters[:blank_to_nil] = lambda do |field| field && field.empty? ? nil : field end # implicit conversion of values csv = CSV.new(content, headers: true, converters: [:all, :blank_to_nil]) # convert to hash csv.to_a.map(&:to_hash) end |