ruby_reportable 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile.lock +1 -1
- data/lib/ruby_reportable/report.rb +15 -7
- data/lib/ruby_reportable/version.rb +1 -1
- data/spec/report_spec.rb +55 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d0cd73a1582735d357ee4416825b5d5196ff38f
|
4
|
+
data.tar.gz: 2ea92387f5ae939dd1157b71a5bc1844da7fe67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a01b3ca5daa501cf06a54009beba2792fed844b25ee9d05cacfb9f347ea25eae0e8ce1c0661ec9f635b792b52c42295a526635a4757bf30f131cc3dba51dbf9
|
7
|
+
data.tar.gz: cf827b20f91ce1aa86e60a2ed0cc3a8a5c7eabd79c6be93f47ee69101b05cc7b267bed9b201190ea004843f529108871501671bf840eb876a56d0622bbe53668
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0-
|
1
|
+
2.0.0-p247
|
data/Gemfile.lock
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'benchmark'
|
2
|
+
require 'date'
|
2
3
|
|
3
4
|
module RubyReportable
|
4
5
|
module Report
|
@@ -170,20 +171,27 @@ module RubyReportable
|
|
170
171
|
end
|
171
172
|
end
|
172
173
|
|
174
|
+
def _convert_for_sort(value)
|
175
|
+
case value.class
|
176
|
+
when NilClass
|
177
|
+
value.to_s
|
178
|
+
when Date, DateTime, Time
|
179
|
+
value
|
180
|
+
when Array
|
181
|
+
value.map {|sub| _convert_for_sort(sub)}
|
182
|
+
else
|
183
|
+
value.to_s
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
173
187
|
def _sort(sort, data, options = {})
|
174
188
|
if sort.to_s.empty?
|
175
189
|
data
|
176
190
|
else
|
177
191
|
sort = [sort] unless sort.is_a?(Array)
|
178
192
|
|
179
|
-
|
180
|
-
sort.map.each do |element|
|
181
|
-
parts = data.partition { |d| d[element].blank? }
|
182
|
-
sorted = parts.last.sort { |a,b| a[element] <=> b[element] }
|
183
|
-
data = sorted + parts.first
|
184
|
-
end
|
193
|
+
data.sort_by {|element| sort.map {|column| _convert_for_sort(element[column]) }}
|
185
194
|
end
|
186
|
-
return data
|
187
195
|
end
|
188
196
|
|
189
197
|
def _group(group, data, options = {})
|
data/spec/report_spec.rb
CHANGED
@@ -196,7 +196,16 @@ describe RubyReportable::Report do
|
|
196
196
|
it "should sort results" do
|
197
197
|
@report.source do
|
198
198
|
logic do
|
199
|
-
|
199
|
+
[
|
200
|
+
'!',
|
201
|
+
'==',
|
202
|
+
'const_missing',
|
203
|
+
'try',
|
204
|
+
'to_s',
|
205
|
+
'zebra',
|
206
|
+
'const_get',
|
207
|
+
'_output'
|
208
|
+
]
|
200
209
|
end
|
201
210
|
end
|
202
211
|
|
@@ -207,7 +216,51 @@ describe RubyReportable::Report do
|
|
207
216
|
source_data = @report._data(@report._source).source
|
208
217
|
final = @report._sort('name', @report._output(source_data))
|
209
218
|
|
210
|
-
final.should ==
|
219
|
+
final.should == [
|
220
|
+
'!',
|
221
|
+
'==',
|
222
|
+
'_output',
|
223
|
+
'const_get',
|
224
|
+
'const_missing',
|
225
|
+
'to_s',
|
226
|
+
'try',
|
227
|
+
'zebra'
|
228
|
+
].map {|e| {'name' => e}}
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should handle multiple sorts" do
|
232
|
+
@report.source do
|
233
|
+
logic do
|
234
|
+
[
|
235
|
+
{'country' => 'USA', 'name' => 'Tinker'},
|
236
|
+
{'country' => 'Sweden', 'name' => 'Charmander'},
|
237
|
+
{'country' => 'USA', 'name' => 'Pikachu'},
|
238
|
+
{'country' => 'Norway', 'name' => 'Slink'},
|
239
|
+
{'country' => 'Sweden', 'name' => 'Katarina'},
|
240
|
+
{'country' => nil, 'name' => 'Slyfox'}
|
241
|
+
]
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
@report.output('country') do
|
246
|
+
element['country']
|
247
|
+
end
|
248
|
+
|
249
|
+
@report.output('name') do
|
250
|
+
element['name']
|
251
|
+
end
|
252
|
+
|
253
|
+
source_data = @report._data(@report._source).source
|
254
|
+
final = @report._sort(['country', 'name'], @report._output(source_data))
|
255
|
+
|
256
|
+
final.should == [
|
257
|
+
{'country' => nil, 'name' => 'Slyfox'},
|
258
|
+
{'country' => 'Norway', 'name' => 'Slink'},
|
259
|
+
{'country' => 'Sweden', 'name' => 'Charmander'},
|
260
|
+
{'country' => 'Sweden', 'name' => 'Katarina'},
|
261
|
+
{'country' => 'USA', 'name' => 'Pikachu'},
|
262
|
+
{'country' => 'USA', 'name' => 'Tinker'},
|
263
|
+
]
|
211
264
|
end
|
212
265
|
end
|
213
266
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_reportable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John 'asceth' Long
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project: ruby_reportable
|
96
|
-
rubygems_version: 2.0.
|
96
|
+
rubygems_version: 2.0.3
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Ruby Reporting
|