rudash 2.17.1 → 2.17.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/at.rb +8 -8
- data/lib/rudash/capitalize.rb +4 -4
- data/lib/rudash/chain.rb +4 -4
- data/lib/rudash/compact.rb +5 -5
- data/lib/rudash/concat.rb +9 -9
- data/lib/rudash/curry.rb +4 -4
- data/lib/rudash/difference.rb +11 -11
- data/lib/rudash/drop_right.rb +9 -9
- data/lib/rudash/each.rb +8 -8
- data/lib/rudash/each_right.rb +10 -10
- data/lib/rudash/eq.rb +4 -4
- data/lib/rudash/every.rb +5 -5
- data/lib/rudash/filter.rb +23 -23
- data/lib/rudash/find.rb +7 -7
- data/lib/rudash/find_last.rb +7 -7
- data/lib/rudash/flip.rb +10 -10
- data/lib/rudash/flow.rb +11 -11
- data/lib/rudash/flow_right.rb +6 -6
- data/lib/rudash/get.rb +22 -22
- data/lib/rudash/group_by.rb +17 -17
- data/lib/rudash/head.rb +8 -8
- data/lib/rudash/identity.rb +4 -4
- data/lib/rudash/initial.rb +6 -6
- data/lib/rudash/intersection.rb +10 -10
- data/lib/rudash/is_array.rb +4 -4
- data/lib/rudash/is_empty.rb +9 -9
- data/lib/rudash/is_equal.rb +4 -4
- data/lib/rudash/is_hash.rb +4 -4
- data/lib/rudash/is_nil.rb +4 -4
- data/lib/rudash/is_number.rb +4 -4
- data/lib/rudash/is_string.rb +4 -4
- data/lib/rudash/join.rb +6 -6
- data/lib/rudash/keys.rb +11 -11
- data/lib/rudash/last.rb +5 -5
- data/lib/rudash/map.rb +19 -19
- data/lib/rudash/negate.rb +8 -8
- data/lib/rudash/pick.rb +16 -16
- data/lib/rudash/range.rb +43 -43
- data/lib/rudash/reduce.rb +29 -29
- data/lib/rudash/reduce_right.rb +5 -5
- data/lib/rudash/reject.rb +13 -13
- data/lib/rudash/remove.rb +9 -9
- data/lib/rudash/reverse.rb +9 -9
- data/lib/rudash/set.rb +20 -20
- data/lib/rudash/size.rb +5 -5
- data/lib/rudash/slice.rb +12 -12
- data/lib/rudash/some.rb +5 -5
- data/lib/rudash/tail.rb +5 -5
- data/lib/rudash/take.rb +11 -11
- data/lib/rudash/union.rb +15 -15
- data/lib/rudash/uniq.rb +11 -11
- data/lib/rudash/unset.rb +30 -30
- data/lib/rudash/update.rb +9 -9
- data/lib/rudash/without.rb +5 -5
- data/lib/rudash.rb +54 -54
- data/lib/utils/chain_wrapper.rb +18 -18
- data/lib/utils/dynamic_args_count.rb +10 -10
- data/lib/utils/index.rb +17 -17
- data/lib/utils/nested_path_creator.rb +24 -24
- data/lib/utils/path_resolver.rb +17 -17
- data/lib/utils/subset_deep_match.rb +41 -41
- data/lib/version.rb +1 -1
- metadata +1 -1
data/lib/rudash/join.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
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)
|
8
7
|
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/rudash/keys.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
module Keys
|
3
|
+
def keys(value)
|
4
|
+
case value
|
5
|
+
when Hash
|
6
|
+
value.map { |key, value| "#{key}" }
|
7
|
+
when Array
|
8
|
+
value.map.with_index { |value, index| "#{index}" }
|
9
|
+
else
|
10
|
+
[]
|
11
|
+
end
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|
data/lib/rudash/last.rb
CHANGED
data/lib/rudash/map.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
2
|
+
module Map
|
3
|
+
def map(collection, *rest_args)
|
4
|
+
iteratee_fn = self.head(rest_args) || self.method(:identity)
|
5
|
+
col = collection.is_a?(String) ? collection.split('') : collection
|
6
|
+
|
7
|
+
return self.map(collection, -> () { nil }) if !Rudash::Utils.is_function?(iteratee_fn)
|
8
|
+
|
9
|
+
if col.is_a?(Array)
|
10
|
+
return col.map.with_index { |value, index|
|
11
|
+
Rudash::DynamicArgsCount.call(iteratee_fn, value, index)
|
12
|
+
}
|
13
|
+
elsif col.is_a?(Hash)
|
14
|
+
return col.map { |k,v|
|
15
|
+
Rudash::DynamicArgsCount.call(iteratee_fn, v, k)
|
16
|
+
}
|
17
|
+
else
|
18
|
+
return []
|
19
|
+
end
|
21
20
|
end
|
21
|
+
end
|
22
22
|
end
|
data/lib/rudash/negate.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
2
|
+
module Negate
|
3
|
+
def negate(a_proc)
|
4
|
+
raise 'Expected a Proc/Method' if !Rudash::Utils.is_function?(a_proc)
|
5
|
+
|
6
|
+
negate_proc = -> (*args) {
|
7
|
+
!a_proc.(*args)
|
8
|
+
}
|
10
9
|
end
|
10
|
+
end
|
11
11
|
end
|
data/lib/rudash/pick.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
}
|
15
|
-
|
16
|
-
self.each(paths, eacher)
|
17
|
-
picked_hash
|
2
|
+
module Pick
|
3
|
+
def pick(hash, paths)
|
4
|
+
return self.pick(hash, [paths]) if !paths.is_a?(Array)
|
5
|
+
return {} if !hash.is_a?(Hash)
|
6
|
+
|
7
|
+
picked_hash = {}
|
8
|
+
|
9
|
+
eacher = -> (path) {
|
10
|
+
value = self.get(hash, path)
|
11
|
+
if !value.nil?
|
12
|
+
self.set(picked_hash, path, value)
|
18
13
|
end
|
14
|
+
}
|
15
|
+
|
16
|
+
self.each(paths, eacher)
|
17
|
+
picked_hash
|
19
18
|
end
|
19
|
+
end
|
20
20
|
end
|
data/lib/rudash/range.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
2
|
+
module Range
|
3
|
+
def range(*args)
|
4
|
+
start_step = 0
|
5
|
+
step_jump = 1
|
6
|
+
end_step = 0
|
7
|
+
|
8
|
+
case args.size
|
9
|
+
when 0
|
10
|
+
return []
|
11
|
+
when 1
|
12
|
+
end_step = args[0]
|
13
|
+
when 2
|
14
|
+
start_step, end_step = args
|
15
|
+
else
|
16
|
+
start_step, end_step, step_jump = args
|
17
|
+
step_jump_configured = true
|
18
|
+
end
|
19
|
+
|
20
|
+
# step_jump direction (+/-) should be defined by start/end values
|
21
|
+
norm_step_jump = (end_step > start_step ? step_jump.abs : -step_jump.abs)
|
22
|
+
|
23
|
+
# illegal behaviors
|
24
|
+
return [] if (norm_step_jump != step_jump && step_jump_configured)
|
25
|
+
# End illegal behavior
|
26
|
+
|
27
|
+
iterator = start_step
|
28
|
+
result = []
|
29
|
+
|
30
|
+
# calculate loop count
|
31
|
+
boundaries = [start_step, end_step]
|
32
|
+
max = boundaries.max
|
33
|
+
min = boundaries.min
|
34
|
+
i = (norm_step_jump == 0 ? (max - min) : ((max - min).to_f / norm_step_jump)).abs
|
35
|
+
# end loop calculation
|
36
|
+
|
37
|
+
while i > 0
|
38
|
+
result << iterator
|
39
|
+
iterator += norm_step_jump
|
40
|
+
i-=1
|
41
|
+
end
|
42
|
+
|
43
|
+
result
|
45
44
|
end
|
45
|
+
end
|
46
46
|
end
|
data/lib/rudash/reduce.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
2
|
+
module Reduce
|
3
|
+
def reduce(collection, *rest_args)
|
4
|
+
reducer = rest_args[0]
|
5
|
+
initial_state = rest_args[1]
|
6
|
+
col = collection.is_a?(String) ? collection.split('') : collection
|
7
|
+
|
8
|
+
return self.reduce(collection, -> () { nil }) if !Rudash::Utils.is_function?(reducer)
|
9
|
+
|
10
|
+
case rest_args.size
|
11
|
+
when 1
|
12
|
+
return col.reduce { |acc, current|
|
13
|
+
if col.is_a?(Hash)
|
14
|
+
Rudash::DynamicArgsCount.call(reducer, acc, current[1], current[0])
|
15
|
+
else
|
16
|
+
Rudash::DynamicArgsCount.call(reducer, acc, current)
|
17
|
+
end
|
18
|
+
}
|
19
|
+
when 2
|
20
|
+
return col.reduce(initial_state) { |acc, current|
|
21
|
+
if col.is_a?(Hash)
|
22
|
+
Rudash::DynamicArgsCount.call(reducer, acc, current[1], current[0])
|
23
|
+
else
|
24
|
+
Rudash::DynamicArgsCount.call(reducer, acc, current)
|
25
|
+
end
|
26
|
+
}
|
27
|
+
else
|
28
|
+
return nil
|
29
|
+
end
|
31
30
|
end
|
31
|
+
end
|
32
32
|
end
|
data/lib/rudash/reduce_right.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
module ReduceRight
|
3
|
+
def reduce_right(collection, *rest_args)
|
4
|
+
reversed_collection = Rudash::Utils.force_reverse(collection)
|
5
|
+
self.reduce(reversed_collection, *rest_args)
|
7
6
|
end
|
7
|
+
end
|
8
8
|
end
|
data/lib/rudash/reject.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
2
|
+
module Reject
|
3
|
+
def reject(collection, *rest_args)
|
4
|
+
filter = self.head(rest_args) || self.method(:identity)
|
5
|
+
|
6
|
+
if filter.is_a?(Hash)
|
7
|
+
slice_matcher = Rudash::SubsetDeepMatch.subset_deep_match?.(filter)
|
8
|
+
return self.filter(collection, self.negate(slice_matcher))
|
9
|
+
elsif Rudash::Utils.is_function?(filter)
|
10
|
+
return self.filter(collection, self.negate(filter))
|
11
|
+
else
|
12
|
+
return []
|
13
|
+
end
|
15
14
|
end
|
15
|
+
end
|
16
16
|
end
|
data/lib/rudash/remove.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
2
|
+
module Remove
|
3
|
+
def remove(array, *rest_args)
|
4
|
+
predicate_fn = self.head(rest_args)
|
5
|
+
return [] if !array.is_a?(Array)
|
6
|
+
removed_items = self.filter(array, predicate_fn)
|
7
|
+
|
8
|
+
array.replace(array - removed_items)
|
9
|
+
removed_items
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/reverse.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
2
|
+
module Reverse
|
3
|
+
def reverse(value)
|
4
|
+
case value
|
5
|
+
when Array, String
|
6
|
+
value.reverse
|
7
|
+
else
|
8
|
+
value
|
9
|
+
end
|
11
10
|
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/rudash/set.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
2
|
+
module Set
|
3
|
+
def set(object, path, value)
|
4
|
+
return object if !object.is_a?(Hash) && !object.is_a?(Array)
|
5
|
+
|
6
|
+
resolved_path = Rudash::PathResolver.resolve(path)
|
7
|
+
Rudash::NestedPathCreator.create_path_if_not_exist(object, resolved_path)
|
8
|
+
|
9
|
+
*initial_path, last = resolved_path
|
10
|
+
|
11
|
+
last_key = Rudash::Utils.match_number?(last) ? last.to_i : last.to_sym
|
12
|
+
|
13
|
+
if initial_path.size == 0
|
14
|
+
object[last_key] = value
|
15
|
+
return object
|
16
|
+
end
|
17
|
+
|
18
|
+
last_parent = self.get(object, initial_path)
|
19
|
+
last_parent[last_key] = value
|
20
|
+
object
|
22
21
|
end
|
22
|
+
end
|
23
23
|
end
|
data/lib/rudash/size.rb
CHANGED
data/lib/rudash/slice.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
2
|
+
module Slice
|
3
|
+
def slice(array, *rest_args)
|
4
|
+
return self.slice(array.split(''), *rest_args) if array.is_a?(String)
|
5
|
+
return [] if !array.is_a?(Array)
|
6
|
+
|
7
|
+
start_point = rest_args[0] || 0
|
8
|
+
end_point = rest_args[1] || array.size
|
9
|
+
|
10
|
+
return [] if !end_point.is_a?(Numeric)
|
11
|
+
|
12
|
+
array.slice(start_point, end_point - start_point) || []
|
14
13
|
end
|
14
|
+
end
|
15
15
|
end
|
data/lib/rudash/some.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
2
|
+
module Some
|
3
|
+
def some?(array, filter)
|
4
|
+
filtered_arr = self.filter(array, filter)
|
5
|
+
filtered_arr.length != 0
|
7
6
|
end
|
7
|
+
end
|
8
8
|
end
|
data/lib/rudash/tail.rb
CHANGED
data/lib/rudash/take.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
module Take
|
3
|
+
def take(array, *rest_args)
|
4
|
+
return [] if !self.is_array?(array)
|
5
|
+
count = self.head(rest_args) || 1
|
6
|
+
|
7
|
+
begin
|
8
|
+
return array.take(count)
|
9
|
+
rescue
|
10
|
+
return []
|
11
|
+
end
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|
data/lib/rudash/union.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
2
|
+
module Union
|
3
|
+
def union(*values)
|
4
|
+
|
5
|
+
union_reducer = -> (acc, current) {
|
6
|
+
return acc if !current.is_a?(Array) || !acc.is_a?(Array)
|
7
|
+
acc | current
|
8
|
+
}
|
9
|
+
|
10
|
+
is_array = -> (value) { value.is_a?(Array) }
|
11
|
+
|
12
|
+
arr_values = self.filter(values, is_array)
|
13
|
+
head = self.head(arr_values)
|
14
|
+
|
15
|
+
self.reduce(arr_values, union_reducer, head) || []
|
17
16
|
end
|
17
|
+
end
|
18
18
|
end
|
data/lib/rudash/uniq.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Rudash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
2
|
+
module Uniq
|
3
|
+
def uniq(value)
|
4
|
+
case value
|
5
|
+
when String
|
6
|
+
self.uniq(value.split(''))
|
7
|
+
when Array
|
8
|
+
value.uniq
|
9
|
+
else
|
10
|
+
[]
|
11
|
+
end
|
13
12
|
end
|
13
|
+
end
|
14
14
|
end
|