fiber_units 0.1.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 +4 -4
- data/CHANGELOG.md +22 -0
- data/lib/fiber_units/dimensions/count.rb +48 -0
- data/lib/fiber_units/dimensions/row_count.rb +1 -10
- data/lib/fiber_units/dimensions/stitch_count.rb +1 -10
- data/lib/fiber_units/measurement.rb +18 -0
- data/lib/fiber_units/version.rb +1 -1
- data/lib/fiber_units.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b852a73832747576078a185f9e3fab2a926fd9836d4df9b6a6ce05e2f5718436
|
|
4
|
+
data.tar.gz: 37e5f5208b1c12a13d9c1f01a30d87f7508520df120c4c99bc9fd1810a73bbb1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b7b1a97a8d92bb353e9296592ca712f176e737119ba064eb2122a1f7fc8181cc02db21860e86e818ab999412ce23ec753d3a6070293e4242b7507a6d965ee3f
|
|
7
|
+
data.tar.gz: 532b9eb308506abaef91e538bb6bfc247a82355130141e10cdb2827925d1034111156648947832feda0406c03d667713f0c6f68f0aecdb5e0b50e4263324147e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.3.0] - 2026-03-14
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Shared `Count` base class for `RowCount` and `StitchCount`
|
|
7
|
+
- Equality and comparison behavior for `StitchCount` and `RowCount`
|
|
8
|
+
- Coverage for shared count behavior through `RowCount` and `StitchCount` specs
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-03-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Comparison operators (`<`, `>`, `<=`, `>=`, `==`, `!=`) for `Measurement` class
|
|
14
|
+
- Support for cross-unit comparisons (e.g., `4.inches > 10.centimeters`)
|
|
15
|
+
- Dimension safety checks in comparisons (raises error for incompatible units)
|
|
16
|
+
|
|
3
17
|
## [0.1.0] - 2026-03-09
|
|
4
18
|
|
|
19
|
+
### Added
|
|
20
|
+
- Core `Measurement` class for representing and manipulating fiber unit measurements
|
|
21
|
+
- Dimension types: `Length`, `Weight`, `RowCount`, and `StitchCount`
|
|
22
|
+
- Conversion framework with `LengthConversion` and `WeightConversion` support
|
|
23
|
+
- Unit operations: addition, subtraction, multiplication, and division
|
|
24
|
+
- `Ratio` class for expressing relationships between measurements
|
|
25
|
+
- Numeric extensions for DSL-style usage (e.g., `10.cm`, `100.grams`)
|
|
26
|
+
- Comprehensive RBS type signatures for type checking support
|
|
5
27
|
- Initial release
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module FiberUnits
|
|
2
|
+
class Count
|
|
3
|
+
include Comparable
|
|
4
|
+
|
|
5
|
+
attr_reader :value
|
|
6
|
+
|
|
7
|
+
def initialize(value, _unit = nil)
|
|
8
|
+
@value = value
|
|
9
|
+
freeze
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def +(other)
|
|
13
|
+
ensure_same_class!(other)
|
|
14
|
+
self.class.new(value + other.value)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def -(other)
|
|
18
|
+
ensure_same_class!(other)
|
|
19
|
+
self.class.new(value - other.value)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def *(other)
|
|
23
|
+
self.class.new(value * other)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_i
|
|
27
|
+
value
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def <=>(other)
|
|
31
|
+
return nil unless other.instance_of?(self.class)
|
|
32
|
+
value <=> other.value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def ==(other)
|
|
36
|
+
other.class == self.class && other.value == value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def ensure_same_class!(other)
|
|
42
|
+
unless other.instance_of?(self.class)
|
|
43
|
+
raise FiberUnits::DimensionError,
|
|
44
|
+
"Cannot combine #{self.class} with #{other.class}"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module FiberUnits
|
|
2
2
|
class Measurement
|
|
3
|
+
include Comparable
|
|
4
|
+
|
|
3
5
|
attr_reader :value, :unit
|
|
4
6
|
|
|
5
7
|
def initialize(value, unit)
|
|
@@ -39,6 +41,22 @@ module FiberUnits
|
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
|
|
44
|
+
def <=>(other)
|
|
45
|
+
ensure_same_dimension!(other)
|
|
46
|
+
to_base <=> other.to_base
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def ==(other)
|
|
50
|
+
return false unless other.is_a?(Measurement)
|
|
51
|
+
return false unless other.is_a?(self.class)
|
|
52
|
+
|
|
53
|
+
(to_base - other.to_base).abs < 1e-10
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def !=(other)
|
|
57
|
+
!(self == other)
|
|
58
|
+
end
|
|
59
|
+
|
|
42
60
|
def to(target_unit)
|
|
43
61
|
raise FiberUnits::InvalidUnitError unless self.class::FACTORS.key?(target_unit)
|
|
44
62
|
|
data/lib/fiber_units/version.rb
CHANGED
data/lib/fiber_units.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "fiber_units/conversions/weight_conversion"
|
|
|
8
8
|
|
|
9
9
|
require_relative "fiber_units/dimensions/length"
|
|
10
10
|
require_relative "fiber_units/dimensions/weight"
|
|
11
|
+
require_relative "fiber_units/dimensions/count"
|
|
11
12
|
require_relative "fiber_units/dimensions/stitch_count"
|
|
12
13
|
require_relative "fiber_units/dimensions/row_count"
|
|
13
14
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fiber_units
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Meagan Waller
|
|
@@ -28,6 +28,7 @@ files:
|
|
|
28
28
|
- lib/fiber_units.rb
|
|
29
29
|
- lib/fiber_units/conversions/length_conversion.rb
|
|
30
30
|
- lib/fiber_units/conversions/weight_conversion.rb
|
|
31
|
+
- lib/fiber_units/dimensions/count.rb
|
|
31
32
|
- lib/fiber_units/dimensions/length.rb
|
|
32
33
|
- lib/fiber_units/dimensions/row_count.rb
|
|
33
34
|
- lib/fiber_units/dimensions/stitch_count.rb
|