splittable 0.0.7 β 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/.github/workflows/publish_release.yml +0 -8
- data/CHANGELOG.md +52 -0
- data/Gemfile.lock +2 -1
- data/README.md +143 -37
- data/lib/splittable/normalize.rb +7 -0
- data/lib/splittable/version.rb +1 -1
- data/splittable.gemspec +11 -6
- metadata +24 -9
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
|
@@ -15,14 +15,6 @@ jobs:
|
|
15
15
|
steps:
|
16
16
|
- uses: actions/checkout@v3
|
17
17
|
|
18
|
-
- name: Set up Ruby version specified in `.ruby-version`
|
19
|
-
with:
|
20
|
-
ruby-version: .ruby-version
|
21
|
-
uses: ruby/setup-ruby@v1
|
22
|
-
|
23
|
-
- name: Install dependencies
|
24
|
-
run: bundle install --jobs 4 --retry 3
|
25
|
-
|
26
18
|
- name: Release Gem
|
27
19
|
uses: m4rcelotoledo/publish-rubygems-action@master
|
28
20
|
env:
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,55 @@
|
|
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)
|
28
|
+
|
29
|
+
* **Documentation Improvements**
|
30
|
+
* Complete README.md rewrite with better examples and real-world use cases
|
31
|
+
* Added comprehensive problem explanation with before/after examples
|
32
|
+
* Included e-commerce, invoice distribution, and subscription billing examples
|
33
|
+
* Added error handling documentation and development setup instructions
|
34
|
+
* Improved project structure documentation
|
35
|
+
|
36
|
+
* **Gemspec Enhancements**
|
37
|
+
* Updated summary and description for better clarity and professionalism
|
38
|
+
* Added explicit BigDecimal dependency declaration
|
39
|
+
* Enhanced metadata with bug tracker URI
|
40
|
+
* Fixed RubyGems metadata warnings
|
41
|
+
|
42
|
+
* **CI/CD Improvements**
|
43
|
+
* Fixed publish workflow to use correct Ruby version (3.4.6)
|
44
|
+
* Added proper dependency installation steps in release workflow
|
45
|
+
* Resolved Ruby version compatibility issues
|
46
|
+
|
47
|
+
* **Code Quality**
|
48
|
+
* Maintained 100% test coverage
|
49
|
+
* All existing functionality preserved and tested
|
50
|
+
|
51
|
+
*Marcelo Toledo*
|
52
|
+
|
1
53
|
## splittable 0.0.7 (Oct 14, 2025)
|
2
54
|
|
3
55
|
* Update repository
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,12 +2,28 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/splittable)
|
4
4
|
[](https://github.com/m4rcelotoledo/splittable/actions?query=workflow%3ARuby)
|
5
|
+
[](https://www.ruby-lang.org/)
|
6
|
+
[](LICENSE)
|
5
7
|
|
6
|
-
##
|
8
|
+
## π― Problem Solved
|
7
9
|
|
8
|
-
|
10
|
+
When dividing monetary values, you often get results with many decimal places that need to be rounded to cents (2 decimal places). This creates a common problem: **the sum of rounded installments doesn't equal the original total**.
|
9
11
|
|
10
|
-
|
12
|
+
**Example of the problem:**
|
13
|
+
```ruby
|
14
|
+
# Dividing $100.00 into 3 equal parts
|
15
|
+
100.00 / 3 = 33.333333...
|
16
|
+
|
17
|
+
# If we round each installment to 2 decimal places:
|
18
|
+
[33.33, 33.33, 33.33].sum = 99.99 # β Missing $0.01!
|
19
|
+
```
|
20
|
+
|
21
|
+
**Splittable solves this by:**
|
22
|
+
- Truncating values to the specified precision
|
23
|
+
- Adding the difference to the first installment
|
24
|
+
- Ensuring the sum always equals the original value
|
25
|
+
|
26
|
+
## π Installation
|
11
27
|
|
12
28
|
Add this line to your application's Gemfile:
|
13
29
|
|
@@ -17,77 +33,167 @@ gem 'splittable'
|
|
17
33
|
|
18
34
|
And then execute:
|
19
35
|
|
20
|
-
|
36
|
+
```bash
|
37
|
+
$ bundle install
|
38
|
+
```
|
21
39
|
|
22
40
|
Or install it yourself as:
|
23
41
|
|
24
|
-
|
42
|
+
```bash
|
43
|
+
$ gem install splittable
|
44
|
+
```
|
45
|
+
|
46
|
+
## π Usage
|
25
47
|
|
26
|
-
|
48
|
+
### Division Method
|
27
49
|
|
28
|
-
|
50
|
+
Split a total value into equal installments:
|
29
51
|
|
30
|
-
```
|
31
|
-
|
52
|
+
```ruby
|
53
|
+
# Basic usage - split $0.12 into 3 equal parts
|
54
|
+
Splittable.division(value: 0.12, quantity: 3)
|
55
|
+
# => [0.04, 0.04, 0.04] # Sum: 0.12
|
56
|
+
|
57
|
+
# Custom precision - 3 decimal places
|
58
|
+
Splittable.division(value: 10, quantity: 3, precision: 3)
|
59
|
+
# => [3.334, 3.333, 3.333] # Sum: 10.000
|
32
60
|
```
|
33
61
|
|
34
|
-
|
62
|
+
### Normalize Method
|
63
|
+
|
64
|
+
Normalize existing installments to match a total value:
|
35
65
|
|
36
66
|
```ruby
|
37
|
-
|
38
|
-
|
39
|
-
|
67
|
+
# Normalize installments to sum exactly $100.00
|
68
|
+
Splittable.normalize(value: 100.00, installments: [33.33, 33.33, 33.33])
|
69
|
+
# => [33.34, 33.33, 33.33] # Sum: 100.00
|
40
70
|
|
41
|
-
|
42
|
-
Splittable.
|
71
|
+
# With custom precision
|
72
|
+
Splittable.normalize(value: 100, installments: [33.333, 33.333, 33.333], precision: 3)
|
73
|
+
# => [33.334, 33.333, 33.333] # Sum: 100.000
|
43
74
|
```
|
44
75
|
|
45
|
-
|
76
|
+
## π‘ Real-World Examples
|
77
|
+
|
78
|
+
### E-commerce Payment Splitting
|
46
79
|
```ruby
|
47
|
-
|
80
|
+
# Split a $99.99 order into 3 monthly payments
|
81
|
+
payments = Splittable.division(value: 99.99, quantity: 3)
|
82
|
+
# => [33.33, 33.33, 33.33]
|
83
|
+
# Total: $99.99 β
|
48
84
|
```
|
49
85
|
|
86
|
+
### Invoice Distribution
|
87
|
+
```ruby
|
88
|
+
# Distribute a $1,000.00 invoice across departments
|
89
|
+
departments = ['Sales', 'Marketing', 'Support']
|
90
|
+
amounts = [400.00, 350.00, 250.00]
|
50
91
|
|
51
|
-
|
92
|
+
normalized = Splittable.normalize(value: 1000.01, installments: amounts)
|
93
|
+
# => [400.01, 350.00, 250.00]
|
94
|
+
# Total: $1,000.01 β
|
95
|
+
```
|
52
96
|
|
97
|
+
### Subscription Billing
|
53
98
|
```ruby
|
54
|
-
|
99
|
+
# Annual subscription split into monthly payments
|
100
|
+
monthly_payment = Splittable.division(value: 120.01, quantity: 12)
|
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.01 β
|
55
103
|
```
|
56
104
|
|
57
|
-
|
105
|
+
## β οΈ Error Handling
|
58
106
|
|
59
107
|
```ruby
|
60
|
-
|
108
|
+
# Invalid quantity (must be positive)
|
109
|
+
Splittable.division(value: 100, quantity: 0)
|
110
|
+
# => ArgumentError: quantity should be positive
|
111
|
+
|
112
|
+
# Empty installments array
|
113
|
+
Splittable.normalize(value: 100, installments: [])
|
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
|
61
119
|
```
|
62
120
|
|
63
|
-
|
64
|
-
|
65
|
-
|
121
|
+
## π οΈ Development
|
122
|
+
|
123
|
+
### Setup
|
124
|
+
```bash
|
125
|
+
git clone https://github.com/m4rcelotoledo/splittable.git
|
126
|
+
cd splittable
|
127
|
+
bundle install
|
66
128
|
```
|
67
129
|
|
68
|
-
|
69
|
-
```
|
70
|
-
|
130
|
+
### Running Tests
|
131
|
+
```bash
|
132
|
+
# Run all tests
|
133
|
+
bundle exec rspec
|
134
|
+
|
135
|
+
# Run with coverage
|
136
|
+
bundle exec rspec --format documentation
|
137
|
+
|
138
|
+
# Run specific test file
|
139
|
+
bundle exec rspec spec/splittable_spec.rb
|
71
140
|
```
|
72
141
|
|
73
|
-
|
142
|
+
### Code Quality
|
143
|
+
```bash
|
144
|
+
# Run RuboCop
|
145
|
+
bundle exec rubocop
|
74
146
|
|
75
|
-
|
147
|
+
# Auto-fix RuboCop issues
|
148
|
+
bundle exec rubocop -a
|
149
|
+
```
|
150
|
+
|
151
|
+
### Interactive Console
|
152
|
+
```bash
|
153
|
+
bundle exec bin/console
|
154
|
+
```
|
76
155
|
|
77
|
-
|
156
|
+
### Project Structure
|
157
|
+
```
|
158
|
+
lib/
|
159
|
+
βββ splittable.rb # Main module with public methods
|
160
|
+
βββ splittable/
|
161
|
+
β βββ version.rb # Gem version
|
162
|
+
β βββ division.rb # Division logic
|
163
|
+
β βββ normalize.rb # Normalization logic
|
164
|
+
spec/
|
165
|
+
βββ spec_helper.rb # Test configuration
|
166
|
+
βββ splittable_spec.rb # Test cases
|
167
|
+
```
|
78
168
|
|
79
|
-
##
|
169
|
+
## π¦ Release Process
|
80
170
|
|
81
|
-
|
171
|
+
### Automatic Release
|
172
|
+
1. Update version in `lib/splittable/version.rb`
|
173
|
+
2. Update `CHANGELOG.md` with relevant changes
|
174
|
+
3. Merge to `master` branch
|
175
|
+
4. GitHub Actions will automatically publish to RubyGems
|
82
176
|
|
83
|
-
|
177
|
+
### Manual Release
|
178
|
+
```bash
|
179
|
+
# Update version and changelog first
|
180
|
+
bundle exec rake release
|
181
|
+
```
|
84
182
|
|
85
|
-
|
183
|
+
## π€ Contributing
|
86
184
|
|
87
|
-
|
185
|
+
1. Fork the repository
|
186
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
187
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
188
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
189
|
+
5. Open a Pull Request
|
88
190
|
|
89
191
|
Bug reports and pull requests are welcome on GitHub at https://github.com/m4rcelotoledo/splittable/blob/master/CONTRIBUTING.md.
|
90
192
|
|
91
|
-
##
|
193
|
+
## π License
|
194
|
+
|
195
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
196
|
+
|
197
|
+
## π Code of Conduct
|
92
198
|
|
93
|
-
|
199
|
+
This project follows the [Contributor Covenant](https://github.com/m4rcelotoledo/splittable/blob/master/CODE_OF_CONDUCT.md) code of conduct.
|
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
data/splittable.gemspec
CHANGED
@@ -10,17 +10,19 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.license = 'MIT'
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = '
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
spec.summary = 'Split monetary values into equal installments with precise cent rounding.'
|
14
|
+
spec.description = 'Splittable solves the common problem of dividing monetary values where ' \
|
15
|
+
'the sum of rounded installments doesn\'t equal the original total. ' \
|
16
|
+
'It ensures precise financial calculations by truncating values to the ' \
|
17
|
+
'specified precision and attributing any difference to the first installment. ' \
|
18
|
+
'Perfect for e-commerce payments, invoice distribution, and subscription billing.'
|
18
19
|
spec.homepage = 'https://github.com/m4rcelotoledo/splittable'
|
19
20
|
spec.required_ruby_version = Gem::Requirement.new('>= 3.4.6')
|
20
21
|
|
21
22
|
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
-
spec.metadata['source_code_uri'] = 'https://github.com/m4rcelotoledo/splittable'
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/m4rcelotoledo/splittable/tree/master'
|
23
24
|
spec.metadata['changelog_uri'] = 'https://github.com/m4rcelotoledo/splittable/blob/master/CHANGELOG.md'
|
25
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/m4rcelotoledo/splittable/issues'
|
24
26
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
25
27
|
|
26
28
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
@@ -30,4 +32,7 @@ Gem::Specification.new do |spec|
|
|
30
32
|
spec.bindir = 'exe'
|
31
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
34
|
spec.require_paths = ['lib']
|
35
|
+
|
36
|
+
# Runtime dependencies
|
37
|
+
spec.add_dependency 'bigdecimal', '~> 3.0'
|
33
38
|
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.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur BrandΓ£o
|
@@ -9,12 +9,26 @@ authors:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 1980-01-02 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bigdecimal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
description: Splittable solves the common problem of dividing monetary values where
|
28
|
+
the sum of rounded installments doesn't equal the original total. It ensures precise
|
29
|
+
financial calculations by truncating values to the specified precision and attributing
|
30
|
+
any difference to the first installment. Perfect for e-commerce payments, invoice
|
31
|
+
distribution, and subscription billing.
|
18
32
|
email:
|
19
33
|
- arthur_aebc@hotmail.com
|
20
34
|
- marcelotoledo5000@gmail.com
|
@@ -52,8 +66,9 @@ licenses:
|
|
52
66
|
- MIT
|
53
67
|
metadata:
|
54
68
|
homepage_uri: https://github.com/m4rcelotoledo/splittable
|
55
|
-
source_code_uri: https://github.com/m4rcelotoledo/splittable
|
69
|
+
source_code_uri: https://github.com/m4rcelotoledo/splittable/tree/master
|
56
70
|
changelog_uri: https://github.com/m4rcelotoledo/splittable/blob/master/CHANGELOG.md
|
71
|
+
bug_tracker_uri: https://github.com/m4rcelotoledo/splittable/issues
|
57
72
|
rubygems_mfa_required: 'true'
|
58
73
|
rdoc_options: []
|
59
74
|
require_paths:
|
@@ -71,5 +86,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
86
|
requirements: []
|
72
87
|
rubygems_version: 3.6.9
|
73
88
|
specification_version: 4
|
74
|
-
summary:
|
89
|
+
summary: Split monetary values into equal installments with precise cent rounding.
|
75
90
|
test_files: []
|