rudash 2.8.1 → 2.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rudash/filter.rb +12 -4
- data/lib/rudash/flip.rb +1 -1
- data/lib/rudash/map.rb +12 -4
- data/lib/rudash/negate.rb +1 -1
- data/lib/rudash/reduce.rb +6 -6
- 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: c10d55f0e8a0c9fa3172f01030876b2094501ee6dec705d6b97c09de1b2870fe
|
4
|
+
data.tar.gz: 47c4324b5f508c47222dafdff4ea24dd2511d5bbce0d6d8599b4d130df621d5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aac039a0e05f5fd2ddb67eee5a997acdac8274495cca9f1a074e9418720798d4dd48f531dbb4c00f1c6a4ea4b37e89ba76c9751fdab0ecae15359e7bcd127b59
|
7
|
+
data.tar.gz: 18f0778caae5e1fb1b3386f648061c415ceecb7d17a655e9401ce08bb5735b06cfd3622fb5f580e527318da6ab06cede06d9b875d0e7cba8ac7bf64bd3191c0b
|
data/lib/rudash/filter.rb
CHANGED
@@ -17,15 +17,23 @@ module Rudash
|
|
17
17
|
|
18
18
|
if collection.is_a?(Array)
|
19
19
|
begin
|
20
|
-
return collection.select.with_index { |x, idx| filter
|
20
|
+
return collection.select.with_index { |x, idx| filter.(x, idx) }
|
21
21
|
rescue ArgumentError => e
|
22
|
-
|
22
|
+
begin
|
23
|
+
return collection.select { |x| filter.(x) }
|
24
|
+
rescue ArgumentError => e
|
25
|
+
return collection.select { filter.() }
|
26
|
+
end
|
23
27
|
end
|
24
28
|
elsif collection.is_a?(Hash)
|
25
29
|
begin
|
26
|
-
return collection.select { |k, v| filter
|
30
|
+
return collection.select { |k, v| filter.(v, k) }
|
27
31
|
rescue ArgumentError => e
|
28
|
-
|
32
|
+
begin
|
33
|
+
return collection.select { |k, v| filter.(v) }
|
34
|
+
rescue ArgumentError => e
|
35
|
+
return collection.select { filter.() }
|
36
|
+
end
|
29
37
|
end
|
30
38
|
else
|
31
39
|
return []
|
data/lib/rudash/flip.rb
CHANGED
data/lib/rudash/map.rb
CHANGED
@@ -12,15 +12,23 @@ module Rudash
|
|
12
12
|
|
13
13
|
if col.is_a?(Array)
|
14
14
|
begin
|
15
|
-
return col.map.with_index { |value, index| mapper_proc
|
15
|
+
return col.map.with_index { |value, index| mapper_proc.(value, index) }
|
16
16
|
rescue ArgumentError => e
|
17
|
-
|
17
|
+
begin
|
18
|
+
return col.map { |value| mapper_proc.(value) }
|
19
|
+
rescue ArgumentError => e
|
20
|
+
return col.map { mapper_proc.() }
|
21
|
+
end
|
18
22
|
end
|
19
23
|
elsif col.is_a?(Hash)
|
20
24
|
begin
|
21
|
-
return col.map { |k,v| mapper_proc
|
25
|
+
return col.map { |k,v| mapper_proc.(v, k) }
|
22
26
|
rescue ArgumentError => e
|
23
|
-
|
27
|
+
begin
|
28
|
+
return col.map { |k,v| mapper_proc.(v) }
|
29
|
+
rescue ArgumentError => e
|
30
|
+
return col.map { mapper_proc.() }
|
31
|
+
end
|
24
32
|
end
|
25
33
|
else
|
26
34
|
return []
|
data/lib/rudash/negate.rb
CHANGED
data/lib/rudash/reduce.rb
CHANGED
@@ -11,24 +11,24 @@ module Rudash
|
|
11
11
|
return col.reduce { |acc, current|
|
12
12
|
if col.is_a?(Hash)
|
13
13
|
begin
|
14
|
-
reducer
|
14
|
+
reducer.(acc, current[1], current[0])
|
15
15
|
rescue ArgumentError => e
|
16
|
-
reducer
|
16
|
+
reducer.(acc, current[1])
|
17
17
|
end
|
18
18
|
else
|
19
|
-
reducer
|
19
|
+
reducer.(acc, current)
|
20
20
|
end
|
21
21
|
}
|
22
22
|
when 2
|
23
23
|
return col.reduce(initial_state) { |acc, current|
|
24
24
|
if col.is_a?(Hash)
|
25
25
|
begin
|
26
|
-
reducer
|
26
|
+
reducer.(acc, current[1], current[0])
|
27
27
|
rescue ArgumentError => e
|
28
|
-
reducer
|
28
|
+
reducer.(acc, current[1])
|
29
29
|
end
|
30
30
|
else
|
31
|
-
reducer
|
31
|
+
reducer.(acc, current)
|
32
32
|
end
|
33
33
|
}
|
34
34
|
else
|