philiprehberger-interval 0.3.0 → 0.4.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: 2614076496fada8f6202df687ec993c5438e3a47945824e05e6bb4d00cc1c046
4
- data.tar.gz: 2557c885218f82fe7de28ea6e91e660b9b901ab2995ca8d68e3a1ef9cf9b2d21
3
+ metadata.gz: ecb8d7c68d3603d44c8df9a87a224c52300377809ad98ab1d19fe1a89ec13449
4
+ data.tar.gz: 75b3438103596f8a4de7f358a9f1cc25cd39fe5e80a47dfb6f25d38852e26964
5
5
  SHA512:
6
- metadata.gz: ed05a860c2d28ce9cfdf00787585e117c41ee03bd1a4f917f4c06d4c461313a7fcdfe0fa7ce9f6073804c4c67c1169e84a7988a2070d8f54f42a725a0caef36b
7
- data.tar.gz: 8451b55300a3d8d489cc895792256f4e7a1077d9be2a0df25aee1e7f9ef42d9defa2de2fe7eabe3b3d3c58c6c959037f65f89a06eaa8e96d61025ff91a09e285
6
+ metadata.gz: 78198caa2a0cf621b3545997e8fdfb58ad7424d7304e7d4367873dd69eaa02db2c91f1ed5a95cd365074be886063fb91941dea72180b2ce4e099c6e1982fddcf
7
+ data.tar.gz: 2dbb700fce8cd9cf5d973ab0baabece8e8b94e8d79f71939a805418f7fdfdbf626ca183ae9ab0fc18c2c036f21a2c0de9ddd28d90e1978da02139ac8eb3d1178
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.4.0] - 2026-04-15
11
+
12
+ ### Added
13
+ - `Range#overlap_ratio(other)` — fraction of self covered by another interval (Float in 0.0–1.0)
14
+
10
15
  ## [0.3.0] - 2026-04-15
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -36,6 +36,7 @@ a.overlaps?(b) # => true
36
36
  a.intersect(b) # => [3, 5]
37
37
  a.union(b) # => [1, 8]
38
38
  a.include?(4) # => true
39
+ a.overlap_ratio(b) # => 0.5
39
40
  ```
40
41
 
41
42
  ### Interval Types
@@ -113,6 +114,7 @@ shift.include?(Time.new(2026, 1, 1, 12)) # => true
113
114
  | `#contains?(other)` | Check if interval fully contains another |
114
115
  | `#adjacent?(other)` | Check if intervals are touching but not overlapping |
115
116
  | `#intersect(other)` | Return the overlap between two intervals |
117
+ | `#overlap_ratio(other)` | Fraction of self covered by other (0.0–1.0) |
116
118
  | `#union(other)` | Return the combined interval |
117
119
  | `#subtract(other)` | Remove another interval, returning remaining parts |
118
120
  | `#size` | Length of the interval |
@@ -113,6 +113,23 @@ module Philiprehberger
113
113
  @finish - @start
114
114
  end
115
115
 
116
+ # Return the fraction of self that is covered by another interval.
117
+ #
118
+ # Returns a Float in 0.0..1.0. Returns 0.0 if disjoint, 1.0 if self is
119
+ # fully contained in other. If self has zero length (a point), returns
120
+ # 1.0 when the point is within other, else 0.0.
121
+ #
122
+ # @param other [Range] the other interval
123
+ # @return [Float] the fraction of self covered by other
124
+ def overlap_ratio(other)
125
+ return other.include?(@start) ? 1.0 : 0.0 if size.zero?
126
+
127
+ overlap = intersect(other)
128
+ return 0.0 if overlap.nil?
129
+
130
+ overlap.size.to_f / size
131
+ end
132
+
116
133
  # Check if a point is within the interval.
117
134
  #
118
135
  # @param point [Comparable] the point to check
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Interval
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger