Class: Report::Csv::Table

Inherits:
Struct
  • Object
show all
Includes:
Utils
Defined in:
lib/report/csv/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#safe_delete, #tmp_path

Instance Attribute Details

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of parent



3
4
5
# File 'lib/report/csv/table.rb', line 3

def parent
  @parent
end

#tableObject

Returns the value of attribute table

Returns:

  • (Object)

    the current value of table



3
4
5
# File 'lib/report/csv/table.rb', line 3

def table
  @table
end

Instance Method Details

#cleanupObject



24
25
26
# File 'lib/report/csv/table.rb', line 24

def cleanup
  safe_delete @path if @path
end

#pathObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/report/csv/table.rb', line 5

def path
  return @path if defined?(@path)
  tmp_path = tmp_path(:hint => table.name, :extname => '.csv')
  File.open(tmp_path, 'wb') do |f|
    if table._head
      table._head.each(parent.report) do |row|
        f.write row.to_a.to_csv
      end
      f.write [].to_csv
    end
    if table._body
      f.write table._body.columns.map(&:name).to_csv
      table._body.each(parent.report) do |row|
        f.write row.to_a.to_csv
      end
    end
  end
  @path = tmp_path
end