Module: DumbDelimited::InstanceMethods

Defined in:
lib/dumb_delimited.rb

Instance Method Summary collapse

Instance Method Details

#to_s(eol = false) ⇒ String

Serializes a model object to a delimited string, using the delimiter specified by ClassMethods#delimiter. By default, the string will not end with a line terminator. To end the string with a line terminator designated by :row_sep in ClassMethods#options, set eol to true.

Parameters:

  • eol (Boolean) (defaults to: false)

Returns:

  • (String)


321
322
323
324
325
326
327
# File 'lib/dumb_delimited.rb', line 321

def to_s(eol = false)
  row_sep = eol ? self.class.options[:row_sep] : -""

  CSV.generate(**self.class.options, row_sep: row_sep, write_headers: false) do |csv|
    csv << self
  end
end