splittable 0.0.8 → 0.0.9
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 +27 -1
- data/Gemfile.lock +1 -1
- data/README.md +11 -7
- data/lib/splittable/normalize.rb +7 -0
- data/lib/splittable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11114efe2ce13eb5f799082f87b27b9031d61c88dc4bbf15429bbb96c5038a62
|
4
|
+
data.tar.gz: 214bcc97eb502853d46db7e0b2678570269b6226658cf3c11df921607372fc75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b47c45ce0f0078632eef4fd3ca2914c17398d75c1e5691d344db08bc9b81a165abe6165763861819e090ffdf264ac0aaf6d5cee9415649d28fbd7f67e7e02e7
|
7
|
+
data.tar.gz: 7d4722cc082db9dcb8d450f7fdd876f71842ee61ea8f3ec7716a695cef935ec15b08c09c6473c2f95894f467e14902045069ff5549b5ccd1d8a19352e628cee5
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,30 @@
|
|
1
|
-
# splittable 0.0.
|
1
|
+
# splittable 0.0.9 (Oct 15, 2025)
|
2
|
+
|
3
|
+
* **Bug Fixes**
|
4
|
+
* Fixed incorrect examples in README.md with mathematically accurate values
|
5
|
+
* Corrected division examples to show proper cent adjustment behavior
|
6
|
+
* Fixed normalize examples to demonstrate actual gem behavior
|
7
|
+
|
8
|
+
* **Error Handling Improvements**
|
9
|
+
* Added proper validation for empty installments array in normalize method
|
10
|
+
* Added validation for nil installments parameter
|
11
|
+
* Improved error messages with clear ArgumentError exceptions
|
12
|
+
* Enhanced error handling documentation with accurate examples
|
13
|
+
|
14
|
+
* **Test Coverage**
|
15
|
+
* Added comprehensive tests for error handling scenarios
|
16
|
+
* Added tests for empty and nil installments arrays
|
17
|
+
* Maintained 100% test coverage (38 examples, 0 failures)
|
18
|
+
* Improved test readability with better formatting
|
19
|
+
|
20
|
+
* **Code Quality**
|
21
|
+
* Enhanced input validation in Splittable::Normalize class
|
22
|
+
* Improved error messages for better developer experience
|
23
|
+
* All existing functionality preserved and thoroughly tested
|
24
|
+
|
25
|
+
*Marcelo Toledo*
|
26
|
+
|
27
|
+
## splittable 0.0.8 (Oct 14, 2025)
|
2
28
|
|
3
29
|
* **Documentation Improvements**
|
4
30
|
* Complete README.md rewrite with better examples and real-world use cases
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -52,7 +52,7 @@ Split a total value into equal installments:
|
|
52
52
|
```ruby
|
53
53
|
# Basic usage - split $0.12 into 3 equal parts
|
54
54
|
Splittable.division(value: 0.12, quantity: 3)
|
55
|
-
# => [0.
|
55
|
+
# => [0.04, 0.04, 0.04] # Sum: 0.12
|
56
56
|
|
57
57
|
# Custom precision - 3 decimal places
|
58
58
|
Splittable.division(value: 10, quantity: 3, precision: 3)
|
@@ -79,7 +79,7 @@ Splittable.normalize(value: 100, installments: [33.333, 33.333, 33.333], precisi
|
|
79
79
|
```ruby
|
80
80
|
# Split a $99.99 order into 3 monthly payments
|
81
81
|
payments = Splittable.division(value: 99.99, quantity: 3)
|
82
|
-
# => [33.
|
82
|
+
# => [33.33, 33.33, 33.33]
|
83
83
|
# Total: $99.99 ✅
|
84
84
|
```
|
85
85
|
|
@@ -89,17 +89,17 @@ payments = Splittable.division(value: 99.99, quantity: 3)
|
|
89
89
|
departments = ['Sales', 'Marketing', 'Support']
|
90
90
|
amounts = [400.00, 350.00, 250.00]
|
91
91
|
|
92
|
-
normalized = Splittable.normalize(value: 1000.
|
92
|
+
normalized = Splittable.normalize(value: 1000.01, installments: amounts)
|
93
93
|
# => [400.01, 350.00, 250.00]
|
94
|
-
# Total: $1,000.
|
94
|
+
# Total: $1,000.01 ✅
|
95
95
|
```
|
96
96
|
|
97
97
|
### Subscription Billing
|
98
98
|
```ruby
|
99
99
|
# Annual subscription split into monthly payments
|
100
|
-
monthly_payment = Splittable.division(value: 120.
|
100
|
+
monthly_payment = Splittable.division(value: 120.01, quantity: 12)
|
101
101
|
# => [10.01, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00]
|
102
|
-
# Total: $120.
|
102
|
+
# Total: $120.01 ✅
|
103
103
|
```
|
104
104
|
|
105
105
|
## ⚠️ Error Handling
|
@@ -111,7 +111,11 @@ Splittable.division(value: 100, quantity: 0)
|
|
111
111
|
|
112
112
|
# Empty installments array
|
113
113
|
Splittable.normalize(value: 100, installments: [])
|
114
|
-
# =>
|
114
|
+
# => ArgumentError: installments should be a non-empty array
|
115
|
+
|
116
|
+
# Nil installments
|
117
|
+
Splittable.normalize(value: 100, installments: nil)
|
118
|
+
# => ArgumentError: installments should be a non-empty array
|
115
119
|
```
|
116
120
|
|
117
121
|
## 🛠️ Development
|
data/lib/splittable/normalize.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
class Splittable::Normalize
|
4
4
|
def initialize(value:, installments:, precision: 2)
|
5
|
+
check_installments_validity!(installments)
|
5
6
|
@value = BigDecimal(value, 15).truncate(precision)
|
6
7
|
@installments = installments.map { |installment| BigDecimal(installment.round(precision), 15) }
|
7
8
|
end
|
@@ -17,4 +18,10 @@ class Splittable::Normalize
|
|
17
18
|
|
18
19
|
attr_reader :value
|
19
20
|
attr_accessor :installments
|
21
|
+
|
22
|
+
def check_installments_validity!(installments)
|
23
|
+
return if installments.is_a?(Array) && !installments.empty?
|
24
|
+
|
25
|
+
raise ArgumentError, 'installments should be a non-empty array'
|
26
|
+
end
|
20
27
|
end
|
data/lib/splittable/version.rb
CHANGED