array_include_methods 1.3.0 → 1.4.0
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 +5 -0
- data/README.md +35 -3
- data/VERSION +1 -1
- data/array_include_methods.gemspec +2 -2
- data/lib/array_include_methods.rb +31 -0
- 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: 201b9e696a4644180df82e669767d5a83cd626dc9863ba7451d22707c53b20ba
|
4
|
+
data.tar.gz: b3920beaa33a19dedf9430eca869400cf763d0ddc0a28005550a7ea569c953e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '00929ce43674a96779a5a08c43357fcd0e4708782586a732f9040f6981c70858a80971f101a61a22b1d6de3e0e7a36d8d585d318f66370f040535443ea3ac04a'
|
7
|
+
data.tar.gz: d71713c34a7adad5d900342273666c99388b0c5e2b8cff0f3a45071c07809664bc904fd0d68576d322361b0e29dd118ae22076d7272fc7cb57379b72a43ae270
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.4.0
|
4
|
+
|
5
|
+
- `array_diff_indexes(other_array)` (alias: `array_diff_indices`)
|
6
|
+
- `array_intersection_indexes(other_array)` (alias: `array_intersection_indices`)
|
7
|
+
|
3
8
|
## 1.3.0
|
4
9
|
|
5
10
|
- [API Breaking] Separate between operations `include_any?(*array)` and `include_any?(array)` to avoid confusion (remove support for the latter as it is not necessary)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ArrayIncludeMethods 1.
|
1
|
+
# ArrayIncludeMethods 1.4.0 - Ruby Refinement
|
2
2
|
[](http://badge.fury.io/rb/array_include_methods)
|
3
3
|
[](https://travis-ci.com/AndyObtiva/array_include_methods)
|
4
4
|
[](https://coveralls.io/github/AndyObtiva/array_include_methods?branch=master)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
Include the following in Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'array_include_methods', '~> 1.
|
15
|
+
gem 'array_include_methods', '~> 1.4.0'
|
16
16
|
```
|
17
17
|
|
18
18
|
Run:
|
@@ -26,7 +26,7 @@ bundle
|
|
26
26
|
Run:
|
27
27
|
|
28
28
|
```
|
29
|
-
gem install array_include_methods -v1.
|
29
|
+
gem install array_include_methods -v1.4.0
|
30
30
|
```
|
31
31
|
|
32
32
|
## Usage
|
@@ -96,6 +96,38 @@ Returns first array index of `other_array` in `first_array` assuming `first_arra
|
|
96
96
|
[1, 2, 3, 4].array_index(nil) # returns -1
|
97
97
|
```
|
98
98
|
|
99
|
+
### `Array#array_intersection_indexes(other_array)`
|
100
|
+
(alias: `Array#array_intersection_indices(other_array)`)
|
101
|
+
|
102
|
+
Returns indexes from `self` array for which elements match elements in `other_array` assuming same sort
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
[1, 2, 3, 4].array_intersection_indexes([2, 3, 4]) # returns [1, 2, 3]
|
106
|
+
[1, 2, 3, 4].array_intersection_indexes([2, 3]) # returns [1, 2]
|
107
|
+
[1, 2, 3, 4].array_intersection_indexes([3, 4]) # returns [2, 3]
|
108
|
+
[1, 2, 3, 4].array_intersection_indexes([2, 4]) # returns [1, 3]
|
109
|
+
[1, 2, 3, 4].array_intersection_indexes([4, 2]) # returns [3]
|
110
|
+
[1, 2, 3, 4].array_intersection_indexes([2, 4, 5]) # returns [1, 3]
|
111
|
+
[1, 2, 3, 4].array_intersection_indexes([]) # returns []
|
112
|
+
[1, 2, 3, 4].array_intersection_indexes(nil) # returns []
|
113
|
+
```
|
114
|
+
|
115
|
+
### `Array#array_diff_indexes(other_array)`
|
116
|
+
(alias: `Array#array_diff_indices(other_array)`)
|
117
|
+
|
118
|
+
Returns indexes from `self` array for which elements do not match elements in `other_array` assuming same sort
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
[1, 2, 3, 4].array_diff_indexes([2, 3, 4]) # returns [0]
|
122
|
+
[1, 2, 3, 4].array_diff_indexes([2, 3]) # returns [0, 3]
|
123
|
+
[1, 2, 3, 4].array_diff_indexes([3, 4]) # returns [0, 1]
|
124
|
+
[1, 2, 3, 4].array_diff_indexes([2, 4]) # returns [0, 2]
|
125
|
+
[1, 2, 3, 4].array_diff_indexes([4, 2]) # returns [0, 1, 2]
|
126
|
+
[1, 2, 3, 4].array_diff_indexes([2, 4, 5]) # returns [0, 2]
|
127
|
+
[1, 2, 3, 4].array_diff_indexes([]) # returns [0, 1, 2, 3]
|
128
|
+
[1, 2, 3, 4].array_diff_indexes(nil) # returns [0, 1, 2, 3]
|
129
|
+
```
|
130
|
+
|
99
131
|
## Opal Compatibility
|
100
132
|
|
101
133
|
This gem degrades gracefully to monkey-patching in [Opal Ruby](https://opalrb.com) and provides a `using` method shim so consumer code does not have to change if it used gems that rely on the Ruby refinement
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: array_include_methods 1.
|
5
|
+
# stub: array_include_methods 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "array_include_methods".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -65,6 +65,37 @@ module ArrayIncludeMethods
|
|
65
65
|
end
|
66
66
|
result_array_index
|
67
67
|
end
|
68
|
+
|
69
|
+
def array_intersection_indexes(array)
|
70
|
+
array_intersection_and_diff_indexes(array)[:intersection_indexes]
|
71
|
+
end
|
72
|
+
alias array_intersection_indices array_intersection_indexes
|
73
|
+
|
74
|
+
def array_diff_indexes(array)
|
75
|
+
array_intersection_and_diff_indexes(array)[:diff_indexes]
|
76
|
+
end
|
77
|
+
alias array_diff_indices array_diff_indexes
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def array_intersection_and_diff_indexes(array)
|
82
|
+
return {intersection_indexes: [], diff_indexes: self.size.times.to_a} if array.nil?
|
83
|
+
intersection_indexes = []
|
84
|
+
diff_indexes = []
|
85
|
+
array_current_index = 0
|
86
|
+
each_with_index do |element, index|
|
87
|
+
if element == array[array_current_index]
|
88
|
+
intersection_indexes << index
|
89
|
+
array_current_index += 1
|
90
|
+
else
|
91
|
+
diff_indexes << index
|
92
|
+
end
|
93
|
+
end
|
94
|
+
{
|
95
|
+
intersection_indexes: intersection_indexes,
|
96
|
+
diff_indexes: diff_indexes
|
97
|
+
}
|
98
|
+
end
|
68
99
|
end
|
69
100
|
end
|
70
101
|
if RUBY_PLATFORM == 'opal'
|