rudash 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudash/at.rb +11 -10
  3. data/lib/rudash/capitalize.rb +9 -7
  4. data/lib/rudash/compact.rb +7 -5
  5. data/lib/rudash/concat.rb +10 -8
  6. data/lib/rudash/curry.rb +9 -7
  7. data/lib/rudash/difference.rb +14 -12
  8. data/lib/rudash/each.rb +12 -10
  9. data/lib/rudash/each_right.rb +14 -12
  10. data/lib/rudash/eq.rb +5 -3
  11. data/lib/rudash/every.rb +8 -6
  12. data/lib/rudash/filter.rb +25 -25
  13. data/lib/rudash/find.rb +10 -10
  14. data/lib/rudash/find_last.rb +10 -9
  15. data/lib/rudash/flip.rb +9 -7
  16. data/lib/rudash/get.rb +26 -25
  17. data/lib/rudash/head.rb +10 -8
  18. data/lib/rudash/identity.rb +5 -3
  19. data/lib/rudash/initial.rb +7 -5
  20. data/lib/rudash/intersection.rb +13 -11
  21. data/lib/rudash/is_array.rb +5 -3
  22. data/lib/rudash/is_empty.rb +9 -7
  23. data/lib/rudash/is_equal.rb +5 -3
  24. data/lib/rudash/is_hash.rb +5 -3
  25. data/lib/rudash/is_nil.rb +5 -3
  26. data/lib/rudash/is_number.rb +5 -3
  27. data/lib/rudash/is_proc.rb +5 -3
  28. data/lib/rudash/is_string.rb +9 -7
  29. data/lib/rudash/join.rb +7 -5
  30. data/lib/rudash/keys.rb +11 -9
  31. data/lib/rudash/last.rb +6 -4
  32. data/lib/rudash/map.rb +23 -22
  33. data/lib/rudash/negate.rb +11 -9
  34. data/lib/rudash/pick.rb +20 -20
  35. data/lib/rudash/reduce.rb +34 -32
  36. data/lib/rudash/reduce_right.rb +8 -6
  37. data/lib/rudash/remove.rb +12 -12
  38. data/lib/rudash/reverse.rb +9 -7
  39. data/lib/rudash/set.rb +22 -20
  40. data/lib/rudash/size.rb +8 -6
  41. data/lib/rudash/slice.rb +13 -11
  42. data/lib/rudash/some.rb +8 -6
  43. data/lib/rudash/tail.rb +6 -4
  44. data/lib/rudash/union.rb +18 -18
  45. data/lib/rudash/uniq.rb +11 -9
  46. data/lib/rudash/update.rb +10 -11
  47. data/lib/rudash/without.rb +8 -6
  48. data/lib/rudash.rb +46 -46
  49. data/lib/utils/index.rb +14 -12
  50. data/lib/utils/nested_path_creator.rb +22 -20
  51. data/lib/utils/path_resolver.rb +17 -15
  52. data/lib/utils/subset_deep_match.rb +42 -40
  53. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd83c39622ad30f4a0c1831c7ccb7cd7a92c5bad4f46e39b854d2e7bf9f6f176
4
- data.tar.gz: 3dbd1c65c36b27dfa5b1b3a8bcefbc84b600d9c8f20c9f43a9861cafa96af37a
3
+ metadata.gz: e987273a8b6ffa1757fdb51262efc6cbbac87163547016e584cfc59a10baffb8
4
+ data.tar.gz: 436525000120d10dca368e60634d2adf942dea647ca24d1774fc7fa49568bd94
5
5
  SHA512:
6
- metadata.gz: a85e4581e865eab2ec4c3fdc43fe3c442e4d4b953e531942278d8b37e186c3af466bf3e35e14a83d2147176ca640bd425dd2ce5f1d2a17b9e1faf624bdccf7c4
7
- data.tar.gz: aba56b13cbd1ca07343cd2eec0914dcc64f2a6e61e817afab123ac6f57766e737cdd2c3a0cc42ceb53047fdcd163c58a4ce6b2f31e51d581e0128bcc4352dfb7
6
+ metadata.gz: 2681e573738db3534f6d7bc2bfeab947403bcbe5fefabd47f3af8071e8d8c135bc290c5bf81d838785ba2bdf15b5bff0e6f7ef629117088f3aac065fb95165d9
7
+ data.tar.gz: e26add9c41040bfe7f51ffc21b4317d2c54065543b1d83f56e431d2f53cf6af065d64ee2004169213ecd3892936d96f40caf643918f2cd0db12f376fafa3e57b
data/lib/rudash/at.rb CHANGED
@@ -1,15 +1,16 @@
1
1
  require_relative 'get.rb'
2
2
  require_relative 'map.rb'
3
3
 
4
- module At
5
- extend Get
6
- extend Map
7
-
8
- def at(object, paths)
9
- get_mapper = -> (path) {
10
- self.get(object, path)
11
- }
12
-
13
- self.map(paths, get_mapper)
4
+ module Rudash
5
+ module At
6
+ extend Rudash
7
+
8
+ def at(object, paths)
9
+ get_mapper = -> (path) {
10
+ self.get(object, path)
11
+ }
12
+
13
+ self.map(paths, get_mapper)
14
+ end
14
15
  end
15
16
  end
@@ -1,10 +1,12 @@
1
- module Capitalize
2
- def capitalize(value)
3
- case value
4
- when String
5
- value.capitalize
6
- else
7
- value.to_s
1
+ module Rudash
2
+ module Capitalize
3
+ def capitalize(value)
4
+ case value
5
+ when String
6
+ value.capitalize
7
+ else
8
+ value.to_s
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,10 +1,12 @@
1
1
  require_relative 'is_nil.rb'
2
2
 
3
- module Compact
4
- extend IsNil
3
+ module Rudash
4
+ module Compact
5
+ extend Rudash
5
6
 
6
- def compact(array)
7
- return [] if !array.is_a?(Array)
8
- array.compact
7
+ def compact(array)
8
+ return [] if !array.is_a?(Array)
9
+ array.compact
10
+ end
9
11
  end
10
12
  end
data/lib/rudash/concat.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require_relative 'is_nil.rb'
2
2
 
3
- module Concat
4
- extend IsNil
3
+ module Rudash
4
+ module Concat
5
+ extend Rudash
5
6
 
6
- def concat(head, *values)
7
- head_arr = head.is_a?(Array) ? head : [head]
8
- if values.size == 0
9
- return head_arr
10
- else
11
- return head_arr + self.concat(*values)
7
+ def concat(head, *values)
8
+ head_arr = head.is_a?(Array) ? head : [head]
9
+ if values.size == 0
10
+ return head_arr
11
+ else
12
+ return head_arr + self.concat(*values)
13
+ end
12
14
  end
13
15
  end
14
16
  end
data/lib/rudash/curry.rb CHANGED
@@ -1,10 +1,12 @@
1
- module Curry
2
- def curry(a_proc)
3
- case a_proc
4
- when Proc
5
- a_proc.curry
6
- else
7
- raise 'Expected a Proc'
1
+ module Rudash
2
+ module Curry
3
+ def curry(a_proc)
4
+ case a_proc
5
+ when Proc
6
+ a_proc.curry
7
+ else
8
+ raise 'Expected a Proc'
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,16 +1,18 @@
1
1
  require_relative 'reduce.rb'
2
2
 
3
- module Difference
4
- extend Reduce
5
-
6
- def difference(*values)
7
- diff_reducer = -> (acc, current) {
8
- return [] if !acc.is_a?(Array)
9
- return acc if !current.is_a?(Array)
10
-
11
- acc - current
12
- }
13
-
14
- self.reduce(values, diff_reducer)
3
+ module Rudash
4
+ module Difference
5
+ extend Rudash
6
+
7
+ def difference(*values)
8
+ diff_reducer = -> (acc, current) {
9
+ return [] if !acc.is_a?(Array)
10
+ return acc if !current.is_a?(Array)
11
+
12
+ acc - current
13
+ }
14
+
15
+ self.reduce(values, diff_reducer)
16
+ end
15
17
  end
16
18
  end
data/lib/rudash/each.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require_relative 'map.rb'
2
2
 
3
- module Each
4
- extend Map
5
-
6
- def each(collection, *rest_args)
7
- self.map(collection, *rest_args)
8
- collection
9
- end
10
-
11
- def for_each(*args)
12
- self.each(*args)
3
+ module Rudash
4
+ module Each
5
+ extend Rudash
6
+
7
+ def each(collection, *rest_args)
8
+ self.map(collection, *rest_args)
9
+ collection
10
+ end
11
+
12
+ def for_each(*args)
13
+ self.each(*args)
14
+ end
13
15
  end
14
16
  end
@@ -1,17 +1,19 @@
1
1
  require_relative 'each.rb'
2
2
  require_relative '../utils/index.rb'
3
3
 
4
- module EachRight
5
- extend Each
6
-
7
- def each_right(collection, *rest_args)
8
- reversed_collection = Utils.force_reverse(collection)
9
-
10
- self.each(reversed_collection, *rest_args)
11
- collection
12
- end
13
-
14
- def for_each_right(*args)
15
- self.each_right(*args)
4
+ module Rudash
5
+ module EachRight
6
+ extend Rudash
7
+
8
+ def each_right(collection, *rest_args)
9
+ reversed_collection = Rudash::Utils.force_reverse(collection)
10
+
11
+ self.each(reversed_collection, *rest_args)
12
+ collection
13
+ end
14
+
15
+ def for_each_right(*args)
16
+ self.each_right(*args)
17
+ end
16
18
  end
17
19
  end
data/lib/rudash/eq.rb CHANGED
@@ -1,5 +1,7 @@
1
- module Eq
2
- def eq?(object, other)
3
- object.equal?(other)
1
+ module Rudash
2
+ module Eq
3
+ def eq?(object, other)
4
+ object.equal?(other)
5
+ end
4
6
  end
5
7
  end
data/lib/rudash/every.rb CHANGED
@@ -1,10 +1,12 @@
1
1
  require_relative 'filter.rb'
2
2
 
3
- module Every
4
- extend Filter
5
-
6
- def every?(array, filter)
7
- filtered_arr = self.filter(array, filter)
8
- filtered_arr.length == array.length
3
+ module Rudash
4
+ module Every
5
+ extend Rudash
6
+
7
+ def every?(array, filter)
8
+ filtered_arr = self.filter(array, filter)
9
+ filtered_arr.length == array.length
10
+ end
9
11
  end
10
12
  end
data/lib/rudash/filter.rb CHANGED
@@ -3,33 +3,33 @@ require_relative 'identity.rb'
3
3
  require_relative 'head.rb'
4
4
  require_relative '../utils/subset_deep_match.rb'
5
5
 
6
- module Filter
7
- extend IsNil
8
- extend Identity
9
- extend Head
10
-
11
- def filter(collection, *rest_args)
12
- filter = self.head(rest_args) || self.method(:identity)
13
-
14
- if filter.is_a?(Hash)
15
- slice_matcher = SubsetDeepMatch.subset_deep_match?.(filter)
16
- return self.filter(collection, slice_matcher)
17
- end
18
-
19
- if collection.is_a?(Array)
20
- begin
21
- return collection.select.with_index { |x, idx| filter[x, idx] }
22
- rescue ArgumentError => e
23
- return collection.select { |x| filter[x] }
6
+ module Rudash
7
+ module Filter
8
+ extend Rudash
9
+
10
+ def filter(collection, *rest_args)
11
+ filter = self.head(rest_args) || self.method(:identity)
12
+
13
+ if filter.is_a?(Hash)
14
+ slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(filter)
15
+ return self.filter(collection, slice_matcher)
24
16
  end
25
- elsif collection.is_a?(Hash)
26
- begin
27
- return collection.select { |k, v| filter[v, k] }
28
- rescue ArgumentError => e
29
- return collection.select { |k, v| filter[v] }
17
+
18
+ if collection.is_a?(Array)
19
+ begin
20
+ return collection.select.with_index { |x, idx| filter[x, idx] }
21
+ rescue ArgumentError => e
22
+ return collection.select { |x| filter[x] }
23
+ end
24
+ elsif collection.is_a?(Hash)
25
+ begin
26
+ return collection.select { |k, v| filter[v, k] }
27
+ rescue ArgumentError => e
28
+ return collection.select { |k, v| filter[v] }
29
+ end
30
+ else
31
+ return []
30
32
  end
31
- else
32
- return []
33
33
  end
34
34
  end
35
35
  end
data/lib/rudash/find.rb CHANGED
@@ -2,15 +2,15 @@ require_relative 'filter.rb'
2
2
  require_relative 'head.rb'
3
3
  require_relative 'identity.rb'
4
4
 
5
- module Find
6
- extend Filter
7
- extend Head
8
- extend Identity
9
-
10
- def find(collection, *rest_args)
11
- filter_proc = self.head(rest_args) || self.method(:identity)
12
- filtered_arr = self.filter(collection, filter_proc)
13
-
14
- filtered_arr[0]
5
+ module Rudash
6
+ module Find
7
+ extend Rudash
8
+
9
+ def find(collection, *rest_args)
10
+ filter_proc = self.head(rest_args) || self.method(:identity)
11
+ filtered_arr = self.filter(collection, filter_proc)
12
+
13
+ filtered_arr[0]
14
+ end
15
15
  end
