multi_range 2.1.1 → 2.2.1

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: 2b5352f51a43f950f0900f8964dfb2f955aa2c23d4845d2535a1420bbb829905
4
- data.tar.gz: 0cc8ee461ef7a33f0c18c596676e4b57102dc73ddb9f9c9f4c1ce00838e709bf
3
+ metadata.gz: 2d67638eab33c3a377488c4fb32c0e33f8385eab6d743d3f37f7476f20f94b97
4
+ data.tar.gz: 198971530fc824d45690f92b4c45013a8bd58ddb204e9a84a2971bdda20ed1fb
5
5
  SHA512:
6
- metadata.gz: 66d4a320e3b9d2461aa59f1052e39ff7984af7c22aefa202997c0dedb20fba7f2ea64fabc4f245d993ab23afb96772edf2452db0393fb5689b11cc14cf1316a8
7
- data.tar.gz: 5b395dfa8e9dde8639fde7c83bcabe69de2b655a49e3148b933275c3eb8af590adf7af5f8335e841a9c6cab9c625a2e58a4d4224baff8909e3c78b9397e4c5d4
6
+ metadata.gz: 752b8eff047ed5b7dded92afbdf612fc0e2f63b119fba141421d07e2983d8fd9aa79914cb60e890414362d6e84497b2737145dc18166299f772a74e74ffb231d
7
+ data.tar.gz: 48e47778eaf9066be35983239fdf073e011010ba2555d1a2b4a48d4c507db7e9d419a64503f469a54e16363be61e5e300977f364d02c91f12d56ad3028ef315f
@@ -20,8 +20,7 @@ jobs:
20
20
  fail-fast: false
21
21
  matrix:
22
22
  ruby:
23
- - 2.0
24
- - 2.2
23
+ - 2.3
25
24
  - 2.6
26
25
  - 2.7
27
26
  gemfile:
data/CHANGELOG.md CHANGED
@@ -1,44 +1,52 @@
1
- ## Change Log
2
-
3
- ### [v2.1.0](https://github.com/khiav223577/multi_range/compare/v2.0.0...v2.1.0) 2021/03/17
4
- - [#24](https://github.com/khiav223577/multi_range/pull/24) Avoid empty sub ranges (@GerritSe)
5
- - [#25](https://github.com/khiav223577/multi_range/pull/25) Do not publish code coverage for PRs from forks (@khiav223577)
6
- - [#22](https://github.com/khiav223577/multi_range/pull/22) Migrating from Travis CI to GitHub Actions (@khiav223577)
7
- - [#21](https://github.com/khiav223577/multi_range/pull/21) Fix: test files should not be included in coverage (@khiav223577)
8
-
9
- ### [v2.0.0](https://github.com/khiav223577/multi_range/compare/v1.3.0...v2.0.0) 2020/11/19
10
- - [#19](https://github.com/khiav223577/multi_range/pull/19) Implement intersection (@chrisnankervis)
11
- - [#20](https://github.com/khiav223577/multi_range/pull/20) Drop support for Ruby 1.8 and 1.9 (@khiav223577)
12
- - [#17](https://github.com/khiav223577/multi_range/pull/17) Refactoring - increase MAINTAINABILITY (@khiav223577)
13
-
14
- ### [v1.3.0](https://github.com/khiav223577/multi_range/compare/v1.2.0...v1.3.0) 2020/10/20
15
- - [#16](https://github.com/khiav223577/multi_range/pull/16) Implement contain_overlaps? method (@khiav223577)
16
-
17
- ### [v1.2.0](https://github.com/khiav223577/multi_range/compare/v1.1.0...v1.2.0) 2020/10/16
18
- - [#15](https://github.com/khiav223577/multi_range/pull/15) Add test cases to test union float ranges (@khiav223577)
19
- - [#14](https://github.com/khiav223577/multi_range/pull/14) Support float ranges (@khiav223577)
20
-
21
- ### [v1.1.0](https://github.com/khiav223577/multi_range/compare/v1.0.0...v1.1.0) 2020/10/15
22
- - [#13](https://github.com/khiav223577/multi_range/pull/13) Rename flatten => merge_overlaps (@khiav223577)
23
-
24
- ### [v1.0.0](https://github.com/khiav223577/multi_range/compare/v0.0.4...v1.0.0) 2020/10/15
25
- - [#12](https://github.com/khiav223577/multi_range/pull/12) Implement #overlaps? (@khiav223577)
26
- - [#11](https://github.com/khiav223577/multi_range/pull/11) Support difference other multi_range object (@khiav223577)
27
- - [#10](https://github.com/khiav223577/multi_range/pull/10) Add frozen_string_literal (@khiav223577)
28
- - [#9](https://github.com/khiav223577/multi_range/pull/9) Implement range union (@khiav223577)
29
- - [#8](https://github.com/khiav223577/multi_range/pull/8) Support initializing a MultiRange object with unsorted ranges (@khiav223577)
30
-
31
- ### [v0.0.4](https://github.com/khiav223577/multi_range/compare/v0.0.3...v0.0.4) 2020/03/26
32
- - [#7](https://github.com/khiav223577/multi_range/pull/7) Add flatten method (@khiav223577)
33
-
34
- ### [v0.0.3](https://github.com/khiav223577/multi_range/compare/v0.0.2...v0.0.3) 2020/03/02
35
- - [#6](https://github.com/khiav223577/multi_range/pull/6) freeze internal ranges variable (@khiav223577)
36
- - [#5](https://github.com/khiav223577/multi_range/pull/5) Add min, max, to_a method (@khiav223577)
37
-
38
- ### [v0.0.2](https://github.com/khiav223577/multi_range/compare/v0.0.1...v0.0.2) 2020/03/02
39
- - [#4](https://github.com/khiav223577/multi_range/pull/4) Add each, map, index_with methods (@khiav223577)
40
- - [#3](https://github.com/khiav223577/multi_range/pull/3) Support passing integer as range (@khiav223577)
41
-
42
- ### v0.0.1 2020/03/01
43
- - [#2](https://github.com/khiav223577/multi_range/pull/2) Support Ruby 1.8.7 (@khiav223577)
44
- - [#1](https://github.com/khiav223577/multi_range/pull/1) Implement MultiRange (@khiav223577)
1
+ ## Change Log
2
+
3
+ ### [v2.2.0](https://github.com/khiav223577/multi_range/compare/v1.3.2...v2.2.0) 2023/10/21
4
+ - [#34](https://github.com/khiav223577/multi_range/pull/34) Fix: wrong empty range check which causes some differences to be dropped (@khiav223577)
5
+ - [#33](https://github.com/khiav223577/multi_range/pull/33) Fix: result should not be empty when intersection with inclusive range with one element (@khiav223577)
6
+ - [#32](https://github.com/khiav223577/multi_range/pull/32) Drop the support of ruby 2.2 (@khiav223577)
7
+
8
+ ### [v2.1.1](https://github.com/khiav223577/multi_range/compare/v2.1.0...v2.1.1) 2021/08/07
9
+ - [#26](https://github.com/khiav223577/multi_range/pull/26) Fix: unexpected float value when sample an one-element range (@khiav223577)
10
+
11
+ ### [v2.1.0](https://github.com/khiav223577/multi_range/compare/v2.0.0...v2.1.0) 2021/03/17
12
+ - [#24](https://github.com/khiav223577/multi_range/pull/24) Avoid empty sub ranges (@GerritSe)
13
+ - [#25](https://github.com/khiav223577/multi_range/pull/25) Do not publish code coverage for PRs from forks (@khiav223577)
14
+ - [#22](https://github.com/khiav223577/multi_range/pull/22) Migrating from Travis CI to GitHub Actions (@khiav223577)
15
+ - [#21](https://github.com/khiav223577/multi_range/pull/21) Fix: test files should not be included in coverage (@khiav223577)
16
+
17
+ ### [v2.0.0](https://github.com/khiav223577/multi_range/compare/v1.3.0...v2.0.0) 2020/11/19
18
+ - [#19](https://github.com/khiav223577/multi_range/pull/19) Implement intersection (@chrisnankervis)
19
+ - [#20](https://github.com/khiav223577/multi_range/pull/20) Drop support for Ruby 1.8 and 1.9 (@khiav223577)
20
+ - [#17](https://github.com/khiav223577/multi_range/pull/17) Refactoring - increase MAINTAINABILITY (@khiav223577)
21
+
22
+ ### [v1.3.0](https://github.com/khiav223577/multi_range/compare/v1.2.0...v1.3.0) 2020/10/20
23
+ - [#16](https://github.com/khiav223577/multi_range/pull/16) Implement contain_overlaps? method (@khiav223577)
24
+
25
+ ### [v1.2.0](https://github.com/khiav223577/multi_range/compare/v1.1.0...v1.2.0) 2020/10/16
26
+ - [#15](https://github.com/khiav223577/multi_range/pull/15) Add test cases to test union float ranges (@khiav223577)
27
+ - [#14](https://github.com/khiav223577/multi_range/pull/14) Support float ranges (@khiav223577)
28
+
29
+ ### [v1.1.0](https://github.com/khiav223577/multi_range/compare/v1.0.0...v1.1.0) 2020/10/15
30
+ - [#13](https://github.com/khiav223577/multi_range/pull/13) Rename flatten => merge_overlaps (@khiav223577)
31
+
32
+ ### [v1.0.0](https://github.com/khiav223577/multi_range/compare/v0.0.4...v1.0.0) 2020/10/15
33
+ - [#12](https://github.com/khiav223577/multi_range/pull/12) Implement #overlaps? (@khiav223577)
34
+ - [#11](https://github.com/khiav223577/multi_range/pull/11) Support difference other multi_range object (@khiav223577)
35
+ - [#10](https://github.com/khiav223577/multi_range/pull/10) Add frozen_string_literal (@khiav223577)
36
+ - [#9](https://github.com/khiav223577/multi_range/pull/9) Implement range union (@khiav223577)
37
+ - [#8](https://github.com/khiav223577/multi_range/pull/8) Support initializing a MultiRange object with unsorted ranges (@khiav223577)
38
+
39
+ ### [v0.0.4](https://github.com/khiav223577/multi_range/compare/v0.0.3...v0.0.4) 2020/03/26
40
+ - [#7](https://github.com/khiav223577/multi_range/pull/7) Add flatten method (@khiav223577)
41
+
42
+ ### [v0.0.3](https://github.com/khiav223577/multi_range/compare/v0.0.2...v0.0.3) 2020/03/02
43
+ - [#6](https://github.com/khiav223577/multi_range/pull/6) freeze internal ranges variable (@khiav223577)
44
+ - [#5](https://github.com/khiav223577/multi_range/pull/5) Add min, max, to_a method (@khiav223577)
45
+
46
+ ### [v0.0.2](https://github.com/khiav223577/multi_range/compare/v0.0.1...v0.0.2) 2020/03/02
47
+ - [#4](https://github.com/khiav223577/multi_range/pull/4) Add each, map, index_with methods (@khiav223577)
48
+ - [#3](https://github.com/khiav223577/multi_range/pull/3) Support passing integer as range (@khiav223577)
49
+
50
+ ### v0.0.1 2020/03/01
51
+ - [#2](https://github.com/khiav223577/multi_range/pull/2) Support Ruby 1.8.7 (@khiav223577)
52
+ - [#1](https://github.com/khiav223577/multi_range/pull/1) Implement MultiRange (@khiav223577)
data/README.md CHANGED
@@ -8,9 +8,9 @@
8
8
 
9
9
  ## Supports
10
10
 
11
- - Ruby 2.0 ~ 2.7
12
-
13
- For Ruby 1.8.x and 1.9.x, please use multi_range < 2.
11
+ - Ruby 2.3 ~ 2.7
12
+ - For Ruby 1.8.x and 1.9.x, please use multi_range < v2.0.0
13
+ - For Ruby 2.0 ~ 2.2, please use multi_range < v2.2.0
14
14
 
15
15
  ## Installation
16
16
 
data/gemfiles/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in rails_or.gemspec
4
4
 
5
5
  group :test do
6
- gem 'simplecov', '< 0.18'
6
+ gem 'simplecov', '< 0.18'
7
7
  end
8
8
 
9
9
  gemspec :path => '../'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class MultiRange
4
- VERSION = '2.1.1'
4
+ VERSION = '2.2.1'
5
5
  end
data/lib/multi_range.rb CHANGED
@@ -62,7 +62,9 @@ class MultiRange
62
62
  other_ranges = MultiRange.new(other).merge_overlaps.ranges
63
63
  tree = IntervalTree::Tree.new(other_ranges)
64
64
  intersected_ranges = merge_overlaps.ranges.flat_map do |range|
65
- matching_ranges_converted_to_exclusive = tree.search(range) || []
65
+ # A workaround for the issue: https://github.com/greensync/interval-tree/issues/17
66
+ query = (range.first == range.last) ? range.first : range
67
+ matching_ranges_converted_to_exclusive = tree.search(query) || []
66
68
 
67
69
  # The interval tree converts interval endings to exclusive, so we need to restore the original
68
70
  matching_ranges = matching_ranges_converted_to_exclusive.map do |matching_range_converted_to_exclusive|
@@ -205,14 +207,14 @@ class MultiRange
205
207
  sub_range2_begin = if other.exclude_end?
206
208
  other.end
207
209
  else
208
- other.end + (other.end.is_a?(Float) ? Float::EPSILON : 1)
210
+ other.end.is_a?(Float) ? other.end.next_float : other.end + 1
209
211
  end
210
212
 
211
213
  sub_range2 = range.exclude_end? ? sub_range2_begin...range.end : sub_range2_begin..range.end
212
214
 
213
215
  sub_ranges = []
214
- sub_ranges << sub_range1 if sub_range1.begin < sub_range1.end
215
- sub_ranges << sub_range2 if sub_range2.begin < sub_range2.end
216
+ sub_ranges << sub_range1 if not empty_range?(sub_range1)
217
+ sub_ranges << sub_range2 if not empty_range?(sub_range2)
216
218
  return sub_ranges
217
219
  end
218
220
 
@@ -223,14 +225,26 @@ class MultiRange
223
225
  return true
224
226
  end
225
227
 
226
- def intersect_two_ranges(range_a, range_b)
227
- ranges = [range_a, range_b]
228
- start = ranges.map(&:begin).max
229
- finish = ranges.map(&:end).min
230
- if ranges.sort_by { |range| [range.end, range.exclude_end? ? 1 : 0] }.first.exclude_end?
231
- start...finish
232
- else
233
- start..finish
234
- end
228
+ def intersect_two_ranges(range1, range2)
229
+ start_range = range_with_larger_start(range1, range2)
230
+ end_range = range_with_smaller_end(range1, range2)
231
+ return start_range.begin...end_range.end if end_range.exclude_end?
232
+ return start_range.begin..end_range.end
233
+ end
234
+
235
+ def empty_range?(range)
236
+ range.begin > range.end || (range.begin == range.end && range.exclude_end?)
237
+ end
238
+
239
+ def range_with_larger_start(range1, range2)
240
+ return range1 if range1.begin > range2.begin
241
+ return range2
242
+ end
243
+
244
+ def range_with_smaller_end(range1, range2)
245
+ return range1 if range1.end < range2.end
246
+ return range2 if range1.end > range2.end
247
+ return range1 if range1.exclude_end?
248
+ return range2
235
249
  end
236
250
  end
data/multi_range.gemspec CHANGED
@@ -39,7 +39,6 @@ Gem::Specification.new do |spec|
39
39
  spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
40
40
  spec.add_development_dependency 'rake', '>= 10.5.0'
41
41
  spec.add_development_dependency 'minitest', '~> 5.0'
42
- spec.add_development_dependency 'minitest-color', '~> 0.0.2'
43
42
  spec.add_development_dependency 'backports', '~> 3.15.0'
44
43
 
45
44
  spec.add_dependency 'roulette-wheel-selection', '~> 1.1.1'
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: 2.1.1
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-07 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,20 +58,6 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '5.0'
61
- - !ruby/object:Gem::Dependency
62
- name: minitest-color
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: 0.0.2
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: 0.0.2
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: backports
77
63
  requirement: !ruby/object:Gem::Requirement