rangops 1.0.0.beta1 → 1.0.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: 485eb7acc54d2b3bbb164eba5bb8feb7740db3a0f0fbdeeaed3f0daa8e8e0c98
4
- data.tar.gz: 074c8cc3f02759af90fd9319a82126a1be621ce626cac962c061018d76d2c175
3
+ metadata.gz: 5710c3163c9b9098afe8d67062eff72e52018d102c4d2eeb322038a73692b52c
4
+ data.tar.gz: 3a832f5d480caf10ec7dc687363d602134b3749d51531f9bc8b1967b32c2b18f
5
5
  SHA512:
6
- metadata.gz: 7386938a537baa3226be2ac6f5f504acb46778c836422a809385c56acd3508b4e4a1fef6a44d2dd30fe784a1399a036a5e0804c6c0e8f3cf47e5b62f7a43e33a
7
- data.tar.gz: 8b7da51eb22ee01822246af4e7fca799d10250b4b92574fef5339b850d1e709c3dcb456a5f0a562f9af9e5b6c80a4e51f36bb650c07d439c6bba96e063b71021
6
+ metadata.gz: d9afee6c9742f6903f5cea072e9061aa3eb5f16600a500fdd48b9c68642fe4c21d376acf64b021b19bea0a1e5e402f36cff23aae690181d295bde7774b0f1931
7
+ data.tar.gz: 0f06c047dd654d539c2aa93869dab696e8e32184cba8f4b30a37671d33b09159c62b11b0354b948e49b11b3ba6525afa78736e40cd82e2b2c42073503e1a29b0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rangops (1.0.0.beta1)
4
+ rangops (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,49 +1,90 @@
1
1
  # Rangops
2
2
 
3
- Rangops is a simple Ruby extension library that aims to treat Ranges as sets.
3
+ Rangops is a tiny Ruby extension library that aims to treat Ranges as sets.
4
4
 
5
- It provides methods for elementary set related operations and predicates.
5
+ Install it with `gem install rangops` or add `gem "rangops"` to your Gemfile.
6
6
 
7
- class Range
8
- include Rangops::Set
9
- end
7
+ It patches `Range` class with methods for basic set related operations
8
+ and predicates, like:
10
9
 
11
10
  Union:
12
11
 
13
- (1..5).union(3..10)
14
- => 1..10
12
+ (1..5).union(3..10)
13
+ => 1..10
15
14
 
16
- (11..19) | (16..23)
17
- => 11..23
15
+ (1..5) + (3..10)
16
+ => 1..10
18
17
 
19
18
  Intersection:
20
19
 
21
- (1..5).intersection(3..10)
22
- => 3..5
20
+ (1..5).intersection(3..10)
21
+ => 3..5
23
22
 
24
- (11..19) & (16..23)
25
- => 16..19
23
+ (1..5) & (3..10)
24
+ => 3..5
26
25
 
27
26
 
28
- Complement, difference operations and subset/superset checking is also available.
29
- For full list of methods, check [API docs](https://bartpiet.github.io/rangops/).
27
+ Symmetric difference:
30
28
 
31
- No mapping to arrays nor iterating on elements is performed, so operations
32
- on ranges of any size are possible without penalty on speed or memory usage.
33
- Ranges delimited with any type of Numerics can be operated.
29
+ (1..10).difference(5..15)
30
+ => [1..5, 10..15]
34
31
 
35
- (1.0..10).union(Rational(20, 4)..Float::INFINITY)
36
- => 1.0..Infinity
32
+ (1..10) - (5..15)
33
+ => [1..5, 10..15]
37
34
 
38
- It works equally well on string and date ranges, although some operations may be
39
- not available if they only make sense for numbers.
35
+ Relative complement:
40
36
 
41
- Library tries to adhere to conventions established in Ruby core and `Set` module
42
- from standard library. It only focuses on extending core Range class; only ranges or
43
- elements covered by them can be used as arguments. Due to the properties of Range class,
44
- most operations return meaningful results only for ranges of the same type.
37
+ (1..10).complement(5..15)
38
+ => 10..15
39
+
40
+ Checking for subsets/supersets:
41
+
42
+ (2..3).subset?(0..10)
43
+ => true
44
+
45
+ (0..10).superset?(2..3)
46
+ => true
47
+
48
+
49
+ Check [API docs](https://bartpiet.github.io/rangops/Rangops/Set.html) for full list of aliases
50
+ and predicates.
51
+
52
+ There is no mapping to arrays nor iteratons under the hood,
53
+ just begin/end values comparison - so operations on ranges of any size are
54
+ possible, with no penalty on speed or memory usage.
55
+ Ranges delimited with any type of Numerics can be used.
56
+
57
+ (1.0..10).union(Rational(20, 4)..Float::INFINITY)
58
+ => 1.0..Infinity
59
+
60
+ Beginless and endless ranges are supported.
61
+
62
+ (nil..10).intersection(5..nil)
63
+ => 5..10
64
+
65
+ (nil..10).union(5..nil)
66
+ => nil..nil
67
+
68
+ End exclusion is supported too.
69
+
70
+ (1...3).intersect?(3..10)
71
+ => false
72
+
73
+ It works well on string and date ranges too.
74
+
75
+ ('2025-01-01'..'2026-12-31') & ('2026-01-01'..'2027-12-31')
76
+ => '2026-01-01'..'2026-12-31'
77
+
78
+ ('a'..'e') & ('c'..'g')
79
+ => "c".."e"
80
+
81
+
82
+ Operations are supposed to return a `Range` result, so they only work on
83
+ arguments delimited with values of the same type.
84
+ `(1..5) & ('c'..'g')` will just return `nil`.
45
85
 
46
86
 
47
87
  ## License
48
88
 
49
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
89
+ The gem is available as open source under the terms of the
90
+ [MIT License](https://opensource.org/licenses/MIT).
data/docs/README_md.html CHANGED
@@ -8,7 +8,7 @@
8
8
  <title>README - Rangops</title>
9
9
 
10
10
  <meta name="keywords" content="ruby,documentation,README">
11
- <meta name="description" content="README: Rangops Rangops is a simple Ruby extension library that aims to treat Ranges as sets. It provides methods for elementary set related operations and p">
11
+ <meta name="description" content="README: Rangops Rangops is a tiny Ruby extension library that aims to treat Ranges as sets. Install it with `gem install rangops` or add `gem &quot;rangops&quot;` to y">
12
12
 
13
13
 
14
14
  <script type="text/javascript">
@@ -106,41 +106,78 @@
106
106
 
107
107
  <h1 id="label-Rangops"><a href="Rangops.html"><code>Rangops</code></a><span><a href="#label-Rangops">&para;</a> <a href="#top">&uarr;</a></span></h1>
108
108
 
109
- <p><a href="Rangops.html"><code>Rangops</code></a> is a simple Ruby extension library that aims to treat Ranges as sets.</p>
109
+ <p><a href="Rangops.html"><code>Rangops</code></a> is a tiny Ruby extension library that aims to treat Ranges as sets.</p>
110
110
 
111
- <p>It provides methods for elementary set related operations and predicates.</p>
111
+ <p>Install it with <code>gem install rangops</code> or add <code>gem &quot;rangops&quot;</code> to your Gemfile.</p>
112
112
 
113
- <pre class="ruby"> <span class="ruby-keyword">class</span> <span class="ruby-constant">Range</span>
114
- <span class="ruby-identifier">include</span> <span class="ruby-constant">Rangops</span><span class="ruby-operator">::</span><span class="ruby-constant">Set</span>
115
- <span class="ruby-keyword">end</span>
116
- </pre>
113
+ <p>It patches <code>Range</code> class with methods for basic set related operations and predicates, like:</p>
117
114
 
118
115
  <p>Union:</p>
119
116
 
120
- <pre> (1..5).union(3..10)
121
- =&gt; 1..10
117
+ <pre>(1..5).union(3..10)
118
+ =&gt; 1..10
122
119
 
123
- (11..19) | (16..23)
124
- =&gt; 11..23</pre>
120
+ (1..5) + (3..10)
121
+ =&gt; 1..10</pre>
125
122
 
126
123
  <p>Intersection:</p>
127
124
 
128
- <pre> (1..5).intersection(3..10)
129
- =&gt; 3..5
125
+ <pre>(1..5).intersection(3..10)
126
+ =&gt; 3..5
130
127
 
131
- (11..19) &amp; (16..23)
132
- =&gt; 16..19</pre>
128
+ (1..5) &amp; (3..10)
129
+ =&gt; 3..5</pre>
133
130
 
134
- <p>Complement, difference operations and subset/superset checking is also available. For full list of methods, check <a href="https://bartpiet.github.io/rangops/">API docs</a>.</p>
131
+ <p>Symmetric difference:</p>
135
132
 
136
- <p>No mapping to arrays nor iterating on elements is performed, so operations on ranges of any size are possible without penalty on speed or memory usage. Ranges delimited with any type of Numerics can be operated.</p>
133
+ <pre>(1..10).difference(5..15)
134
+ =&gt; [1..5, 10..15]
137
135
 
138
- <pre> (1.0..10).union(Rational(20, 4)..Float::INFINITY)
139
- =&gt; 1.0..Infinity</pre>
136
+ (1..10) - (5..15)
137
+ =&gt; [1..5, 10..15]</pre>
140
138
 
141
- <p>It works equally well on string and date ranges, although some operations may be not available if they only make sense for numbers.</p>
139
+ <p>Relative complement:</p>
142
140
 
143
- <p>Library tries to adhere to conventions established in Ruby core and <code>Set</code> module from standard library. It only focuses on extending core Range class; only ranges or elements covered by them can be used as arguments. Due to the properties of Range class, most operations return meaningful results only for ranges of the same type.</p>
141
+ <pre>(1..10).complement(5..15)
142
+ =&gt; 10..15</pre>
143
+
144
+ <p>Checking for subsets/supersets:</p>
145
+
146
+ <pre>(2..3).subset?(0..10)
147
+ =&gt; true
148
+
149
+ (0..10).superset?(2..3)
150
+ =&gt; true</pre>
151
+
152
+ <p>Check <a href="https://bartpiet.github.io/rangops/Rangops/Set.html">API docs</a> for full list of aliases and predicates.</p>
153
+
154
+ <p>There is no mapping to arrays nor iteratons under the hood, just begin/end values comparison - so operations on ranges of any size are possible, with no penalty on speed or memory usage. Ranges delimited with any type of Numerics can be used.</p>
155
+
156
+ <pre>(1.0..10).union(Rational(20, 4)..Float::INFINITY)
157
+ =&gt; 1.0..Infinity</pre>
158
+
159
+ <p>Beginless and endless ranges are supported.</p>
160
+
161
+ <pre>(nil..10).intersection(5..nil)
162
+ =&gt; 5..10
163
+
164
+ (nil..10).union(5..nil)
165
+ =&gt; nil..nil</pre>
166
+
167
+ <p>End exclusion is supported too.</p>
168
+
169
+ <pre>(1...3).intersect?(3..10)
170
+ =&gt; false</pre>
171
+
172
+ <p>It works well on string and date ranges too.</p>
173
+
174
+ <pre>(&#39;2025-01-01&#39;..&#39;2026-12-31&#39;) &amp; (&#39;2026-01-01&#39;..&#39;2027-12-31&#39;)
175
+ =&gt; &#39;2026-01-01&#39;..&#39;2026-12-31&#39;
176
+
177
+ (&#39;a&#39;..&#39;e&#39;) &amp; (&#39;c&#39;..&#39;g&#39;)
178
+ =&gt; &quot;c&quot;..&quot;e&quot;</pre>
179
+
180
+ <p>Operations are supposed to return a <code>Range</code> result, so they only work on arguments delimited with values of the same type. <code>(1..5) &amp; (&#39;c&#39;..&#39;g&#39;)</code> will just return <code>nil</code>.</p>
144
181
 
145
182
  <h2 id="label-License">License<span><a href="#label-License">&para;</a> <a href="#top">&uarr;</a></span></h2>
146
183
 
@@ -183,7 +183,7 @@
183
183
 
184
184
  <div class="method-description">
185
185
  <div class="method-source-code" id="sort_by_boundaries-source">
186
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 175</span>
186
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 176</span>
187
187
  <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">sort_by_boundaries</span>(<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>)
188
188
  <span class="ruby-identifier">ary</span> = [<span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span>]
189
189
  <span class="ruby-identifier">lower</span> = <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">r</span>.<span class="ruby-identifier">begin</span>.<span class="ruby-identifier">nil?</span> } <span class="ruby-operator">||</span> <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:begin</span>).<span class="ruby-identifier">first</span>
@@ -407,7 +407,7 @@
407
407
 
408
408
  <div class="method-description">
409
409
  <div class="method-source-code" id="disjoint-3F-source">
410
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 104</span>
410
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 105</span>
411
411
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">disjoint?</span>(<span class="ruby-identifier">other</span>)
412
412
  <span class="ruby-operator">!</span><span class="ruby-identifier">intersect?</span>(<span class="ruby-identifier">other</span>)
413
413
  <span class="ruby-keyword">end</span></pre>
@@ -439,7 +439,8 @@
439
439
  <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 97</span>
440
440
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">intersect?</span>(<span class="ruby-identifier">other</span>)
441
441
  <span class="ruby-identifier">lower</span>, <span class="ruby-identifier">upper</span> = <span class="ruby-constant">Set</span>.<span class="ruby-identifier">sort_by_boundaries</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">other</span>)
442
- <span class="ruby-identifier">lower</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">upper</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">upper</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">end</span>)
442
+ <span class="ruby-identifier">lower</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">upper</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-operator">||</span>
443
+ (<span class="ruby-identifier">upper</span>.<span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">lower</span>.<span class="ruby-identifier">end</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">lower</span>.<span class="ruby-identifier">exclude_end?</span>)
443
444
  <span class="ruby-keyword">end</span></pre>
444
445
  </div>
445
446
  <p>Checks if 2 ranges have any common elements.</p>
@@ -535,7 +536,7 @@
535
536
 
536
537
  <div class="method-description">
537
538
  <div class="method-source-code" id="proper_subset-3F-source">
538
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 162</span>
539
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 163</span>
539
540
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proper_subset?</span>(<span class="ruby-identifier">other</span>)
540
541
  <span class="ruby-identifier">subset?</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>
541
542
  <span class="ruby-keyword">end</span></pre>
@@ -570,7 +571,7 @@
570
571
 
571
572
  <div class="method-description">
572
573
  <div class="method-source-code" id="proper_superset-3F-source">
573
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 133</span>
574
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 134</span>
574
575
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">proper_superset?</span>(<span class="ruby-identifier">other</span>)
575
576
  <span class="ruby-identifier">superset?</span>(<span class="ruby-identifier">other</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>
576
577
  <span class="ruby-keyword">end</span></pre>
@@ -605,7 +606,7 @@
605
606
 
606
607
  <div class="method-description">
607
608
  <div class="method-source-code" id="subset-3F-source">
608
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 148</span>
609
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 149</span>
609
610
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">subset?</span>(<span class="ruby-identifier">other</span>)
610
611
  <span class="ruby-identifier">other</span>.<span class="ruby-identifier">superset?</span>(<span class="ruby-keyword">self</span>)
611
612
  <span class="ruby-keyword">end</span></pre>
@@ -646,7 +647,7 @@
646
647
 
647
648
  <div class="method-description">
648
649
  <div class="method-source-code" id="superset-3F-source">
649
- <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 119</span>
650
+ <pre><span class="ruby-comment"># File lib/rangops/set.rb, line 120</span>
650
651
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">superset?</span>(<span class="ruby-identifier">other</span>)
651
652
  <span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">begin</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">cover?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">end</span>)
652
653
  <span class="ruby-keyword">end</span></pre>
data/docs/created.rid CHANGED
@@ -1,3 +1,3 @@
1
- Tue, 12 Aug 2025 22:43:46 +0200
2
- README.md Wed, 11 Nov 2020 21:15:00 +0100
3
- lib/rangops/set.rb Tue, 12 Aug 2025 22:43:14 +0200
1
+ Thu, 14 Aug 2025 19:37:19 +0200
2
+ README.md Thu, 14 Aug 2025 19:34:50 +0200
3
+ lib/rangops/set.rb Wed, 13 Aug 2025 22:04:18 +0200
data/docs/index.html CHANGED
@@ -10,7 +10,7 @@
10
10
  <meta name="keywords" content="ruby,documentation,Rangops">
11
11
 
12
12
 
13
- <meta name="description" content="Rangops: Rangops Rangops is a simple Ruby extension library that aims to treat Ranges as sets. It provides methods for elementary set related operations and p">
13
+ <meta name="description" content="Rangops: Rangops Rangops is a tiny Ruby extension library that aims to treat Ranges as sets. Install it with `gem install rangops` or add `gem &quot;rangops&quot;` to y">
14
14
 
15
15
 
16
16
  <script type="text/javascript">
@@ -115,41 +115,78 @@
115
115
 
116
116
  <h1 id="label-Rangops"><a href="Rangops.html"><code>Rangops</code></a><span><a href="#label-Rangops">&para;</a> <a href="#top">&uarr;</a></span></h1>
117
117
 
118
- <p><a href="Rangops.html"><code>Rangops</code></a> is a simple Ruby extension library that aims to treat Ranges as sets.</p>
118
+ <p><a href="Rangops.html"><code>Rangops</code></a> is a tiny Ruby extension library that aims to treat Ranges as sets.</p>
119
119
 
120
- <p>It provides methods for elementary set related operations and predicates.</p>
120
+ <p>Install it with <code>gem install rangops</code> or add <code>gem &quot;rangops&quot;</code> to your Gemfile.</p>
121
121
 
122
- <pre class="ruby"> <span class="ruby-keyword">class</span> <span class="ruby-constant">Range</span>
123
- <span class="ruby-identifier">include</span> <span class="ruby-constant">Rangops</span><span class="ruby-operator">::</span><span class="ruby-constant">Set</span>
124
- <span class="ruby-keyword">end</span>
125
- </pre>
122
+ <p>It patches <code>Range</code> class with methods for basic set related operations and predicates, like:</p>
126
123
 
127
124
  <p>Union:</p>
128
125
 
129
- <pre> (1..5).union(3..10)
130
- =&gt; 1..10
126
+ <pre>(1..5).union(3..10)
127
+ =&gt; 1..10
131
128
 
132
- (11..19) | (16..23)
133
- =&gt; 11..23</pre>
129
+ (1..5) + (3..10)
130
+ =&gt; 1..10</pre>
134
131
 
135
132
  <p>Intersection:</p>
136
133
 
137
- <pre> (1..5).intersection(3..10)
138
- =&gt; 3..5
134
+ <pre>(1..5).intersection(3..10)
135
+ =&gt; 3..5
139
136
 
140
- (11..19) &amp; (16..23)
141
- =&gt; 16..19</pre>
137
+ (1..5) &amp; (3..10)
138
+ =&gt; 3..5</pre>
142
139
 
143
- <p>Complement, difference operations and subset/superset checking is also available. For full list of methods, check <a href="https://bartpiet.github.io/rangops/">API docs</a>.</p>
140
+ <p>Symmetric difference:</p>
144
141
 
145
- <p>No mapping to arrays nor iterating on elements is performed, so operations on ranges of any size are possible without penalty on speed or memory usage. Ranges delimited with any type of Numerics can be operated.</p>
142
+ <pre>(1..10).difference(5..15)
143
+ =&gt; [1..5, 10..15]
146
144
 
147
- <pre> (1.0..10).union(Rational(20, 4)..Float::INFINITY)
148
- =&gt; 1.0..Infinity</pre>
145
+ (1..10) - (5..15)
146
+ =&gt; [1..5, 10..15]</pre>
149
147
 
150
- <p>It works equally well on string and date ranges, although some operations may be not available if they only make sense for numbers.</p>
148
+ <p>Relative complement:</p>
151
149
 
152
- <p>Library tries to adhere to conventions established in Ruby core and <code>Set</code> module from standard library. It only focuses on extending core Range class; only ranges or elements covered by them can be used as arguments. Due to the properties of Range class, most operations return meaningful results only for ranges of the same type.</p>
150
+ <pre>(1..10).complement(5..15)
151
+ =&gt; 10..15</pre>
152
+
153
+ <p>Checking for subsets/supersets:</p>
154
+
155
+ <pre>(2..3).subset?(0..10)
156
+ =&gt; true
157
+
158
+ (0..10).superset?(2..3)
159
+ =&gt; true</pre>
160
+
161
+ <p>Check <a href="https://bartpiet.github.io/rangops/Rangops/Set.html">API docs</a> for full list of aliases and predicates.</p>
162
+
163
+ <p>There is no mapping to arrays nor iteratons under the hood, just begin/end values comparison - so operations on ranges of any size are possible, with no penalty on speed or memory usage. Ranges delimited with any type of Numerics can be used.</p>
164
+
165
+ <pre>(1.0..10).union(Rational(20, 4)..Float::INFINITY)
166
+ =&gt; 1.0..Infinity</pre>
167
+
168
+ <p>Beginless and endless ranges are supported.</p>
169
+
170
+ <pre>(nil..10).intersection(5..nil)
171
+ =&gt; 5..10
172
+
173
+ (nil..10).union(5..nil)
174
+ =&gt; nil..nil</pre>
175
+
176
+ <p>End exclusion is supported too.</p>
177
+
178
+ <pre>(1...3).intersect?(3..10)
179
+ =&gt; false</pre>
180
+
181
+ <p>It works well on string and date ranges too.</p>
182
+
183
+ <pre>(&#39;2025-01-01&#39;..&#39;2026-12-31&#39;) &amp; (&#39;2026-01-01&#39;..&#39;2027-12-31&#39;)
184
+ =&gt; &#39;2026-01-01&#39;..&#39;2026-12-31&#39;
185
+
186
+ (&#39;a&#39;..&#39;e&#39;) &amp; (&#39;c&#39;..&#39;g&#39;)
187
+ =&gt; &quot;c&quot;..&quot;e&quot;</pre>
188
+
189
+ <p>Operations are supposed to return a <code>Range</code> result, so they only work on arguments delimited with values of the same type. <code>(1..5) &amp; (&#39;c&#39;..&#39;g&#39;)</code> will just return <code>nil</code>.</p>
153
190
 
154
191
  <h2 id="label-License">License<span><a href="#label-License">&para;</a> <a href="#top">&uarr;</a></span></h2>
155
192
 
@@ -1 +1 @@
1
- var search_data = {"index":{"searchIndex":["rangops","set","&()","+()","-()","complement()","contains?()","difference()","disjoint?()","intersect?()","intersection()","is_contained_by?()","proper_subset?()","proper_superset?()","sort_by_boundaries()","subset?()","superset?()","union()","|()","readme"],"longSearchIndex":["rangops","rangops::set","rangops::set#&()","rangops::set#+()","rangops::set#-()","rangops::set#complement()","rangops::set#contains?()","rangops::set#difference()","rangops::set#disjoint?()","rangops::set#intersect?()","rangops::set#intersection()","rangops::set#is_contained_by?()","rangops::set#proper_subset?()","rangops::set#proper_superset?()","rangops::set::sort_by_boundaries()","rangops::set#subset?()","rangops::set#superset?()","rangops::set#union()","rangops::set#|()",""],"info":[["Rangops","","Rangops.html","",""],["Rangops::Set","","Rangops/Set.html","","<p>Module defining basic set operations that can be performed\non ranges.\n<p>union\n<p>intersection\n"],["&","Rangops::Set","Rangops/Set.html#method-i-26","(other)",""],["+","Rangops::Set","Rangops/Set.html#method-i-2B","(other)",""],["-","Rangops::Set","Rangops/Set.html#method-i-2D","(other)",""],["complement","Rangops::Set","Rangops/Set.html#method-i-complement","(other)","<p>Relative complement of 2 ranges. Returns a range covering\nelements from <code>other</code> that are not covered by ...\n"],["contains?","Rangops::Set","Rangops/Set.html#method-i-contains-3F","(other)",""],["difference","Rangops::Set","Rangops/Set.html#method-i-difference","(other)","<p>Symmetric difference of 2 ranges. Returns ranges covering\nelements of both operands, excluding elements ...\n"],["disjoint?","Rangops::Set","Rangops/Set.html#method-i-disjoint-3F","(other)","<p>Opposite of ‘intersect?.\n"],["intersect?","Rangops::Set","Rangops/Set.html#method-i-intersect-3F","(other)","<p>Checks if 2 ranges have any common elements.\n\n<pre> (1..10).intersect?(8..15)\n =&gt; true\n\n (1..10).intersect?(11..15) ...</pre>\n"],["intersection","Rangops::Set","Rangops/Set.html#method-i-intersection","(other)","<p>Intersection of 2 ranges. Returns a range covering elements\ncommon to both ranges. Returns <code>nil</code> if ranges ...\n"],["is_contained_by?","Rangops::Set","Rangops/Set.html#method-i-is_contained_by-3F","(other)",""],["proper_subset?","Rangops::Set","Rangops/Set.html#method-i-proper_subset-3F","(other)","<p>Checks if <code>self</code> is proper subset of <code>other</code>,\ni.e. is subset and has elements not present\nin <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">proper_subset?</span>(<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">12</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["proper_superset?","Rangops::Set","Rangops/Set.html#method-i-proper_superset-3F","(other)","<p>Checks if <code>self</code> is proper superset of <code>other</code>,\ni.e. is superset and has elements not present\nin <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">proper_superset?</span>(<span class=\"ruby-value\">2</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["sort_by_boundaries","Rangops::Set","Rangops/Set.html#method-c-sort_by_boundaries","(a, b)","<p>Determine which range has lower begin, and which one higher end.\n"],["subset?","Rangops::Set","Rangops/Set.html#method-i-subset-3F","(other)","<p>Checks if <code>self</code> is subset of <code>other</code>, i.e. all\nelements of <code>self</code> fit within <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">subset?</span>(<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">12</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["superset?","Rangops::Set","Rangops/Set.html#method-i-superset-3F","(other)","<p>Checks if <code>self</code> is superset of <code>other</code>, i.e. all\nelements of <code>other</code> fit within <code>self</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">superset?</span>(<span class=\"ruby-value\">2</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["union","Rangops::Set","Rangops/Set.html#method-i-union","(other)","<p>Union of 2 ranges. Returns a range covering sum of all elements\nbelonging to both ranges. Returns <code>nil</code> ...\n"],["|","Rangops::Set","Rangops/Set.html#method-i-7C","(other)",""],["README","","README_md.html","","<p>Rangops\n<p>Rangops is a simple Ruby extension library that aims to treat Ranges as sets.\n<p>It provides methods …\n"]]}}
1
+ var search_data = {"index":{"searchIndex":["rangops","set","&()","+()","-()","complement()","contains?()","difference()","disjoint?()","intersect?()","intersection()","is_contained_by?()","proper_subset?()","proper_superset?()","sort_by_boundaries()","subset?()","superset?()","union()","|()","readme"],"longSearchIndex":["rangops","rangops::set","rangops::set#&()","rangops::set#+()","rangops::set#-()","rangops::set#complement()","rangops::set#contains?()","rangops::set#difference()","rangops::set#disjoint?()","rangops::set#intersect?()","rangops::set#intersection()","rangops::set#is_contained_by?()","rangops::set#proper_subset?()","rangops::set#proper_superset?()","rangops::set::sort_by_boundaries()","rangops::set#subset?()","rangops::set#superset?()","rangops::set#union()","rangops::set#|()",""],"info":[["Rangops","","Rangops.html","",""],["Rangops::Set","","Rangops/Set.html","","<p>Module defining basic set operations that can be performed\non ranges.\n<p>union\n<p>intersection\n"],["&","Rangops::Set","Rangops/Set.html#method-i-26","(other)",""],["+","Rangops::Set","Rangops/Set.html#method-i-2B","(other)",""],["-","Rangops::Set","Rangops/Set.html#method-i-2D","(other)",""],["complement","Rangops::Set","Rangops/Set.html#method-i-complement","(other)","<p>Relative complement of 2 ranges. Returns a range covering\nelements from <code>other</code> that are not covered by ...\n"],["contains?","Rangops::Set","Rangops/Set.html#method-i-contains-3F","(other)",""],["difference","Rangops::Set","Rangops/Set.html#method-i-difference","(other)","<p>Symmetric difference of 2 ranges. Returns ranges covering\nelements of both operands, excluding elements ...\n"],["disjoint?","Rangops::Set","Rangops/Set.html#method-i-disjoint-3F","(other)","<p>Opposite of ‘intersect?.\n"],["intersect?","Rangops::Set","Rangops/Set.html#method-i-intersect-3F","(other)","<p>Checks if 2 ranges have any common elements.\n\n<pre> (1..10).intersect?(8..15)\n =&gt; true\n\n (1..10).intersect?(11..15) ...</pre>\n"],["intersection","Rangops::Set","Rangops/Set.html#method-i-intersection","(other)","<p>Intersection of 2 ranges. Returns a range covering elements\ncommon to both ranges. Returns <code>nil</code> if ranges ...\n"],["is_contained_by?","Rangops::Set","Rangops/Set.html#method-i-is_contained_by-3F","(other)",""],["proper_subset?","Rangops::Set","Rangops/Set.html#method-i-proper_subset-3F","(other)","<p>Checks if <code>self</code> is proper subset of <code>other</code>,\ni.e. is subset and has elements not present\nin <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">proper_subset?</span>(<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">12</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["proper_superset?","Rangops::Set","Rangops/Set.html#method-i-proper_superset-3F","(other)","<p>Checks if <code>self</code> is proper superset of <code>other</code>,\ni.e. is superset and has elements not present\nin <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">proper_superset?</span>(<span class=\"ruby-value\">2</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["sort_by_boundaries","Rangops::Set","Rangops/Set.html#method-c-sort_by_boundaries","(a, b)","<p>Determine which range has lower begin, and which one higher end.\n"],["subset?","Rangops::Set","Rangops/Set.html#method-i-subset-3F","(other)","<p>Checks if <code>self</code> is subset of <code>other</code>, i.e. all\nelements of <code>self</code> fit within <code>other</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">subset?</span>(<span class=\"ruby-value\">0</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">12</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["superset?","Rangops::Set","Rangops/Set.html#method-i-superset-3F","(other)","<p>Checks if <code>self</code> is superset of <code>other</code>, i.e. all\nelements of <code>other</code> fit within <code>self</code>.\n\n<pre class=\"ruby\">(<span class=\"ruby-value\">1</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">10</span>).<span class=\"ruby-identifier\">superset?</span>(<span class=\"ruby-value\">2</span><span class=\"ruby-operator\">..</span><span class=\"ruby-value\">5</span>) <span class=\"ruby-operator\">...</span>\n</pre>\n"],["union","Rangops::Set","Rangops/Set.html#method-i-union","(other)","<p>Union of 2 ranges. Returns a range covering sum of all elements\nbelonging to both ranges. Returns <code>nil</code> ...\n"],["|","Rangops::Set","Rangops/Set.html#method-i-7C","(other)",""],["README","","README_md.html","","<p>Rangops\n<p>Rangops is a tiny Ruby extension library that aims to treat Ranges as sets.\n<p>Install it with <code>gem</code> …\n"]]}}
Binary file
@@ -10,7 +10,7 @@
10
10
  <meta name="keywords" content="ruby,documentation,Table of Contents - Rangops">
11
11
 
12
12
 
13
- <meta name="description" content="Table of Contents - Rangops: Rangops Rangops is a simple Ruby extension library that aims to treat Ranges as sets. It provides methods for elementary set related operations and p">
13
+ <meta name="description" content="Table of Contents - Rangops: Rangops Rangops is a tiny Ruby extension library that aims to treat Ranges as sets. Install it with `gem install rangops` or add `gem &quot;rangops&quot;` to y">
14
14
 
15
15
 
16
16
  <script type="text/javascript">
data/lib/rangops/set.rb CHANGED
@@ -96,7 +96,8 @@ module Rangops
96
96
  # => false
97
97
  def intersect?(other)
98
98
  lower, upper = Set.sort_by_boundaries(self, other)
99
- lower.cover?(upper.begin) || upper.cover?(lower.end)
99
+ lower.cover?(upper.begin) ||
100
+ (upper.cover?(lower.end) && !lower.exclude_end?)
100
101
  end
101
102
 
102
103
 
@@ -1,3 +1,3 @@
1
1
  module Rangops
2
- VERSION = "1.0.0.beta1"
2
+ VERSION = "1.0.0"
3
3
  end
data/rangops.gemspec CHANGED
@@ -13,6 +13,13 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://bartpiet.github.io/rangops/"
14
14
  spec.license = "MIT"
15
15
 
16
+ spec.metadata = {
17
+ "bug_tracker_uri" => "https://github.com/bartpiet/rangops/issues",
18
+ "documentation_uri" => "https://bartpiet.github.io/rangops/",
19
+ "homepage_uri" => "https://github.com/bartpiet/rangops",
20
+ "source_code_uri" => "https://github.com/bartpiet/rangops",
21
+ }
22
+
16
23
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
24
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
25
  if spec.respond_to?(:metadata)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rangops
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Pietraszko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-13 00:00:00.000000000 Z
10
+ date: 2025-08-14 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler
@@ -120,6 +120,10 @@ homepage: https://bartpiet.github.io/rangops/
120
120
  licenses:
121
121
  - MIT
122
122
  metadata:
123
+ bug_tracker_uri: https://github.com/bartpiet/rangops/issues
124
+ documentation_uri: https://bartpiet.github.io/rangops/
125
+ homepage_uri: https://github.com/bartpiet/rangops
126
+ source_code_uri: https://github.com/bartpiet/rangops
123
127
  allowed_push_host: https://rubygems.org
124
128
  rdoc_options: []
125
129
  require_paths: