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.
: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
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
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
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
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
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
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
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
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
Generated with the Darkfish Rdoc Generator 2.