rudash 2.8.0 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rudash/at.rb +11 -10
- data/lib/rudash/capitalize.rb +9 -7
- data/lib/rudash/compact.rb +7 -5
- data/lib/rudash/concat.rb +10 -8
- data/lib/rudash/curry.rb +9 -7
- data/lib/rudash/difference.rb +14 -12
- data/lib/rudash/each.rb +12 -10
- data/lib/rudash/each_right.rb +14 -12
- data/lib/rudash/eq.rb +5 -3
- data/lib/rudash/every.rb +8 -6
- data/lib/rudash/filter.rb +25 -25
- data/lib/rudash/find.rb +10 -10
- data/lib/rudash/find_last.rb +10 -9
- data/lib/rudash/flip.rb +9 -7
- data/lib/rudash/get.rb +26 -25
- data/lib/rudash/head.rb +10 -8
- data/lib/rudash/identity.rb +5 -3
- data/lib/rudash/initial.rb +7 -5
- data/lib/rudash/intersection.rb +13 -11
- data/lib/rudash/is_array.rb +5 -3
- data/lib/rudash/is_empty.rb +9 -7
- data/lib/rudash/is_equal.rb +5 -3
- data/lib/rudash/is_hash.rb +5 -3
- data/lib/rudash/is_nil.rb +5 -3
- data/lib/rudash/is_number.rb +5 -3
- data/lib/rudash/is_proc.rb +5 -3
- data/lib/rudash/is_string.rb +9 -7
- data/lib/rudash/join.rb +7 -5
- data/lib/rudash/keys.rb +11 -9
- data/lib/rudash/last.rb +6 -4
- data/lib/rudash/map.rb +23 -22
- data/lib/rudash/negate.rb +11 -9
- data/lib/rudash/pick.rb +20 -20
- data/lib/rudash/reduce.rb +34 -32
- data/lib/rudash/reduce_right.rb +8 -6
- data/lib/rudash/remove.rb +12 -12
- data/lib/rudash/reverse.rb +9 -7
- data/lib/rudash/set.rb +22 -20
- data/lib/rudash/size.rb +8 -6
- data/lib/rudash/slice.rb +13 -11
- data/lib/rudash/some.rb +8 -6
- data/lib/rudash/tail.rb +6 -4
- data/lib/rudash/union.rb +18 -18
- data/lib/rudash/uniq.rb +11 -9
- data/lib/rudash/update.rb +10 -11
- data/lib/rudash/without.rb +8 -6
- data/lib/rudash.rb +46 -46
- data/lib/utils/index.rb +14 -12
- data/lib/utils/nested_path_creator.rb +22 -20
- data/lib/utils/path_resolver.rb +17 -15
- data/lib/utils/subset_deep_match.rb +42 -40
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e987273a8b6ffa1757fdb51262efc6cbbac87163547016e584cfc59a10baffb8
|
4
|
+
data.tar.gz: 436525000120d10dca368e60634d2adf942dea647ca24d1774fc7fa49568bd94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
data/lib/rudash/capitalize.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/rudash/compact.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require_relative 'is_nil.rb'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module Rudash
|
4
|
+
module Compact
|
5
|
+
extend Rudash
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
4
|
-
|
3
|
+
module Rudash
|
4
|
+
module Concat
|
5
|
+
extend Rudash
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/rudash/difference.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require_relative 'reduce.rb'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/lib/rudash/each_right.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
require_relative 'each.rb'
|
2
2
|
require_relative '../utils/index.rb'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
data/lib/rudash/every.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require_relative 'filter.rb'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
data/lib/rudash/find_last.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require_relative 'filter.rb'
|
2
2
|
require_relative 'identity.rb'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
data/lib/rudash/identity.rb
CHANGED
data/lib/rudash/initial.rb
CHANGED
data/lib/rudash/intersection.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require_relative 'reduce.rb'
|
2
2
|
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
data/lib/rudash/is_array.rb
CHANGED
data/lib/rudash/is_empty.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/rudash/is_equal.rb
CHANGED
data/lib/rudash/is_hash.rb
CHANGED
data/lib/rudash/is_nil.rb
CHANGED
data/lib/rudash/is_number.rb
CHANGED
data/lib/rudash/is_proc.rb
CHANGED
data/lib/rudash/is_string.rb
CHANGED
data/lib/rudash/join.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|