philiprehberger-interval 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6039cd1187d208aeb17ffae5d095d4dd9416fd8175f95084984600dc36c15b74
4
- data.tar.gz: 4cb497c7a97490954a47568a6b024e517f71a680f040644073b60b316f6fe174
3
+ metadata.gz: 2614076496fada8f6202df687ec993c5438e3a47945824e05e6bb4d00cc1c046
4
+ data.tar.gz: 2557c885218f82fe7de28ea6e91e660b9b901ab2995ca8d68e3a1ef9cf9b2d21
5
5
  SHA512:
6
- metadata.gz: 60355c282c23da5623dc104947363632290343db018701c800f0b10e65bb64d87e5c5e0a69b08ca309ee7241318d92381cca64a1f9fc0f5be036a139d2258b9a
7
- data.tar.gz: 4c686abfd2318284ca810c87d25787804029ec3355039f56f3a859d3abdae8925704e0320a3ac6be192174dbe426fd28622ce73be36d514e0e18ae00b26117f1
6
+ metadata.gz: ed05a860c2d28ce9cfdf00787585e117c41ee03bd1a4f917f4c06d4c461313a7fcdfe0fa7ce9f6073804c4c67c1169e84a7988a2070d8f54f42a725a0caef36b
7
+ data.tar.gz: 8451b55300a3d8d489cc895792256f4e7a1077d9be2a0df25aee1e7f9ef42d9defa2de2fe7eabe3b3d3c58c6c959037f65f89a06eaa8e96d61025ff91a09e285
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-04-15
11
+
12
+ ### Added
13
+ - `Interval.intersection(intervals)` — compute the common overlap of a collection of intervals
14
+
10
15
  ## [0.2.0] - 2026-04-03
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -83,6 +83,19 @@ Philiprehberger::Interval.gaps(intervals)
83
83
  # => [[7, 10]]
84
84
  ```
85
85
 
86
+ ### Finding a Common Intersection
87
+
88
+ Compute the overlap shared by every interval, or `nil` if any pair is disjoint:
89
+
90
+ ```ruby
91
+ Philiprehberger::Interval.intersection([
92
+ Philiprehberger::Interval.new(1, 10),
93
+ Philiprehberger::Interval.new(3, 8),
94
+ Philiprehberger::Interval.new(5, 12)
95
+ ])
96
+ # => [5, 8]
97
+ ```
98
+
86
99
  ### With Time Values
87
100
 
88
101
  ```ruby
@@ -110,6 +123,7 @@ shift.include?(Time.new(2026, 1, 1, 12)) # => true
110
123
  | `#clamp(value)` | Clamp value to interval bounds |
111
124
  | `.merge(intervals)` | Merge overlapping intervals into non-overlapping set |
112
125
  | `.gaps(intervals)` | Find gaps between a set of intervals |
126
+ | `.intersection(intervals)` | Common overlap of a collection of intervals, or `nil` |
113
127
 
114
128
  ## Development
115
129
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Interval
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -39,6 +39,20 @@ module Philiprehberger
39
39
  merged
40
40
  end
41
41
 
42
+ # Compute the common overlap across a collection of intervals.
43
+ #
44
+ # @param intervals [Array<Range>] the intervals to intersect
45
+ # @return [Range, nil] the common intersection, or nil if any pair is disjoint
46
+ def self.intersection(intervals)
47
+ return nil if intervals.empty?
48
+
49
+ intervals[1..].reduce(intervals.first) do |acc, current|
50
+ return nil if acc.nil?
51
+
52
+ acc.intersect(current)
53
+ end
54
+ end
55
+
42
56
  # Find gaps between a collection of intervals.
43
57
  #
44
58
  # @param intervals [Array<Range>] the intervals to analyze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-03 00:00:00.000000000 Z
11
+ date: 2026-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interval data type supporting closed, open, and half-open boundaries
14
14
  with overlap detection, containment, intersection, union, subtraction, shift, scale,