elskwid-munger 0.1.4.1 → 0.1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ # Gem::manage_gems
2
3
  require 'rake/gempackagetask'
3
4
  require 'rake/rdoctask'
4
5
  require 'spec/rake/spectask'
data/lib/munger/data.rb CHANGED
@@ -63,7 +63,7 @@ module Munger #:nodoc:
63
63
  else
64
64
  row[names] = col_data
65
65
  end
66
- @data[index] = Item.ensure(row)
66
+ @data[index] = clean_data(row)
67
67
  end
68
68
  end
69
69
  alias :add_columns :add_column
@@ -169,16 +169,16 @@ module Munger #:nodoc:
169
169
 
170
170
  data_hash.each do |row_key, row_hash|
171
171
  new_row = {}
172
- row_hash.each do |column_key, data|
172
+ row_hash.each do |column_key, row_data|
173
173
  column_key.each do |ckey|
174
- new_row.merge!(clean_data(data[:data].data))
174
+ new_row.merge!(row_data[:data])
175
175
  case aggregation
176
176
  when :average
177
- new_row[ckey] = (data[:sum] / data[:count])
177
+ new_row[ckey] = (row_data[:sum] / row_data[:count])
178
178
  when :count
179
- new_row[ckey] = data[:count]
179
+ new_row[ckey] = row_data[:count]
180
180
  else
181
- new_row[ckey] = data[:sum]
181
+ new_row[ckey] = row_data[:sum]
182
182
  end
183
183
  new_keys[ckey] = true
184
184
  end
@@ -12,11 +12,11 @@ module Munger #:nodoc:
12
12
  output = []
13
13
 
14
14
  # header
15
- output << @report.columns.collect { |col| @report.column_title(col).to_s }.join(',')
15
+ output << @report.columns.collect { |col| quote(@report.column_title(col)) }.join(',')
16
16
 
17
17
  # body
18
18
  @report.process_data.each do |row|
19
- output << @report.columns.collect { |col| row[:data][col].to_s }.join(',')
19
+ output << @report.columns.collect { |col| quote(row[:data][col]) }.join(',')
20
20
  end
21
21
 
22
22
  output.join("\n")
@@ -25,7 +25,13 @@ module Munger #:nodoc:
25
25
  def valid?
26
26
  @report.is_a? Munger::Report
27
27
  end
28
-
28
+
29
+ private
30
+
31
+ # quote data if it contains a comma
32
+ def quote(data)
33
+ data.to_s.include?(',') ? "\"#{data}\"" : "#{data}"
34
+ end
29
35
  end
30
36
  end
31
37
  end
data/munger.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = "elskwid-munger"
4
- s.version = "0.1.4.1"
4
+ s.version = "0.1.4.2"
5
5
  s.authors = ['Scott Chacon', 'Brandon Mitchell', 'Don Morrison', 'Eric Lindvall']
6
6
  s.email = "elskwid@gmail.com"
7
7
  s.summary = "A reporting engine in Ruby - the elskwid fork!"
@@ -34,4 +34,10 @@ describe Munger::Item do
34
34
  item['key1'].should eql('value1')
35
35
  item[:key2].should eql('value2')
36
36
  end
37
+
38
+ it "should return a hash after being initialized with a hash" do
39
+ hash = {:key1 => "value1", :key2 => "value2"}
40
+ Munger::Item.ensure(hash).to_hash.should be_kind_of(Hash)
41
+ end
42
+
37
43
  end
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + "/../../spec_helper"
3
3
  describe Munger::Render::CSV do
4
4
  include MungerSpecHelper
5
5
 
6
- before(:each) do
7
- @data = Munger::Data.new(:data => test_data)
6
+ before(:each) do
7
+ @data = Munger::Data.new(:data => test_data + [{:name => 'Comma, Guy', :age => 100, :day => 0, :score => 0}])
8
8
  @report = Munger::Report.new(:data => @data)
9
9
  end
10
10
 
@@ -18,4 +18,10 @@ describe Munger::Render::CSV do
18
18
  text = @render.render
19
19
  text.split("\n").should have_at_least(count).items
20
20
  end
21
+
22
+ it "should quote data with commas" do
23
+ @render = Munger::Render::CSV.new(@report.process)
24
+ text = @render.render
25
+ text.should match /"Comma, Guy"/
26
+ end
21
27
  end
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@ require 'spec'
5
5
  require 'fileutils'
6
6
  require 'logger'
7
7
  require 'pp'
8
+ require 'date'
8
9
 
9
10
  require 'rspec_hpricot_matchers'
10
11
  Spec::Runner.configure do |config|
@@ -22,7 +23,7 @@ module MungerSpecHelper
22
23
  {:name => 'Scott', :age => 23, :day => 1, :score => 31},
23
24
  {:name => 'Alice', :age => 33, :day => 1, :score => 12},
24
25
  {:name => 'Alice', :age => 34, :day => 2, :score => 12},
25
- {:name => 'Alice', :age => 33, :day => 2, :score => 12},
26
+ {:name => 'Alice', :age => 33, :day => 2, :score => 12}
26
27
  ]
27
28
  end
28
29
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 4
9
- - 1
10
- version: 0.1.4.1
9
+ - 2
10
+ version: 0.1.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Chacon
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-04-02 00:00:00 -07:00
21
+ date: 2010-04-06 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies: []
24
24