ruby_reportable 0.4.2 → 0.4.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: effff5f0aa5831dc7975c1e4e4aa00254e86f8ee
4
- data.tar.gz: 793f07f4c7d9a1e44ab07a45abecd190dcb25936
3
+ metadata.gz: 1d0cd73a1582735d357ee4416825b5d5196ff38f
4
+ data.tar.gz: 2ea92387f5ae939dd1157b71a5bc1844da7fe67c
5
5
  SHA512:
6
- metadata.gz: d7f1a8f31e08ccc91df8bb4d689fec211d1aafbbe9f09859a248a415f3622779c38de4b62cd461942dbbf9eb619f5d18ce8a66a8b5fd1cebb7867c14b8f38be5
7
- data.tar.gz: d8ef115a80db54548a33a594a0d283be240b6d893531f48a4cd48c5beca7393de3c811e2d5ddc03bdb7540d897f94707789a18fdcf38789948eb3f08a53bd1be
6
+ metadata.gz: 2a01b3ca5daa501cf06a54009beba2792fed844b25ee9d05cacfb9f347ea25eae0e8ce1c0661ec9f635b792b52c42295a526635a4757bf30f131cc3dba51dbf9
7
+ data.tar.gz: cf827b20f91ce1aa86e60a2ed0cc3a8a5c7eabd79c6be93f47ee69101b05cc7b267bed9b201190ea004843f529108871501671bf840eb876a56d0622bbe53668
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p195
1
+ 2.0.0-p247
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_reportable (0.4.0)
4
+ ruby_reportable (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
- #data.sort_by {|element| sort.map {|column| element[column]} }
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 = {})
@@ -1,3 +1,3 @@
1
1
  module RubyReportable
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
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
- Object.methods
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 == Object.methods.sort.map {|method| {'name' => method}}
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.2
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-07-17 00:00:00.000000000 Z
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.2
96
+ rubygems_version: 2.0.3
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Ruby Reporting