aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlban Peignier2017-12-17 15:31:47 +0100
committerAlban Peignier2018-01-05 10:23:29 +0100
commitf90488de1f657abf24026231485c87d3e42ee11d (patch)
tree5ee9ebe90dbd709dc2fb89aa38559b123453ccf0 /lib
parente7e27a0d80938220664f7cae60d2e6452b74ec69 (diff)
downloadchouette-core-f90488de1f657abf24026231485c87d3e42ee11d.tar.bz2
Move (clean) period split logic into Range#remove. Refs #5299
Diffstat (limited to 'lib')
-rw-r--r--lib/range_ext.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/range_ext.rb b/lib/range_ext.rb
index f1df5e70d..a6a3bfc5d 100644
--- a/lib/range_ext.rb
+++ b/lib/range_ext.rb
@@ -5,4 +5,16 @@ class Range
[self.min, other.min].max..[self.max, other.max].min
end
alias_method :&, :intersection
+
+ def remove(other)
+ return self if (self.max < other.min or other.max < self.min)
+
+ [].tap do |remaining|
+ remaining << (self.min..other.min-1) if self.min < other.min
+ remaining << (other.max+1..self.max) if other.max < self.max
+ remaining.compact!
+ end
+ end
+ alias_method :-, :remove
+
end