Class: Chartio::CSVFormatter

Inherits:
Formatter show all
Defined in:
lib/chartio/csv_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Formatter

#<<

Constructor Details

#initializeCSVFormatter

Returns a new instance of CSVFormatter.



8
9
10
11
12
# File 'lib/chartio/csv_formatter.rb', line 8

def initialize
  @foreign_keys = []
  @stringio = StringIO.open
  @csv = CSV.new(@stringio)
end

Instance Attribute Details

#foreign_keysObject

Returns the value of attribute foreign_keys.



6
7
8
# File 'lib/chartio/csv_formatter.rb', line 6

def foreign_keys
  @foreign_keys
end

Instance Method Details

#foreign_key(incoming_foreign_key) ⇒ Object



14
15
16
# File 'lib/chartio/csv_formatter.rb', line 14

def foreign_key(incoming_foreign_key)
  @foreign_keys << incoming_foreign_key
end

#output_reportObject



18
19
20
21
22
23
24
25
26
# File 'lib/chartio/csv_formatter.rb', line 18

def output_report
  @csv << Chartio::ForeignKeyRelationship::FIELDS.map(&:to_s)

  @foreign_keys.each do |key|
    @csv << key.to_a
  end

  @csv.string
end