-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Munger | ||
module Render | ||
class CSV | ||
|
||
attr_reader :report | ||
|
||
def initialize(report) | ||
@report = report | ||
end | ||
|
||
def render | ||
output = [] | ||
|
||
# header | ||
output << @report.columns.collect { |col| @report.column_title(col).to_s }.join(',') | ||
|
||
# body | ||
@report.process_data.each do |row| | ||
output << @report.columns.collect { |col| row[:data][col].to_s }.join(',') | ||
end | ||
|
||
output.join("\n") | ||
end | ||
|
||
def valid? | ||
@report.is_a? Munger::Report | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require File.dirname(__FILE__) + "/spec_helper" | ||
|
||
describe Munger::Render::CSV do | ||
include MungerSpecHelper | ||
|
||
before(:each) do | ||
@data = Munger::Data.new(:data => test_data) | ||
@report = Munger::Report.new(:data => @data) | ||
end | ||
|
||
it "should accept a Munger::Report object" do | ||
Munger::Render::Text.new(@report.process).should be_valid | ||
end | ||
|
||
it "should render a basic text table" do | ||
@render = Munger::Render::CSV.new(@report.process) | ||
count = @report.rows | ||
text = @render.render | ||
text.split("\n").should have_at_least(count).items | ||
end | ||
end |