Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 4 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
1  lib/munger.rb
@@ -10,6 +10,7 @@
require 'munger/render/html'
require 'munger/render/sortable_html'
require 'munger/render/text'
+require 'munger/render/json'
module Munger
VERSION = '0.1.3'
View
12 lib/munger/render.rb
@@ -1,8 +1,8 @@
# Munger::Render.to_html(report)
-
+
module Munger #:nodoc:
module Render
-
+
def self.to_html(report, options = {})
Html::new(report, options).render
end
@@ -10,13 +10,17 @@ def self.to_html(report, options = {})
def self.to_sortable_html(report, options ={})
SortableHtml::new(report, options).render
end
-
+
def self.to_text(report)
Text::new(report).render
end
-
+
def self.to_csv(report)
CSV::new(report).render
end
+
+ def self.to_jason(report)
+ JSON::new(report).render
+ end
end
end
View
31 lib/munger/render/json.rb
@@ -0,0 +1,31 @@
+module Munger #:nodoc:
+ module Render #:nodoc:
+ class JSON #:nodoc:
+
+ attr_reader :report
+
+ def initialize(report)
+ @report = report
+ end
+
+ def render
+ output = []
+
+ # header
+ output << @report.columns.collect { |col| @report.column_title(col).to_s }
+
+ # body
+ @report.process_data.each do |row|
+ output << @report.columns.collect { |col| row[:data][col].to_s }
+ end
+
+ output
+ end
+
+ def valid?
+ @report.is_a? Munger::Report
+ end
+
+ end
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.