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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dce52f266fe1dd26eaccbac184ee8c1ed5cc160322d92ded5471fb3efda0ee4
4
- data.tar.gz: d001904ffda1cf620638042afd72da56b1b810b457df6227bd1d9fb3e7986a4e
3
+ metadata.gz: 770406d2ee94a20090941404e6bfde0d3a516554be093ae1eb09aa0f85b19688
4
+ data.tar.gz: b1d0e13fb9cd75e2d897d8f2b7e5b9a54ca5c543fcb16c12fb9e35a4cd8717ac
5
5
  SHA512:
6
- metadata.gz: 36fb852c41b4802589fd950b3beadbccad986e8e5e31da5993acfd11e19339e7034eba7099bcd36903e74e592c397e4501682cae47f482c74ad9d86d136b25cc
7
- data.tar.gz: 0a763c262c12b7b45fc0c47f50bbbee929a19c2399e9e9725f70d49222bcdf1d0860c8b1162d8a04e2f2b992e42287b2deacbbf6dbf9c051f98c3fad04ec0488
6
+ metadata.gz: a0fbb1372f1ccdd9967142fa2ad0e13da8859e3c796c594ea2d53c61646ec98d21a395a0f81f1cc41486fc4b408161ceb2ed45c5fe97aeca701e4688892fd979
7
+ data.tar.gz: e41cfe73cc1024d9899a1722215dfbfc2ab0b74bd446e279b1c7c791df162e7c6068332c8ebb01a0594b04d71c7322890fb68c4be148aff46b8a1637a5420717
@@ -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/UselessComparison:
181
- Description: 'Checks for comparison of something with itself.'
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/Tab:
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
@@ -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? ? other.end : other.end + (other.end.is_a?(Float) ? Float::EPSILON : 1)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class MultiRange
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
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.2.0
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-16 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler