Ruport::Formatter::CSV

This formatter implements the CSV format for Ruport's Row, Table, Group and Grouping renderers. It is a light wrapper around James Edward Gray II's FasterCSV.

Rendering Options

:style Used for grouping (:inline,:justified,:raw)

:format_options A hash of FasterCSV options

:show_table_headers True by default

:show_group_headers True by default

Public Instance Methods

apply_template() click to toggle source

Hook for setting available options using a template. See the template documentation for the available options and their format.

# File lib/ruport/formatter/csv.rb, line 42
def apply_template
  apply_table_format_template(template.table_format)
  apply_grouping_format_template(template.grouping_format)

  options.format_options ||= template.format_options
end
build_group_body() click to toggle source

Renders the group body - uses the table renderer to generate the output.

# File lib/ruport/formatter/csv.rb, line 81
def build_group_body
  render_table data, options.to_hash
end
build_group_header() click to toggle source

Renders the header for a group using the group name.

# File lib/ruport/formatter/csv.rb, line 75
def build_group_header
  output << data.name.to_s << "\n\n"
end
build_grouping_body() click to toggle source

Determines the proper style to use and renders the Grouping.

# File lib/ruport/formatter/csv.rb, line 95
def build_grouping_body
  case style
  when :inline
    render_inline_grouping(options)
  when :justified, :raw
    render_justified_or_raw_grouping
  else
    raise NotImplementedError, "Unknown style"
  end
end
build_grouping_header() click to toggle source

Generates a header for the grouping using the grouped_by column and the column names.

# File lib/ruport/formatter/csv.rb, line 88
def build_grouping_header
  unless style == :inline
    output << "#{data.grouped_by}," << grouping_columns
  end
end
build_row() click to toggle source

Produces CSV output for a data row.

# File lib/ruport/formatter/csv.rb, line 68
def build_row
  require "fastercsv"
  output << FCSV.generate_line(data,format_options || {})
end
build_table_body() click to toggle source

Calls the row renderer for each row in the Data::Table

# File lib/ruport/formatter/csv.rb, line 61
def build_table_body
  render_data_by_row { |r| 
    r.options.format_options = format_options
  }
end
build_table_header() click to toggle source

Generates table header by turning column_names into a CSV row. Uses the row renderer to generate the actual formatted output

This method does not do anything if options.show_table_headers is false or the Data::Table has no column names.

# File lib/ruport/formatter/csv.rb, line 54
def build_table_header
  unless data.column_names.empty? || !show_table_headers
    render_row data.column_names, :format_options => format_options 
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.