array_include_methods 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23f887c53772d4bcdbd1b1d8ba7c6bfc288e0d2a240c4964d14f623ff0e06151
4
- data.tar.gz: 755c0b44e13e6630f2692ac28ad64edaee7ac36586c6b68a6cedf4a5841dae3c
3
+ metadata.gz: 8de965f1a7a26091cfd9b1f2bdbb7191b92148afa5acf2b15b623c7950bc93b9
4
+ data.tar.gz: e8e4892cb0cbdd33d0cbf53dbf41d2e5927cbd364ac002e4983d948a0b418760
5
5
  SHA512:
6
- metadata.gz: 1ddb16dbc31b74e3c5f367a164658326f2f1049cf0d4c50005ea2857f02e06264589ffe0ada88a34af0edab50131cd897776e4b880d9b8e057b23c067fefc4ec
7
- data.tar.gz: 801e45a2e0780f17a248063d4093828a36301d1f78a9ef3875698c8ccfbda6f7fc49a99645131208669de42164ab2428fbd201b755f6f034826baa138ece7904
6
+ metadata.gz: 42a8e991852c1539669847b94b214d11ad7c47011670d432634fff64516ec2ffb8d749df18b165bc18b676539540eb5d7836dac215152909f5e12b27ad8e4f2a
7
+ data.tar.gz: 42be75002418adf80e9c7177f6d420dabaa0db20950cbc2d54ef4558773e75697269f0ed9f0849bacc40084c0e7296c55ca163d5f07215592a495f03c3479b54
data/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # Change Log
2
+
3
+ ## 1.1.0
4
+
5
+ - Perform contiguous-element `include_all?([...])` check against an array argument (not splatted)
6
+ - Perform sorted `include_all?([...])` check against an array argument (not splatted)
7
+ - Perform non-repetition `include_all?([...])` check against an array argument (not splatted)
8
+
9
+ ## 1.0.4
10
+
11
+ - Support splat args (e.g. `include_any?(1, 2, 3)` instead of `include_any?([1, 2, 3])`)
12
+
13
+ ## 1.0.3
14
+
15
+ - Opal compatibility through monkey-patching and providing a `using` method shim so that existing gems that used the refinement in Ruby work
16
+
17
+ ## 1.0.2
18
+
19
+ - Handled case of two arrays with elements of unsortable object types (e.g. Hash)
20
+
21
+ ## 1.0.1
22
+
23
+ - Handled case of two arrays with different ordering of common elements
24
+
25
+ ## 1.0.0
26
+
27
+ - Initial implementation of Array#include_all? & Array#include_any?
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- # ArrayIncludeMethods 1.0.1 - Ruby Refinement
1
+ # ArrayIncludeMethods 1.1.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
+ [![Build Status](https://travis-ci.com/AndyObtiva/array_include_methods.svg?branch=master)](https://travis-ci.com/AndyObtiva/array_include_methods)
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)
3
5
 
4
6
  `Array#include_all?` & `Array#include_any?` methods missing from basic Ruby `Array` API.
5
7
 
@@ -10,7 +12,7 @@
10
12
  Include the following in Gemfile:
11
13
 
12
14
  ```ruby
13
- gem 'array_include_methods', '~> 1.0.1'
15
+ gem 'array_include_methods', '~> 1.1.0'
14
16
  ```
15
17
 
16
18
  Run:
@@ -24,7 +26,7 @@ bundle
24
26
  Run:
25
27
 
26
28
  ```
27
- gem install array_include_methods -v1.0.1
29
+ gem install array_include_methods -v1.1.0
28
30
  ```
29
31
 
30
32
  ## Usage
@@ -48,7 +50,15 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
48
50
  ### `Array#include_all?(other_array)`
49
51
 
50
52
  ```ruby
51
- [1, 2, 3, 4].include_all?([2, 4]) # returns true
53
+ [1, 2, 3, 4].include_all?(2, 3) # returns true
54
+ [1, 2, 3, 4].include_all?([2, 3]) # returns true
55
+ [1, 2, 3, 4].include_all?(2, 4) # returns true
56
+ [1, 2, 3, 4].include_all?([2, 4]) # returns false (checks true array containment)
57
+ [1, 2, 3, 4].include_all?(4, 2) # returns true
58
+ [1, 2, 3, 4].include_all?([4, 2]) # returns false (checks true array containment)
59
+ [1, 2, 3, 4].include_all?(2, 4, 4) # returns true
60
+ [1, 2, 3, 4].include_all?([2, 4, 4]) # returns false (checks true array containment)
61
+ [1, 2, 3, 4].include_all?(2, 4, 5) # returns false
52
62
  [1, 2, 3, 4].include_all?([2, 4, 5]) # returns false
53
63
  [1, 2, 3, 4].include_all?([]) # returns true
54
64
  [1, 2, 3, 4].include_all?(nil) # returns false
@@ -57,21 +67,25 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
57
67
  ### `Array#include_any?(other_array)`
58
68
 
59
69
  ```ruby
70
+ [1, 2, 3, 4].include_any?(2, 4, 5) # returns true
60
71
  [1, 2, 3, 4].include_any?([2, 4, 5]) # returns true
72
+ [1, 2, 3, 4].include_any?(6, 7) # returns false
61
73
  [1, 2, 3, 4].include_any?([6, 7]) # returns false
62
74
  [1, 2, 3, 4].include_any?([]) # returns true
63
75
  [1, 2, 3, 4].include_any?(nil) # returns false
64
76
  ```
65
77
 
66
- ## Change Log
78
+ ## Opal Compatibility
79
+
80
+ 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
67
81
 
68
- ### 1.0.1
82
+ ## TODO
69
83
 
70
- - Handled case of two arrays with different ordering of common elements
84
+ [TODO.md](TODO.md)
71
85
 
72
- ### 1.0.0
86
+ ## Change Log
73
87
 
74
- - Initial implementation of Array#include_all? & Array#include_any?
88
+ [CHANGELOG.md](CHANGELOG.md)
75
89
 
76
90
  ## Contributing to array_include_methods
77
91
 
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: array_include_methods 1.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "array_include_methods".freeze
9
+ s.version = "1.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Andy Maleh".freeze]
14
+ s.date = "2021-09-25"
15
+ s.description = "Array#include_all? & Array#include_any? methods missing from basic Ruby Array API".freeze
16
+ s.email = "andy.am@gmail.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "CHANGELOG.md",
19
+ "LICENSE.txt",
20
+ "README.md"
21
+ ]
22
+ s.files = [
23
+ "CHANGELOG.md",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "VERSION",
27
+ "array_include_methods.gemspec",
28
+ "lib/array_include_methods.rb"
29
+ ]
30
+ s.homepage = "http://github.com/AndyObtiva/array_include_methods".freeze
31
+ s.licenses = ["MIT".freeze]
32
+ s.rubygems_version = "3.2.22".freeze
33
+ s.summary = "Array#include_all? & Array#include_any? methods missing from basic Ruby Array API".freeze
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+ end
38
+
39
+ if s.respond_to? :add_runtime_dependency then
40
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
41
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
42
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
43
+ s.add_development_dependency(%q<coveralls>.freeze, ["= 0.8.23"])
44
+ s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
45
+ s.add_development_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
46
+ s.add_development_dependency(%q<rake-tui>.freeze, ["> 0"])
47
+ else
48
+ s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
49
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
50
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.3.9"])
51
+ s.add_dependency(%q<coveralls>.freeze, ["= 0.8.23"])
52
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
53
+ s.add_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
54
+ s.add_dependency(%q<rake-tui>.freeze, ["> 0"])
55
+ end
56
+ end
57
+
@@ -1,13 +1,38 @@
1
1
  module ArrayIncludeMethods
2
+ if RUBY_PLATFORM == 'opal'
3
+ def self.refine(class_or_module, &refinement)
4
+ class_or_module.class_eval(&refinement)
5
+ end
6
+ end
2
7
  refine Array do
3
8
  # Returns `true` if all of the given `array` elements are present in `self`,
4
9
  # otherwise returns `false`
5
10
  # Always returns `true` if the given `array` is empty
6
11
  # Always returns `false` if the given `array` is nil
7
- def include_all?(array)
12
+ def include_all?(*array)
13
+ array_argument = false
14
+ if array.size == 1 && array[0].is_a?(Array)
15
+ array_argument = true
16
+ array = array[0]
17
+ end
8
18
  return false if array.nil?
9
19
  array_include_other_array_same_class_elements = lambda do |a1, a2|
10
- (a1 & a2).uniq.sort == a2.uniq.sort
20
+ begin
21
+ if array_argument
22
+ if a2.size > a1.size
23
+ false
24
+ else
25
+ size_diff = a1.size - a2.size
26
+ (size_diff + 1).times.any? do |start_index|
27
+ a1[start_index, a2.size] == a2
28
+ end
29
+ end
30
+ else
31
+ (a1 & a2).uniq.sort == a2.uniq.sort
32
+ end
33
+ rescue ArgumentError => e
34
+ a2.uniq.all? { |element| a1.include?(element) }
35
+ end
11
36
  end
12
37
  self_grouped_by = self.group_by(&:class)
13
38
  array_grouped_by = array.group_by(&:class)
@@ -24,8 +49,15 @@ module ArrayIncludeMethods
24
49
  # otherwise returns `false`
25
50
  # Always returns `true` if the given `array` is empty
26
51
  # Always returns `false` if the given `array` is nil
27
- def include_any?(array)
52
+ def include_any?(*array)
53
+ array = array[0] if array.size == 1 && array[0].is_a?(Array)
28
54
  !array.nil? && (array.empty? || !(self & array).empty?)
29
55
  end
30
56
  end
31
57
  end
58
+ if RUBY_PLATFORM == 'opal'
59
+ # Create a shim using method that does nothing since we monkey-patch in Opal earlier in `refine` method
60
+ def self.using(refinement)
61
+ # NO OP
62
+ end
63
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: array_include_methods
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-01 00:00:00.000000000 Z
11
+ date: 2021-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,18 +52,60 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.3.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.23
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.23
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: simplecov
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.16.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.16.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-lcov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake-tui
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
60
102
  - !ruby/object:Gem::Version
61
103
  version: '0'
62
104
  type: :development
63
105
  prerelease: false
64
106
  version_requirements: !ruby/object:Gem::Requirement
65
107
  requirements:
66
- - - ">="
108
+ - - ">"
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  description: Array#include_all? & Array#include_any? methods missing from basic Ruby
@@ -72,17 +114,21 @@ email: andy.am@gmail.com
72
114
  executables: []
73
115
  extensions: []
74
116
  extra_rdoc_files:
117
+ - CHANGELOG.md
75
118
  - LICENSE.txt
76
119
  - README.md
77
120
  files:
121
+ - CHANGELOG.md
78
122
  - LICENSE.txt
79
123
  - README.md
124
+ - VERSION
125
+ - array_include_methods.gemspec
80
126
  - lib/array_include_methods.rb
81
127
  homepage: http://github.com/AndyObtiva/array_include_methods
82
128
  licenses:
83
129
  - MIT
84
130
  metadata: {}
85
- post_install_message:
131
+ post_install_message:
86
132
  rdoc_options: []
87
133
  require_paths:
88
134
  - lib
@@ -97,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
143
  - !ruby/object:Gem::Version
98
144
  version: '0'
99
145
  requirements: []
100
- rubygems_version: 3.1.2
101
- signing_key:
146
+ rubygems_version: 3.2.22
147
+ signing_key:
102
148
  specification_version: 4
103
149
  summary: Array#include_all? & Array#include_any? methods missing from basic Ruby Array
104
150
  API