multi_range 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/lib/multi_range.rb +13 -4
- data/lib/multi_range/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 770406d2ee94a20090941404e6bfde0d3a516554be093ae1eb09aa0f85b19688
|
4
|
+
data.tar.gz: b1d0e13fb9cd75e2d897d8f2b7e5b9a54ca5c543fcb16c12fb9e35a4cd8717ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0fbb1372f1ccdd9967142fa2ad0e13da8859e3c796c594ea2d53c61646ec98d21a395a0f81f1cc41486fc4b408161ceb2ed45c5fe97aeca701e4688892fd979
|
7
|
+
data.tar.gz: e41cfe73cc1024d9899a1722215dfbfc2ab0b74bd446e279b1c7c791df162e7c6068332c8ebb01a0594b04d71c7322890fb68c4be148aff46b8a1637a5420717
|
data/.rubocop.yml
CHANGED
@@ -177,8 +177,8 @@ Lint/UselessAssignment:
|
|
177
177
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
|
178
178
|
Enabled: true
|
179
179
|
|
180
|
-
Lint/
|
181
|
-
Description: '
|
180
|
+
Lint/BinaryOperatorWithIdenticalOperands:
|
181
|
+
Description: 'This cop checks for places where binary operator has identical operands.'
|
182
182
|
Enabled: true
|
183
183
|
|
184
184
|
Lint/UselessElseWithoutRescue:
|
@@ -1064,7 +1064,7 @@ Style/SymbolProc:
|
|
1064
1064
|
Description: 'Use symbols as procs instead of blocks when possible.'
|
1065
1065
|
Enabled: false # wants to support ruby 1.8
|
1066
1066
|
|
1067
|
-
Layout/
|
1067
|
+
Layout/IndentationStyle:
|
1068
1068
|
Description: 'No hard tabs.'
|
1069
1069
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation'
|
1070
1070
|
Enabled: true
|
data/lib/multi_range.rb
CHANGED
@@ -26,7 +26,7 @@ class MultiRange
|
|
26
26
|
@is_float = @ranges.any?{|range| range.begin.is_a?(Float) || range.end.is_a?(Float) }
|
27
27
|
end
|
28
28
|
|
29
|
-
def merge_overlaps
|
29
|
+
def merge_overlaps(merge_same_value = true)
|
30
30
|
return MultiRange.new([]) if @ranges.size == 0
|
31
31
|
|
32
32
|
new_ranges = []
|
@@ -36,7 +36,7 @@ class MultiRange
|
|
36
36
|
next current_range = range if current_range == nil
|
37
37
|
next if range.end <= current_range.end
|
38
38
|
|
39
|
-
if can_combine?(current_range, range)
|
39
|
+
if can_combine?(current_range, range, merge_same_value)
|
40
40
|
current_range = range.exclude_end? ? current_range.begin...range.end : current_range.begin..range.end
|
41
41
|
else
|
42
42
|
new_ranges << current_range
|
@@ -68,7 +68,11 @@ class MultiRange
|
|
68
68
|
|
69
69
|
sub_range1 = range.begin...other.begin
|
70
70
|
|
71
|
-
sub_range2_begin = other.exclude_end?
|
71
|
+
sub_range2_begin = if other.exclude_end?
|
72
|
+
other.end
|
73
|
+
else
|
74
|
+
other.end + (other.end.is_a?(Float) ? Float::EPSILON : 1)
|
75
|
+
end
|
72
76
|
sub_range2 = range.exclude_end? ? sub_range2_begin...range.end : sub_range2_begin..range.end
|
73
77
|
|
74
78
|
sub_ranges = []
|
@@ -144,10 +148,15 @@ class MultiRange
|
|
144
148
|
return range.max if range
|
145
149
|
end
|
146
150
|
|
151
|
+
def contain_overlaps?
|
152
|
+
merge_overlaps(false).ranges != ranges
|
153
|
+
end
|
154
|
+
|
147
155
|
private
|
148
156
|
|
149
157
|
# make sure that range1.begin <= range2.begin
|
150
|
-
def can_combine?(range1, range2)
|
158
|
+
def can_combine?(range1, range2, merge_same_value)
|
159
|
+
return merge_same_value if range1.end == range2.begin and range1.exclude_end?
|
151
160
|
return range1.end >= range2.begin if @is_float
|
152
161
|
return range1.end + 1 >= range2.begin
|
153
162
|
end
|
data/lib/multi_range/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khiav reoy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|