Class: Renogen::Formatters::Csv
- Defined in:
- lib/renogen/formatters/csv.rb
Overview
For formatting a change into CSV output
Instance Attribute Summary collapse
-
#headings ⇒ Object
readonly
Returns the value of attribute headings.
Attributes inherited from Base
Instance Method Summary collapse
- #header(changelog) ⇒ Object
- #table_formatter? ⇒ Boolean
- #write_change(ticket) ⇒ Object
- #write_header(header) ⇒ Object
Methods inherited from Base
#initialize, register, #write_footer, #write_group, #write_group_end
Constructor Details
This class inherits a constructor from Renogen::Formatters::Base
Instance Attribute Details
#headings ⇒ Object (readonly)
Returns the value of attribute headings.
9 10 11 |
# File 'lib/renogen/formatters/csv.rb', line 9 def headings @headings end |
Instance Method Details
#header(changelog) ⇒ Object
36 37 38 39 |
# File 'lib/renogen/formatters/csv.rb', line 36 def header(changelog) @headings = changelog.groups.keys @headings.join(',') end |
#table_formatter? ⇒ Boolean
11 12 13 |
# File 'lib/renogen/formatters/csv.rb', line 11 def table_formatter? true end |
#write_change(ticket) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/renogen/formatters/csv.rb', line 19 def write_change(ticket) headings.map do |header| raw_line = ticket[header] next if raw_line.nil? parsed_line = raw_line.is_a?(Array) ? raw_line.join(',') : raw_line parsed_line = parsed_line.chomp parsed_line.gsub!("\n", '\n') if parsed_line.include?("\n") if parsed_line.include?(',') "\"#{parsed_line}\"" else parsed_line end end.join(',') end |
#write_header(header) ⇒ Object
15 16 17 |
# File 'lib/renogen/formatters/csv.rb', line 15 def write_header(header) "#{header}\n" end |