Class: Formatter::Png
- Inherits:
-
Formatter
- Object
- Formatter
- Formatter::Png
- Defined in:
- app/formatters/png_formatter.rb
Constant Summary collapse
- CHART_TYPES =
%w{line line_xy scatter bar venn pie pie_3d sparkline meter}
Instance Method Summary collapse
- #finalize_table ⇒ Object
- #google_hash ⇒ Object
- #google_type ⇒ Object
- #google_url ⇒ Object
- #skip_legend? ⇒ Boolean
Instance Method Details
#finalize_table ⇒ Object
50 51 52 53 |
# File 'app/formatters/png_formatter.rb', line 50 def finalize_table require 'open-uri' output << open(google_url).read end |
#google_hash ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/formatters/png_formatter.rb', line 9 def google_hash out = .to_hash.symbolize_keys columns = out.delete(:columns) || data.column_names if out[:legend] == false or skip_legend? out.delete(:legend) else out[:legend] ||= columns end unless out[:data] out[:data] = [] columns.each_with_index do |col, i| out[:data][i] ||= [] end data.each_with_index do |row, i| columns.each_with_index do |col, i| out[:data][i] << row[col] end end end out end |
#google_type ⇒ Object
38 39 40 |
# File 'app/formatters/png_formatter.rb', line 38 def google_type .chart_type.try(:to_s).try(:downcase) || CHART_TYPES.first end |
#google_url ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/formatters/png_formatter.rb', line 42 def google_url url = Gchart.send(google_type, google_hash) unwise = %w({ } | \ ^ [ ] `) unwise.each { |c| url.gsub!(c, "%#{c[0].to_s(16).upcase}") } url.gsub!(/\s/, "%20") url end |
#skip_legend? ⇒ Boolean
34 35 36 |
# File 'app/formatters/png_formatter.rb', line 34 def skip_legend? google_type == "sparkline" end |