16
16
  end
@@ -1,14 +1,15 @@
1
1
  require_relative 'filter.rb'
2
2
  require_relative 'identity.rb'
3
3
 
4
- module FindLast
5
- extend Filter
6
- extend Identity
7
-
8
- def find_last(collection, *rest_args)
9
- filter_proc = self.head(rest_args) || self.method(:identity)
10
- filtered_arr = self.filter(collection, filter_proc)
11
-
12
- filtered_arr[filtered_arr.length - 1]
4
+ module Rudash
5
+ module FindLast
6
+ extend Rudash
7
+
8
+ def find_last(collection, *rest_args)
9
+ filter_proc = self.head(rest_args) || self.method(:identity)
10
+ filtered_arr = self.filter(collection, filter_proc)
11
+
12
+ filtered_arr[filtered_arr.length - 1]
13
+ end
13
14
  end
14
15
  end
data/lib/rudash/flip.rb CHANGED
@@ -1,9 +1,11 @@
1
- module Flip
2
- def flip(a_proc)
3
- flipped_proc = -> (*args) {
4
- reveresed_args = args.reverse
5
-
6
- a_proc[*reveresed_args]
7
- }
1
+ module Rudash
2
+ module Flip
3
+ def flip(a_proc)
4
+ flipped_proc = -> (*args) {
5
+ reveresed_args = args.reverse
6
+
7
+ a_proc[*reveresed_args]
8
+ }
9
+ end
8
10
  end
9
11
  end
data/lib/rudash/get.rb CHANGED
@@ -3,30 +3,31 @@ require_relative 'filter.rb'
3
3
  require_relative '../utils/path_resolver.rb'
4
4
  require_relative '../utils/index.rb'
5
5
 
6
- module Get
7
- extend Reduce
8
- extend Filter
9
-
10
- def get(hash, path, *rest_args)
11
- return nil if !path.is_a?(String) && !path.is_a?(Array)
12
- return nil if !hash.is_a?(Array) && !hash.is_a?(Hash)
13
-
14
- resolved_path = PathResolver.resolve(path)
15
-
16
- get_reducer = -> (acc, current) {
17
- return nil if acc.nil?
18
-
19
- if acc.is_a?(Array) && Utils.match_number?(current)
20
- acc[current.to_i]
21
- elsif acc.is_a?(Array) && !Utils.match_number?(current)
22
- nil
23
- elsif acc.is_a?(Hash)
24
- acc[current.to_sym] || acc[current]
25
- else
26
- nil
27
- end
28
- }
29
-
30
- self.reduce(resolved_path, get_reducer, hash)
6
+ module Rudash
7
+ module Get
8
+ extend Rudash
9
+
10
+ def get(hash, path, *rest_args)
11
+ return nil if !path.is_a?(String) && !path.is_a?(Array)
12
+ return nil if !hash.is_a?(Array) && !hash.is_a?(Hash)
13
+
14
+ resolved_path = Rudash::PathResolver.resolve(path)
15
+
16
+ get_reducer = -> (acc, current) {
17
+ return nil if acc.nil?
18
+
19
+ if acc.is_a?(Array) && Rudash::Utils.match_number?(current)
20
+ acc[current.to_i]
21
+ elsif acc.is_a?(Array) && !Rudash::Utils.match_number?(current)
22
+ nil
23
+ elsif acc.is_a?(Hash)
24
+ acc[current.to_sym] || acc[current]
25
+ else
26
+ nil
27
+ end
28
+ }
29
+
30
+ self.reduce(resolved_path, get_reducer, hash)
31
+ end
31
32
  end
32
33
  end
data/lib/rudash/head.rb CHANGED
@@ -1,10 +1,12 @@
1
- module Head
2
- def head(array)
3
- return nil if !array.is_a?(Array)
4
- array.first
5
- end
6
-
7
- def first(*args)
8
- self.head(*args)
1
+ module Rudash
2
+ module Head
3
+ def head(array)
4
+ return nil if !array.is_a?(Array)
5
+ array.first
6
+ end
7
+
8
+ def first(*args)
9
+ self.head(*args)
10
+ end
9
11
  end
10
12
  end
@@ -1,5 +1,7 @@
1
- module Identity
2
- def identity(first_arg, *rest_args)
3
- first_arg
1
+ module Rudash
2
+ module Identity
3
+ def identity(first_arg, *rest_args)
4
+ first_arg
5
+ end
4
6
  end
5
7
  end
@@ -1,7 +1,9 @@
1
- module Initial
2
- def initial(array)
3
- return [] if !array.is_a?(Array)
4
- *initial, last = array
5
- initial
1
+ module Rudash
2
+ module Initial
3
+ def initial(array)
4
+ return [] if !array.is_a?(Array)
5
+ *initial, last = array
6
+ initial
7
+ end
6
8
  end
7
9
  end
@@ -1,15 +1,17 @@
1
1
  require_relative 'reduce.rb'
2
2
 
3
- module Intersection
4
- extend Reduce
5
-
6
- def intersection(*values)
7
-
8
- intersection_reducer = -> (acc, current) {
9
- return [] if !current.is_a?(Array) || !acc.is_a?(Array)
10
- acc & current
11
- }
12
-
13
- self.reduce(values, intersection_reducer, values[0])
3
+ module Rudash
4
+ module Intersection
5
+ extend Rudash
6
+
7
+ def intersection(*values)
8
+
9
+ intersection_reducer = -> (acc, current) {
10
+ return [] if !current.is_a?(Array) || !acc.is_a?(Array)
11
+ acc & current
12
+ }
13
+
14
+ self.reduce(values, intersection_reducer, values[0])
15
+ end
14
16
  end
15
17
  end
@@ -1,5 +1,7 @@
1
- module IsArray
2
- def is_array?(value)
3
- value.is_a?(Array)
1
+ module Rudash
2
+ module IsArray
3
+ def is_array?(value)
4
+ value.is_a?(Array)
5
+ end
4
6
  end
5
7
  end
@@ -1,10 +1,12 @@
1
- module IsEmpty
2
- def is_empty?(value)
3
- case value
4
- when Hash, Array
5
- value.empty?
6
- else
7
- true
1
+ module Rudash
2
+ module IsEmpty
3
+ def is_empty?(value)
4
+ case value
5
+ when Hash, Array
6
+ value.empty?
7
+ else
8
+ true
9
+ end
8
10
  end
9
11
  end
10
12
  end
@@ -1,5 +1,7 @@
1
- module IsEqual
2
- def is_equal?(value, other)
3
- value == other
1
+ module Rudash
2
+ module IsEqual
3
+ def is_equal?(value, other)
4
+ value == other
5
+ end
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
- module IsHash
2
- def is_hash?(value)
3
- value.is_a?(Hash)
1
+ module Rudash
2
+ module IsHash
3
+ def is_hash?(value)
4
+ value.is_a?(Hash)
5
+ end
4
6
  end
5
7
  end
data/lib/rudash/is_nil.rb CHANGED
@@ -1,5 +1,7 @@
1
- module IsNil
2
- def is_nil?(object)
3
- object.nil?
1
+ module Rudash
2
+ module IsNil
3
+ def is_nil?(object)
4
+ object.nil?
5
+ end
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
- module IsNumber
2
- def is_number?(value)
3
- value.is_a?(Numeric)
1
+ module Rudash
2
+ module IsNumber
3
+ def is_number?(value)
4
+ value.is_a?(Numeric)
5
+ end
4
6
  end
5
7
  end
@@ -1,5 +1,7 @@
1
- module IsProc
2
- def is_proc?(value)
3
- value.is_a?(Proc)
1
+ module Rudash
2
+ module IsProc
3
+ def is_proc?(value)
4
+ value.is_a?(Proc)
5
+ end
4
6
  end
5
7
  end
@@ -1,10 +1,12 @@
1
- module IsString
2
- def is_string?(object)
3
- case object
4
- when String
5
- true
6
- else
7
- false
1
+ module Rudash
2
+ module IsString
3
+ def is_string?(object)
4
+ case object
5
+ when String
6
+ true
7
+ else
8
+ false
9
+ end
8
10
  end
9
11
  end
10
12
  end
data/lib/rudash/join.rb CHANGED
@@ -1,7 +1,9 @@
1
- module Join
2
- def join(array, separator = ',')
3
- return '' if !array.is_a?(Array)
4
- stringified_separator = separator.is_a?(String) ? separator : separator.to_s
5
- array.join(stringified_separator)
1
+ module Rudash
2
+ module Join
3
+ def join(array, separator = ',')
4
+ return '' if !array.is_a?(Array)
5
+ stringified_separator = separator.is_a?(String) ? separator : separator.to_s
6
+ array.join(stringified_separator)
7
+ end
6
8
  end
7
9
  end