module Sequel::Plugins::CsvSerializer::InstanceMethods
Public Instance Methods
from_csv(csv, opts = OPTS)
click to toggle source
Update the object using the data provided in the first line in CSV. Options:
- :headers
-
The headers to use for the CSV line. Use nil for a header to specify the column should be ignored.
# File lib/sequel/plugins/csv_serializer.rb 147 def from_csv(csv, opts = OPTS) 148 row = CsvSerializer.csv_call(:parse_line, csv, model.process_csv_serializer_opts(opts)).to_hash 149 row.delete(nil) 150 set(row) 151 end
to_csv(opts = OPTS)
click to toggle source
Return a string in CSV format. Accepts the same options as CSV.new, as well as the following options:
- :except
-
Symbol
orArray
of Symbols of columns not to include in the CSV output. - :only
-
Symbol
orArray
of Symbols of columns to include in the CSV output, ignoring all other columns - :include
-
Symbol
orArray
of Symbols specifying non-column attributes to include in the CSV output.
# File lib/sequel/plugins/csv_serializer.rb 162 def to_csv(opts = OPTS) 163 opts = model.process_csv_serializer_opts(opts) 164 headers = opts[:headers] 165 166 CsvSerializer.csv_call(:generate, model.process_csv_serializer_opts(opts)) do |csv| 167 csv << headers.map{|k| public_send(k)} 168 end 169 end