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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37c4759b10b00ca1cf91aabb5e0b7611a6557f4a626e45b6ba8849b4756d6085
4
- data.tar.gz: 1afade43018d247600cbb00b360b2f0e5e859358eb84fb0a00da9d2a6bf109a3
3
+ metadata.gz: 11114efe2ce13eb5f799082f87b27b9031d61c88dc4bbf15429bbb96c5038a62
4
+ data.tar.gz: 214bcc97eb502853d46db7e0b2678570269b6226658cf3c11df921607372fc75
5
5
  SHA512:
6
- metadata.gz: 6c7a5a283d57fc378864f8aa22236a6b58c590cb4218a6ff62783248e8052817a27ffd4d81d0812d0ec64699f6ddbb0addeda1fdbba82ecb8f1e1684786a1ac7
7
- data.tar.gz: 0f10c22baa3d728be34ccd1a01b91901cae23ff32857255d4f66c7ed3ed3bf50988ca2ecb807b7c3f6d9a93c92e5e550ede3017a94e0e7365578ea11a7de8f04
6
+ metadata.gz: 3b47c45ce0f0078632eef4fd3ca2914c17398d75c1e5691d344db08bc9b81a165abe6165763861819e090ffdf264ac0aaf6d5cee9415649d28fbd7f67e7e02e7
7
+ data.tar.gz: 7d4722cc082db9dcb8d450f7fdd876f71842ee61ea8f3ec7716a695cef935ec15b08c09c6473c2f95894f467e14902045069ff5549b5ccd1d8a19352e628cee5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,30 @@
1
- # splittable 0.0.8 (Oct 14, 2025)
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splittable (0.0.8)
4
+ splittable (0.0.9)
5
5
  bigdecimal (~> 3.0)
6
6
 
7
7
  GEM
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.05, 0.03, 0.03] # Sum: 0.11 (truncated from 0.12)
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.34, 33.33, 33.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.00, installments: amounts)
92
+ normalized = Splittable.normalize(value: 1000.01, installments: amounts)
93
93
  # => [400.01, 350.00, 250.00]
94
- # Total: $1,000.00
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.00, quantity: 12)
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.00
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
- # => NoMethodError: undefined method `[]' for nil:NilClass
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Splittable
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splittable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Brandão