ruby-nuggets 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.5.7
5
+ This documentation refers to ruby-nuggets version 0.5.8
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -31,7 +31,7 @@ module Nuggets
31
31
 
32
32
  # call-seq:
33
33
  # hash.unroll(*value_keys) => anArray
34
- # hash.unroll(*value_keys, :sort_by => { |key, value| ... }) => anArray
34
+ # hash.unroll(*value_keys, :sort => ...) => anArray
35
35
  # hash.unroll(*value_keys) { |value_hash| ... } => anArray
36
36
  #
37
37
  # "Unrolls" a nested hash, so that each path through +hash+ results in a
@@ -57,21 +57,31 @@ module Nuggets
57
57
  # #=> [[:foo, :bar, :b, 6, nil], [:foo, :bar, :a, 4, nil]]
58
58
  def unroll(*value_keys, &block)
59
59
  args = value_keys.dup
60
-
61
60
  options = value_keys.last.is_a?(::Hash) ? value_keys.pop : {}
62
- do_sort = options.has_key?(:sort_by)
61
+
62
+ do_sort = if options.has_key?(:sort_by)
63
+ lambda { sort_by(&options[:sort_by]) }
64
+ elsif options.has_key?(:sort)
65
+ sort_opt = options[:sort]
66
+
67
+ if sort_opt == true
68
+ lambda { sort }
69
+ elsif sort_opt.respond_to?(:to_proc)
70
+ lambda { sort(&sort_opt) }
71
+ end
72
+ end
63
73
 
64
74
  rows = []
65
75
 
66
76
  if values.first.is_a?(self.class) # if any is, then all are
67
- (do_sort ? sort_by(&options[:sort_by]) : self).each { |key, value|
77
+ (do_sort ? do_sort.call : self).each { |key, value|
68
78
  value.unroll(*args, &block).each { |row| rows << [key, *row] }
69
79
  }
70
80
  else
71
81
  block[self] if block
72
82
 
73
83
  rows << if value_keys.empty?
74
- do_sort ? sort_by(&options[:sort_by]).map { |key, value| value } : values
84
+ do_sort ? do_sort.call.map { |key, value| value } : values
75
85
  else
76
86
  values_at(*value_keys)
77
87
  end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 5
7
- TINY = 7
7
+ TINY = 8
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille