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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1ce195bb6bf78672483d4823042006672922a3de448b313c3229c765e6acc54
4
- data.tar.gz: 4d7dbcb92fc8345afcf92637741e68dc8a9cd349cc97e63f80fb66eb916c40da
3
+ metadata.gz: 11114efe2ce13eb5f799082f87b27b9031d61c88dc4bbf15429bbb96c5038a62
4
+ data.tar.gz: 214bcc97eb502853d46db7e0b2678570269b6226658cf3c11df921607372fc75
5
5
  SHA512:
6
- metadata.gz: 33eb4933330ff1020bfc37e8a971273ec825bc6f17c64dbdf8d6825c056db25faeab0683aea256022887fabc524b07df19fe850d79e820df194dee3d37c61281
7
- data.tar.gz: ec8f776bc35bb3c5abe8e887ccc6edd07da873d2f0eabbf9925bdbcf6732eba1188dcb5060f5912c6faedbea934879b4691d990338c3e7d22b38807acbf16a2a
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
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splittable (0.0.7)
4
+ splittable (0.0.9)
5
+ bigdecimal (~> 3.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,12 +2,28 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/splittable.svg)](https://badge.fury.io/rb/splittable)
4
4
  [![Ruby](https://github.com/m4rcelotoledo/splittable/workflows/Ruby/badge.svg?branch=master)](https://github.com/m4rcelotoledo/splittable/actions?query=workflow%3ARuby)
5
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.4.6-red.svg)](https://www.ruby-lang.org/)
6
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
5
7
 
6
- ## Goal
8
+ ## 🎯 Problem Solved
7
9
 
8
- This gem solves the problem of several decimal places in divisions where the result must be presented in cents, that is converting the division result to only two decimal places and the difference is attributed to the first plot.
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
- ## Installation
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
- $ bundle install
36
+ ```bash
37
+ $ bundle install
38
+ ```
21
39
 
22
40
  Or install it yourself as:
23
41
 
24
- $ gem install splittable
42
+ ```bash
43
+ $ gem install splittable
44
+ ```
45
+
46
+ ## πŸ“– Usage
25
47
 
26
- ## Usage
48
+ ### Division Method
27
49
 
28
- Using `division` method:
50
+ Split a total value into equal installments:
29
51
 
30
- ``` ruby
31
- Splittable.division(value: 0.1188888, quantity: 3)
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
- Result: the total truncated value was divided by the number of plots informed and attributed the difference in the first installment:
62
+ ### Normalize Method
63
+
64
+ Normalize existing installments to match a total value:
35
65
 
36
66
  ```ruby
37
- => [0.5e-1, 0.3e-1, 0.3e-1] # => [0.05, 0.03, 0.03]
38
- ```
39
- Default precision is 2 decimal places, but, you can customize this with precision parameter:
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
- ``` ruby
42
- Splittable.division(value: 10, quantity: 3, precision: 3)
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
- Result:
76
+ ## πŸ’‘ Real-World Examples
77
+
78
+ ### E-commerce Payment Splitting
46
79
  ```ruby
47
- => [0.3334e1, 0.3333e1, 0.3333e1] # => [0.334, 0.333, 0.333]
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
- Using `normalize` method:
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
- Splittable.normalize(value: 100.003, installments: [33.33, 21.433, 43.33333])
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
- Result: all values are truncated and them the difference is attributed in the first installment:
105
+ ## ⚠️ Error Handling
58
106
 
59
107
  ```ruby
60
- => [0.3524e2, 0.2143e2, 0.4333e2] # => [35.24, 21.43, 43.33]
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
- In this method, you have the same optional precision parameter:
64
- ```ruby
65
- Splittable.normalize(value: 100, installments: [33.33333333, 33.33333333, 33.33333333], precision: 3)
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
- Result:
69
- ```ruby
70
- => [0.33334e2, 0.33333e2, 0.33333e2] # => [33.334, 33.333, 33.333]
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
- ## Development
142
+ ### Code Quality
143
+ ```bash
144
+ # Run RuboCop
145
+ bundle exec rubocop
74
146
 
75
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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
- To install this gem onto your local machine, run `bundle exec rake install`.
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
- ## To Release
169
+ ## πŸ“¦ Release Process
80
170
 
81
- Fill the `CHANGELOG.md` with relevants update.
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
- To automatic release a new version, update the version number in `lib/splittable/version.rb` and merge it to `master` branch.
177
+ ### Manual Release
178
+ ```bash
179
+ # Update version and changelog first
180
+ bundle exec rake release
181
+ ```
84
182
 
85
- To manual release update the version and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
183
+ ## 🀝 Contributing
86
184
 
87
- ## Contributing
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
- ## Code of Conduct
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
- Welcome on GitHub at https://github.com/m4rcelotoledo/splittable/blob/master/CODE_OF_CONDUCT.md.
199
+ This project follows the [Contributor Covenant](https://github.com/m4rcelotoledo/splittable/blob/master/CODE_OF_CONDUCT.md) code of conduct.
@@ -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.7'
4
+ VERSION = '0.0.9'
5
5
  end
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 = 'Calculate division and normalize parcels to use just cents.'
14
- spec.description = 'This gem solves the problem of several decimal places in divisions
15
- where the result must be presented in cents, that is converting the
16
- division result to only two decimal places and the difference is
17
- attributed to the first plot.'
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.7
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
- description: |-
14
- This gem solves the problem of several decimal places in divisions
15
- where the result must be presented in cents, that is converting the
16
- division result to only two decimal places and the difference is
17
- attributed to the first plot.
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: Calculate division and normalize parcels to use just cents.
89
+ summary: Split monetary values into equal installments with precise cent rounding.
75
90
  test_files: []