array_include_methods 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8de965f1a7a26091cfd9b1f2bdbb7191b92148afa5acf2b15b623c7950bc93b9
4
- data.tar.gz: e8e4892cb0cbdd33d0cbf53dbf41d2e5927cbd364ac002e4983d948a0b418760
3
+ metadata.gz: 925807376e5d7c387227dc33369fa80dcefd7abc7f4164f5ed939e8de9a0fa66
4
+ data.tar.gz: 5a316e7e928da5eb1028e626fbcdec588e21fc66d683afec48278da7bdcc5899
5
5
  SHA512:
6
- metadata.gz: 42a8e991852c1539669847b94b214d11ad7c47011670d432634fff64516ec2ffb8d749df18b165bc18b676539540eb5d7836dac215152909f5e12b27ad8e4f2a
7
- data.tar.gz: 42be75002418adf80e9c7177f6d420dabaa0db20950cbc2d54ef4558773e75697269f0ed9f0849bacc40084c0e7296c55ca163d5f07215592a495f03c3479b54
6
+ metadata.gz: 8e50f5e30e11b7e2c19234fe207c436b87ee37ff690212af30eb9460eab789ba08dc06b545d55aa2d41d80ccaf2a97f37c6ee2dfeaac31f7d53be55b1ccb7b26
7
+ data.tar.gz: 9de14d6773e0f55527f6857fb72c75be710615cc02eb61fcf297ca00d3ee2db3d9b9a2e6fea05ebde468497d79a66a38996bd2f1877b0f9813b798b94b93d1dc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.2.0
4
+
5
+ - Add `Array#array_index(array)` method to determine start array index of other array
6
+
3
7
  ## 1.1.0
4
8
 
5
9
  - Perform contiguous-element `include_all?([...])` check against an array argument (not splatted)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ArrayIncludeMethods 1.1.0 - Ruby Refinement
1
+ # ArrayIncludeMethods 1.2.0 - Ruby Refinement
2
2
  [![Gem Version](https://badge.fury.io/rb/array_include_methods.svg)](http://badge.fury.io/rb/array_include_methods)
3
3
  [![Build Status](https://travis-ci.com/AndyObtiva/array_include_methods.svg?branch=master)](https://travis-ci.com/AndyObtiva/array_include_methods)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/array_include_methods/badge.svg?branch=master)](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.1.0'
15
+ gem 'array_include_methods', '~> 1.2.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.1.0
29
+ gem install array_include_methods -v1.2.0
30
30
  ```
31
31
 
32
32
  ## Usage
@@ -47,7 +47,18 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
47
47
 
48
48
  ## Examples
49
49
 
50
- ### `Array#include_all?(other_array)`
50
+ ### `Array#include_any?(*other_array)`
51
+
52
+ ```ruby
53
+ [1, 2, 3, 4].include_any?(2, 4, 5) # returns true
54
+ [1, 2, 3, 4].include_any?([2, 4, 5]) # returns true
55
+ [1, 2, 3, 4].include_any?(6, 7) # returns false
56
+ [1, 2, 3, 4].include_any?([6, 7]) # returns false
57
+ [1, 2, 3, 4].include_any?([]) # returns true
58
+ [1, 2, 3, 4].include_any?(nil) # returns false
59
+ ```
60
+
61
+ ### `Array#include_all?(*other_array)`
51
62
 
52
63
  ```ruby
53
64
  [1, 2, 3, 4].include_all?(2, 3) # returns true
@@ -64,15 +75,19 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
64
75
  [1, 2, 3, 4].include_all?(nil) # returns false
65
76
  ```
66
77
 
67
- ### `Array#include_any?(other_array)`
78
+ ### `Array#array_index(other_array)`
79
+
80
+ Returns first array index of `other_array` in `first_array` assuming `first_array.include_all?(other_array)` returns true
68
81
 
69
82
  ```ruby
70
- [1, 2, 3, 4].include_any?(2, 4, 5) # returns true
71
- [1, 2, 3, 4].include_any?([2, 4, 5]) # returns true
72
- [1, 2, 3, 4].include_any?(6, 7) # returns false
73
- [1, 2, 3, 4].include_any?([6, 7]) # returns false
74
- [1, 2, 3, 4].include_any?([]) # returns true
75
- [1, 2, 3, 4].include_any?(nil) # returns false
83
+ [1, 2, 3, 4].array_index([2, 3, 4]) # returns 1
84
+ [1, 2, 3, 4].array_index([2, 3]) # returns 1
85
+ [1, 2, 3, 4].array_index([3, 4]) # returns 2
86
+ [1, 2, 3, 4].array_index([2, 4]) # returns -1
87
+ [1, 2, 3, 4].array_index([4, 2]) # returns -1
88
+ [1, 2, 3, 4].array_index([2, 4, 5]) # returns -1
89
+ [1, 2, 3, 4].array_index([]) # returns -1
90
+ [1, 2, 3, 4].array_index(nil) # returns -1
76
91
  ```
77
92
 
78
93
  ## Opal Compatibility
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.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.1.0 ruby lib
5
+ # stub: array_include_methods 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "array_include_methods".freeze
9
- s.version = "1.1.0"
9
+ s.version = "1.2.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]
@@ -53,6 +53,21 @@ module ArrayIncludeMethods
53
53
  array = array[0] if array.size == 1 && array[0].is_a?(Array)
54
54
  !array.nil? && (array.empty? || !(self & array).empty?)
55
55
  end
56
+
57
+ def array_index(array)
58
+ result_array_index = -1
59
+ return result_array_index if array.nil?
60
+ if array.size <= self.size
61
+ size_diff = self.size - array.size
62
+ current_array_index = nil
63
+ result = (size_diff + 1).times.any? do |start_index|
64
+ current_array_index = start_index
65
+ self[start_index, array.size] == array
66
+ end
67
+ result_array_index = current_array_index if result
68
+ end
69
+ result_array_index
70
+ end
56
71
  end
57
72
  end
58
73
  if RUBY_PLATFORM == 'opal'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array_include_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh