Class: OutputMode::Outputs::Delimited

Inherits:
OutputMode::Output show all
Defined in:
lib/output_mode/outputs/delimited.rb

Instance Attribute Summary

Attributes inherited from OutputMode::Output

#context, #default, #no, #procs, #yes

Instance Method Summary collapse

Methods inherited from OutputMode::Output

#callables, #generate, #initialize

Constructor Details

This class inherits a constructor from OutputMode::Output

Instance Method Details

#configHash

Returns additional options to CSV.new.

Returns:

  • (Hash)

    additional options to CSV.new

See Also:



34
# File 'lib/output_mode/outputs/delimited.rb', line 34

def config; super; end

#render(*data) ⇒ Object

Implements the render method using CSV



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/output_mode/outputs/delimited.rb', line 40

def render(*data)
  io = StringIO.new
  csv = CSV.new(io, **config)
  data.each do |datum|
    csv << generate(datum).map do |value|
      next nil if value.nil?
      value.to_s.dump[1...-1]
    end
  end
  io.tap(&:rewind).read
end