epitools 0.5.94 → 0.5.95
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/VERSION +1 -1
- data/lib/epitools/core_ext/range.rb +21 -3
- data/spec/core_ext_spec.rb +18 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09ec6a706e691b75f78ba25055e8c79b2beb3944'
|
4
|
+
data.tar.gz: 4ebd4dad0730f0ff7434583261d45e50a7427320
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c43291944e5e7c7e1d409e9df8e33d30d9ff02cfcc1d29b478f231476b8c1d4fa72edae5219f63bad5bbd7da4e4d2aee50794b1b3b1977fbfae3bcc10f0db71
|
7
|
+
data.tar.gz: 78595a9e4d78eea0f8b626827dd14dddd4a4c29f4c6b286ca50def65aeeaa778f51fdbb26713ec80f3d908239c70c4d245602fac969757a6ac69d91e83bbf229
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.95
|
@@ -23,14 +23,32 @@ class Range
|
|
23
23
|
|
24
24
|
(mins.max..maxes.min)
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
#
|
28
28
|
# Return a new range which is the union of the two ranges
|
29
29
|
#
|
30
30
|
def |(other)
|
31
31
|
mins, maxes = minmax.zip(other.minmax)
|
32
|
-
|
33
32
|
(mins.min..maxes.max)
|
34
33
|
end
|
35
|
-
|
34
|
+
|
35
|
+
#
|
36
|
+
# Merge two ranges
|
37
|
+
#
|
38
|
+
def merge(other)
|
39
|
+
if self.overlaps?(other)
|
40
|
+
[self | other]
|
41
|
+
else
|
42
|
+
[self, other]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Test if this range overlaps the other
|
48
|
+
#
|
49
|
+
def overlaps?(other)
|
50
|
+
# overlap == start < finish' AND start' < finish
|
51
|
+
self.first <= other.last and other.first <= self.last
|
52
|
+
end
|
53
|
+
|
36
54
|
end
|
data/spec/core_ext_spec.rb
CHANGED
@@ -831,10 +831,24 @@ describe Range do
|
|
831
831
|
end
|
832
832
|
|
833
833
|
it "does | and &" do
|
834
|
-
a =
|
835
|
-
b =
|
836
|
-
a & b == (5..10)
|
837
|
-
a | b == (1..20)
|
834
|
+
a = 1..10
|
835
|
+
b = 5...21
|
836
|
+
(a & b).should == (5..10)
|
837
|
+
(a | b).should == (1..20)
|
838
|
+
|
839
|
+
c = 1..2
|
840
|
+
d = 5..6
|
841
|
+
|
842
|
+
(c | d).should == (c.first..d.last)
|
843
|
+
a.merge(b).should == [a.first..b.last-1]
|
844
|
+
c.merge(d).should == [c, d]
|
845
|
+
end
|
846
|
+
|
847
|
+
it "overlaps?" do
|
848
|
+
(1..10).overlaps?(20..30).should == false
|
849
|
+
(1..10).overlaps?(10..30).should == true
|
850
|
+
(10..30).overlaps?(1..10).should == true
|
851
|
+
(10..30).overlaps?(1..15).should == true
|
838
852
|
end
|
839
853
|
|
840
854
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.95
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|