array_include_methods 1.0.0 → 1.0.1

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: 464cd95859200569276f7df56c046348abdfa36a0c6674dd44d026f95cd520d7
4
- data.tar.gz: 6ccb6950c545d4623403da76a40f43e16dc4b8f818b5a54144a7bd38ce7b3aa8
3
+ metadata.gz: 23f887c53772d4bcdbd1b1d8ba7c6bfc288e0d2a240c4964d14f623ff0e06151
4
+ data.tar.gz: 755c0b44e13e6630f2692ac28ad64edaee7ac36586c6b68a6cedf4a5841dae3c
5
5
  SHA512:
6
- metadata.gz: bb21245c8ead69fb5edca573721c06f556954bf0eef71421d329944a789cfe5de285911df1e03c463d71cfb0514a134e87d60d8a4cd9b23aa915a6988d629b98
7
- data.tar.gz: a0c2f9c11c53c3859fd809faa132aa5318e15359b649b3e749495267f07ee01de862eb029fe92a194e95cee9600a36694b2b4922b584153f04fe4b8e84704c35
6
+ metadata.gz: 1ddb16dbc31b74e3c5f367a164658326f2f1049cf0d4c50005ea2857f02e06264589ffe0ada88a34af0edab50131cd897776e4b880d9b8e057b23c067fefc4ec
7
+ data.tar.gz: 801e45a2e0780f17a248063d4093828a36301d1f78a9ef3875698c8ccfbda6f7fc49a99645131208669de42164ab2428fbd201b755f6f034826baa138ece7904
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ArrayIncludeMethods - Ruby Refinement
1
+ # ArrayIncludeMethods 1.0.1 - 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
 
4
4
  `Array#include_all?` & `Array#include_any?` methods missing from basic Ruby `Array` API.
@@ -10,7 +10,7 @@
10
10
  Include the following in Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'array_include_methods', '~> 1.0.0'
13
+ gem 'array_include_methods', '~> 1.0.1'
14
14
  ```
15
15
 
16
16
  Run:
@@ -24,7 +24,7 @@ bundle
24
24
  Run:
25
25
 
26
26
  ```
27
- gem install array_include_methods -v1.0.0
27
+ gem install array_include_methods -v1.0.1
28
28
  ```
29
29
 
30
30
  ## Usage
@@ -41,6 +41,38 @@ To activate the `ArrayIncludeMethods` Ruby Refinement for the `Array` class, add
41
41
  using ArrayIncludeMethods
42
42
  ```
43
43
 
44
+ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
45
+
46
+ ## Examples
47
+
48
+ ### `Array#include_all?(other_array)`
49
+
50
+ ```ruby
51
+ [1, 2, 3, 4].include_all?([2, 4]) # returns true
52
+ [1, 2, 3, 4].include_all?([2, 4, 5]) # returns false
53
+ [1, 2, 3, 4].include_all?([]) # returns true
54
+ [1, 2, 3, 4].include_all?(nil) # returns false
55
+ ```
56
+
57
+ ### `Array#include_any?(other_array)`
58
+
59
+ ```ruby
60
+ [1, 2, 3, 4].include_any?([2, 4, 5]) # returns true
61
+ [1, 2, 3, 4].include_any?([6, 7]) # returns false
62
+ [1, 2, 3, 4].include_any?([]) # returns true
63
+ [1, 2, 3, 4].include_any?(nil) # returns false
64
+ ```
65
+
66
+ ## Change Log
67
+
68
+ ### 1.0.1
69
+
70
+ - Handled case of two arrays with different ordering of common elements
71
+
72
+ ### 1.0.0
73
+
74
+ - Initial implementation of Array#include_all? & Array#include_any?
75
+
44
76
  ## Contributing to array_include_methods
45
77
 
46
78
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -5,7 +5,19 @@ module ArrayIncludeMethods
5
5
  # Always returns `true` if the given `array` is empty
6
6
  # Always returns `false` if the given `array` is nil
7
7
  def include_all?(array)
8
- !array.nil? && self & array == array
8
+ return false if array.nil?
9
+ array_include_other_array_same_class_elements = lambda do |a1, a2|
10
+ (a1 & a2).uniq.sort == a2.uniq.sort
11
+ end
12
+ self_grouped_by = self.group_by(&:class)
13
+ array_grouped_by = array.group_by(&:class)
14
+ return false unless array_include_other_array_same_class_elements.call(self_grouped_by.keys.map(&:to_s), array_grouped_by.keys.map(&:to_s))
15
+ array_grouped_by.reduce(true) do |result, pair|
16
+ array_class = pair.first
17
+ array_elements = pair.last
18
+ self_grouped_by[array_class]
19
+ result && array_include_other_array_same_class_elements.call(self_grouped_by[array_class], array_elements)
20
+ end
9
21
  end
10
22
 
11
23
  # Returns `true` if any of the given `array` elements are present in `self`,
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.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh