epitools 0.5.94 → 0.5.95

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
  SHA1:
3
- metadata.gz: 5d01371fe8e7b1abdb22e2f34fa33972aa7b58ef
4
- data.tar.gz: cd1b1caf85ea32aeec4ebcc4caf2e0dae2459c59
3
+ metadata.gz: '09ec6a706e691b75f78ba25055e8c79b2beb3944'
4
+ data.tar.gz: 4ebd4dad0730f0ff7434583261d45e50a7427320
5
5
  SHA512:
6
- metadata.gz: d45da94f1c6618763d097c779df99d4c5144e2678d6a2da89a76d3f26a535146057ada16f2c2e179a2a3ccdf8968609d77918fb212cc487b6fa26bce60d787f9
7
- data.tar.gz: 419827e53335a23f21b69988b255811aae29f762c2490bfd8b7a793a2e29cf5cfc9adf8257f944b7a672da92e53456effbbb0373d754ea8d3345b320e88131a9
6
+ metadata.gz: 2c43291944e5e7c7e1d409e9df8e33d30d9ff02cfcc1d29b478f231476b8c1d4fa72edae5219f63bad5bbd7da4e4d2aee50794b1b3b1977fbfae3bcc10f0db71
7
+ data.tar.gz: 78595a9e4d78eea0f8b626827dd14dddd4a4c29f4c6b286ca50def65aeeaa778f51fdbb26713ec80f3d908239c70c4d245602fac969757a6ac69d91e83bbf229
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.94
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
@@ -831,10 +831,24 @@ describe Range do
831
831
  end
832
832
 
833
833
  it "does | and &" do
834
- a = (1..10)
835
- b = (5...21)
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.94
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-15 00:00:00.000000000 Z
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec