cotcube-helpers 0.1.7.3 → 0.1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/cotcube-helpers/array_ext.rb +28 -28
- 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: a685d90173074f0ee3490602a9108cec0f8a8ff6e616fce2db1ef3566d0f2ef6
|
4
|
+
data.tar.gz: b08e52e6e47a233658765b4fdb3aab72d649aefff91eabb46e8cbcef6542e84e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ced4fffb8f219416f05fe6daf3e891499e788d58d1ca4ea233cfff18998972b3aa9f0be10abdda3081671e534d0346201cfa7f5442b0bc996b75a6f3b1208b
|
7
|
+
data.tar.gz: 853ae393f9f3ba54321d82d2dba17e61fd6f85a4609029dee619ddcab10b2c2e5aa5dd6e7105f3f88e1e072b60034f7657a4cb53baed8188ddb67347326bce7a
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.7.
|
1
|
+
0.1.7.4
|
@@ -47,7 +47,7 @@ class Array
|
|
47
47
|
# same as pairwise, but with arity of three
|
48
48
|
def triplewise(ret=nil, &block)
|
49
49
|
raise ArgumentError, 'Array.triplewise needs an arity of 3 (i.e. |a, b, c|)' unless block.arity == 3
|
50
|
-
raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails. unless self.last.respond_to?(:[]=)
|
50
|
+
raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
|
51
51
|
return [] if size <= 2
|
52
52
|
|
53
53
|
each_index.map do |i|
|
@@ -65,37 +65,37 @@ class Array
|
|
65
65
|
unless attr.nil? || first[attr]
|
66
66
|
raise ArgumentError,
|
67
67
|
"At least first element of Array '#{first}' does not contain attr '#{attr}'!"
|
68
|
-
end
|
69
|
-
raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
|
70
|
-
raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
|
71
|
-
x.respond_to? :include?
|
72
|
-
end.reduce(:&)
|
73
|
-
|
74
|
-
select do |el|
|
75
|
-
value = attr.nil? ? el : el[attr]
|
76
|
-
ranges.map do |range|
|
77
|
-
range.include?(block.nil? ? value : block.call(value))
|
78
|
-
end.reduce(:|)
|
79
|
-
end
|
80
68
|
end
|
69
|
+
raise ArgumentError, 'Ranges should be an Array or, more precisely, respond_to :map' unless ranges.respond_to? :map
|
70
|
+
raise ArgumentError, 'Each range in :ranges should respond to .include!' unless ranges.map do |x|
|
71
|
+
x.respond_to? :include?
|
72
|
+
end.reduce(:&)
|
73
|
+
|
74
|
+
select do |el|
|
75
|
+
value = attr.nil? ? el : el[attr]
|
76
|
+
ranges.map do |range|
|
77
|
+
range.include?(block.nil? ? value : block.call(value))
|
78
|
+
end.reduce(:|)
|
79
|
+
end
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
def select_right_by(inclusive: false, exclusive: false, initial: [], &block)
|
83
|
+
# unless range.is_a? Range and
|
84
|
+
# (range.begin.nil? or range.begin.is_a?(Integer)) and
|
85
|
+
# (range.end.nil? or range.end.is_a?(Integer))
|
86
|
+
# raise ArgumentError, ":range, if given, must be a range of ( nil|Integer..nil|Integer), got '#{range}'"
|
87
|
+
# end
|
88
88
|
|
89
|
-
|
89
|
+
raise ArgumentError, 'No block given.' unless block.is_a? Proc
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
inclusive = true unless exclusive
|
92
|
+
if inclusive && exclusive
|
93
|
+
raise ArgumentError,
|
94
|
+
"Either :inclusive or :exclusive must remain falsey, got '#{inclusive}' and '#{exclusive}'"
|
95
|
+
end
|
96
96
|
|
97
|
-
|
97
|
+
index = find_index { |obj| block.call(obj) }
|
98
98
|
|
99
|
-
|
100
|
-
|
99
|
+
self[((inclusive ? index : index + 1)..)]
|
100
|
+
end
|
101
101
|
end
|