elskwid-munger 0.1.4.5 → 0.1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +7 -32
- data/munger.gemspec +44 -34
- data/{spec/munger/render/csv_spec.rb → test/munger/csv_test.rb} +9 -9
- data/test/munger/data_ar_test.rb +194 -0
- data/test/munger/data_test.rb +185 -0
- data/test/munger/html_test.rb +87 -0
- data/test/munger/item_test.rb +43 -0
- data/{spec/munger/data/new_spec.rb → test/munger/new_test.rb} +9 -9
- data/test/munger/render_test.rb +37 -0
- data/test/munger/report_test.rb +156 -0
- data/{spec/munger/render/text_spec.rb → test/munger/text_test.rb} +9 -9
- data/test/test_helper.rb +60 -0
- metadata +88 -50
- data/spec/munger/data_spec.rb +0 -183
- data/spec/munger/item_spec.rb +0 -43
- data/spec/munger/render/html_spec.rb +0 -87
- data/spec/munger/render_spec.rb +0 -38
- data/spec/munger/report_spec.rb +0 -155
- data/spec/spec_helper.rb +0 -107
metadata
CHANGED
@@ -1,16 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: elskwid-munger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4.6
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 4
|
10
|
-
- 5
|
11
|
-
version: 0.1.4.5
|
12
6
|
platform: ruby
|
13
|
-
authors:
|
7
|
+
authors:
|
14
8
|
- Scott Chacon
|
15
9
|
- Brandon Mitchell
|
16
10
|
- Don Morrison
|
@@ -18,19 +12,62 @@ authors:
|
|
18
12
|
autorequire:
|
19
13
|
bindir: bin
|
20
14
|
cert_chain: []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: builder
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: minitest
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 5.0.8
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 5.0.8
|
25
65
|
description:
|
26
66
|
email: elskwid@gmail.com
|
27
67
|
executables: []
|
28
|
-
|
29
68
|
extensions: []
|
30
|
-
|
31
69
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
files:
|
70
|
+
files:
|
34
71
|
- munger.gemspec
|
35
72
|
- Rakefile
|
36
73
|
- README
|
@@ -48,47 +85,48 @@ files:
|
|
48
85
|
- lib/munger/render/html.rb
|
49
86
|
- lib/munger/render/sortable_html.rb
|
50
87
|
- lib/munger/render/text.rb
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
88
|
+
- test/test_helper.rb
|
89
|
+
- test/munger/csv_test.rb
|
90
|
+
- test/munger/data_ar_test.rb
|
91
|
+
- test/munger/data_test.rb
|
92
|
+
- test/munger/html_test.rb
|
93
|
+
- test/munger/item_test.rb
|
94
|
+
- test/munger/new_test.rb
|
95
|
+
- test/munger/render_test.rb
|
96
|
+
- test/munger/report_test.rb
|
97
|
+
- test/munger/text_test.rb
|
60
98
|
homepage: http://github.com/elskwid/munger
|
61
99
|
licenses: []
|
62
|
-
|
63
100
|
post_install_message:
|
64
101
|
rdoc_options: []
|
65
|
-
|
66
|
-
require_paths:
|
102
|
+
require_paths:
|
67
103
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
105
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
- 0
|
76
|
-
version: "0"
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
111
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
version: "0"
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
86
116
|
requirements: []
|
87
|
-
|
88
117
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
118
|
+
rubygems_version: 1.8.23
|
90
119
|
signing_key:
|
91
120
|
specification_version: 3
|
92
121
|
summary: A reporting engine in Ruby - the elskwid fork!
|
93
|
-
test_files:
|
94
|
-
|
122
|
+
test_files:
|
123
|
+
- test/test_helper.rb
|
124
|
+
- test/munger/csv_test.rb
|
125
|
+
- test/munger/data_ar_test.rb
|
126
|
+
- test/munger/data_test.rb
|
127
|
+
- test/munger/html_test.rb
|
128
|
+
- test/munger/item_test.rb
|
129
|
+
- test/munger/new_test.rb
|
130
|
+
- test/munger/render_test.rb
|
131
|
+
- test/munger/report_test.rb
|
132
|
+
- test/munger/text_test.rb
|
data/spec/munger/data_spec.rb
DELETED
@@ -1,183 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe Munger::Data do
|
4
|
-
include MungerSpecHelper
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@data = Munger::Data.new(:data => test_data)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should accept an array of hashes" do
|
11
|
-
Munger::Data.new(:data => test_data).should be_valid
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be able to set data after init" do
|
15
|
-
m = Munger::Data.new
|
16
|
-
m.data = test_data
|
17
|
-
m.should be_valid
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should be able to set data in init block" do
|
21
|
-
m = Munger::Data.new do |d|
|
22
|
-
d.data = test_data
|
23
|
-
end
|
24
|
-
m.should be_valid
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should be able to add more data after init" do
|
28
|
-
m = Munger::Data.new
|
29
|
-
m.data = test_data
|
30
|
-
m.add_data more_test_data
|
31
|
-
m.should be_valid
|
32
|
-
additional_names = m.data.select { |r| r[:name] == 'David' || r[:name] == 'Michael' }
|
33
|
-
additional_names.should have(4).items
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should be able to add data without initial data" do
|
37
|
-
m = Munger::Data.new
|
38
|
-
m.add_data more_test_data
|
39
|
-
m.should be_valid
|
40
|
-
m.should have(4).items
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be able to extract columns from data" do
|
44
|
-
@titles = @data.columns
|
45
|
-
@titles.should have(4).items
|
46
|
-
@titles.should include(:name, :score, :age)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should be able to add a new column with a default value" do
|
50
|
-
@data.add_column('new_column', :default => 1)
|
51
|
-
@data.data.first['new_column'].should eql(1)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should be able to add a new column with a block" do
|
55
|
-
@data.add_column('new_column') { |c| c.age + 1 }
|
56
|
-
@data.data.first['new_column'].should eql(24)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should be able to add multiple new columns with defaults" do
|
60
|
-
@data.add_column(['col1', 'col2'], :default => [1, 2])
|
61
|
-
@data.data.first['col1'].should eql(1)
|
62
|
-
@data.data.first['col2'].should eql(2)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should be able to add multiple new columns with a block" do
|
66
|
-
@data.add_column(['col1', 'col2']) { |c| [c.age * 2, c.score * 3]}
|
67
|
-
@data.data.first['col1'].should eql(46)
|
68
|
-
@data.data.first['col2'].should eql(36)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should work with add_columns, too" do
|
72
|
-
@data.add_columns(['col1', 'col2'], :default => [1, 2])
|
73
|
-
@data.data.first['col1'].should eql(1)
|
74
|
-
@data.data.first['col2'].should eql(2)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should be able to transform a column" do
|
78
|
-
@data.data.first[:age].should eql(23)
|
79
|
-
@data.transform_column(:age) { |c| c.age * 2 }
|
80
|
-
@data.data.first[:age].should eql(46)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should be able to transform multiple rows" do
|
84
|
-
@data.data.first[:age].should eql(23)
|
85
|
-
@data.data.first[:score].should eql(12)
|
86
|
-
@data.transform_columns([:age, :score]) { |c| [c.age * 2, c.score * 3] }
|
87
|
-
@data.data.first[:age].should eql(46)
|
88
|
-
@data.data.first[:score].should eql(36)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should be able to filter the data down" do
|
92
|
-
orig_size = @data.size
|
93
|
-
@data.filter_rows { |r| r.age < 30 }
|
94
|
-
@data.size.should < orig_size
|
95
|
-
@data.size.should eql(4)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "should be able to pivot the data (1 column)" do
|
99
|
-
orig_size = @data.size
|
100
|
-
new_keys = @data.pivot(:day, :name, :score)
|
101
|
-
@data.size.should < orig_size
|
102
|
-
new_keys.should include(1, 2)
|
103
|
-
scott = @data.data.select { |r| r.name == 'Scott' }.first
|
104
|
-
scott[1].should eql(43)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should be able to pivot the data with average aggregation" do
|
108
|
-
new_keys = @data.pivot(:day, :name, :score, :average)
|
109
|
-
new_keys.should include(1, 2)
|
110
|
-
scott = @data.data.select { |r| r.name == 'Scott' }.first
|
111
|
-
scott[1].should eql(21)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should be able to pivot the data with count aggregation" do
|
115
|
-
new_keys = @data.pivot(:day, :name, :score, :count)
|
116
|
-
scott = @data.data.select { |r| r.name == 'Scott' }.first
|
117
|
-
scott[1].should eql(2)
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should be able to pivot the data in three dimensions (1 col, 2 row)" do
|
121
|
-
new_keys = @data.pivot(:name, [:score, :age], :score, :count)
|
122
|
-
alice = @data.data.select { |r| r.name == 'Alice' }.first
|
123
|
-
alice.Alice.should eql(2)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should be able to add a column then pivot the data (1 column)" do
|
127
|
-
@data.add_column(:day_of_week) { |c| Date::DAYNAMES[c.day] }
|
128
|
-
orig_size = @data.size
|
129
|
-
new_keys = @data.pivot(:day_of_week, :name, :score)
|
130
|
-
@data.size.should < orig_size
|
131
|
-
new_keys.should include("Monday", "Tuesday")
|
132
|
-
alice = @data.data.select { |r| r.name == 'Alice' }.first
|
133
|
-
alice["Monday"].should eql(12)
|
134
|
-
alice["Tuesday"].should eql(24)
|
135
|
-
end
|
136
|
-
|
137
|
-
# like sql group command, give aggregation block
|
138
|
-
it "should be able to group the data like sql" do
|
139
|
-
@data.group(:name)
|
140
|
-
@data.size.should eql(6)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should be able to group on multiple columns" do
|
144
|
-
@data.group([:age, :score], :count => :day, :sum => :day, :average => :score)
|
145
|
-
alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
|
146
|
-
alice.count_day.should eql(2)
|
147
|
-
alice.sum_day.should eql(3)
|
148
|
-
alice.average_day.should eql(nil)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should be able to group with a proc aggregation" do
|
152
|
-
pr = Proc.new {|arr| arr.inject(0) { |a,b| a + (b*2) }}
|
153
|
-
@data.group([:age, :score], :sum => :day, ['test', pr] => :age)
|
154
|
-
alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
|
155
|
-
alice.test_age.should eql(132)
|
156
|
-
alice.sum_day.should eql(3)
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should be able to output an array" do
|
160
|
-
array = @data.to_a
|
161
|
-
array.should be_a_kind_of(Array)
|
162
|
-
array.first.size.should eql(@data.columns.size)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should be able to output a filtered array" do
|
166
|
-
array = @data.to_a([:name, :age])
|
167
|
-
array.should be_a_kind_of(Array)
|
168
|
-
array.first.size.should eql(2)
|
169
|
-
scotts = array.select { |a| a.include?('Scott') }
|
170
|
-
scotts.first.should include('Scott', 23)
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should be able to pivot the data in three dimensions (2 col, 1 row)"
|
174
|
-
|
175
|
-
it "should be able to pivot the data in four dimensions (2 col, 2 row)"
|
176
|
-
|
177
|
-
it "should be able to add two Munger::Datas together if they have the same columns"
|
178
|
-
|
179
|
-
it "should be able to add data and check if it is Munger::Data"
|
180
|
-
|
181
|
-
it "(maybe) should be able to zip two Munger::Datas together given a unique key column in each"
|
182
|
-
|
183
|
-
end
|
data/spec/munger/item_spec.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe Munger::Item do
|
4
|
-
include MungerSpecHelper
|
5
|
-
|
6
|
-
before(:all) do
|
7
|
-
@data = Munger::Data.new(:data => test_data)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should accept a hash with symbols" do
|
11
|
-
hash = {'key1' => 'value1', 'key2' => 'value2'}
|
12
|
-
item = Munger::Item.ensure(hash)
|
13
|
-
item.key1.should eql('value1')
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should accept a hash with strings" do
|
17
|
-
hash = {:key1 => 'value1', :key2 => 'value2'}
|
18
|
-
item = Munger::Item.ensure(hash)
|
19
|
-
item.key1.should eql('value1')
|
20
|
-
item.key2.should_not eql('value1')
|
21
|
-
item.key3.should be(nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should accept mixed types" do
|
25
|
-
hash = {:key1 => 'value1', 'key2' => 'value2'}
|
26
|
-
item = Munger::Item.ensure(hash)
|
27
|
-
item.key1.should eql('value1')
|
28
|
-
item.key2.should eql('value2')
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should be able to access hash values indifferently" do
|
32
|
-
hash = {:key1 => 'value1', 'key2' => 'value2'}
|
33
|
-
item = Munger::Item.ensure(hash)
|
34
|
-
item['key1'].should eql('value1')
|
35
|
-
item[:key2].should eql('value2')
|
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
|
-
|
43
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../../spec_helper"
|
2
|
-
|
3
|
-
describe Munger::Render::Html do
|
4
|
-
include MungerSpecHelper
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@data = Munger::Data.new(:data => test_data)
|
8
|
-
@report = Munger::Report.new(:data => @data)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should accept a Munger::Report object" do
|
12
|
-
Munger::Render::Html.new(@report.process).should be_valid
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should render a basic html table" do
|
16
|
-
@render = Munger::Render::Html.new(@report.process)
|
17
|
-
count = @report.rows
|
18
|
-
|
19
|
-
html = @render.render
|
20
|
-
html.should have_tag('table')
|
21
|
-
html.should have_tag('tr', :count => count + 1) # rows plus header
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should render a thead section for the table" do
|
25
|
-
@render = Munger::Render::Html.new(@report.process)
|
26
|
-
html = @render.render
|
27
|
-
html.should have_tag('thead', :count => 1)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should render a tbody section for the table" do
|
31
|
-
@render = Munger::Render::Html.new(@report.process)
|
32
|
-
html = @render.render
|
33
|
-
html.should have_tag('tbody', :count => 1)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should accept a custom table class" do
|
37
|
-
rep = Munger::Render::Html.new(@report.process, :classes => {:table => 'helloClass'})
|
38
|
-
html = rep.render
|
39
|
-
html.should have_tag('table.helloClass')
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should use aliased column titles" do
|
43
|
-
@report = @report.columns([:age, :name, :score])
|
44
|
-
@report.column_titles = {:age => "The Age", :name => "The Name"}
|
45
|
-
html = Munger::Render::Html.new(@report.process).render
|
46
|
-
html.should match(/The Age/)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should render columns in the right order" do
|
50
|
-
@report = @report.columns([:age, :name]).process
|
51
|
-
html = Munger::Render::Html.new(@report).render
|
52
|
-
html.should have_tag('th', :count => 2) # rows plus header
|
53
|
-
html.should match(/age(.*?)name/)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should render groups" do
|
57
|
-
@report = @report.subgroup(:age).aggregate(:sum => :score).process
|
58
|
-
html = Munger::Render::Html.new(@report).render
|
59
|
-
html.should match(/151/) # only in the aggregate group
|
60
|
-
html.should have_tag('tr.group0', :count => 1)
|
61
|
-
html.should have_tag('tr.group1', :count => 9)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should render group headers" do
|
65
|
-
@report = @report.subgroup(:age, :with_headers => true).process
|
66
|
-
html = Munger::Render::Html.new(@report).render
|
67
|
-
html.should have_tag('tr.groupHeader1', :count => 9)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should render cell styles" do
|
71
|
-
@report.process.style_rows('over_thirty') { |row| row.age > 29 }
|
72
|
-
|
73
|
-
html = Munger::Render::Html.new(@report).render
|
74
|
-
html.should have_tag('tr.over_thirty', :count => 6)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should render row styles" do
|
78
|
-
@report.process.style_cells('highlight', :only => :age) { |c, r| c == 32 }
|
79
|
-
html = Munger::Render::Html.new(@report).render
|
80
|
-
html.should have_tag('td.highlight')
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should render column styles"
|
84
|
-
|
85
|
-
it "should render default css if you ask"
|
86
|
-
|
87
|
-
end
|