splittable 0.0.7 β†’ 0.0.8

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: 37c4759b10b00ca1cf91aabb5e0b7611a6557f4a626e45b6ba8849b4756d6085
4
+ data.tar.gz: 1afade43018d247600cbb00b360b2f0e5e859358eb84fb0a00da9d2a6bf109a3
5
5
  SHA512:
6
- metadata.gz: 33eb4933330ff1020bfc37e8a971273ec825bc6f17c64dbdf8d6825c056db25faeab0683aea256022887fabc524b07df19fe850d79e820df194dee3d37c61281
7
- data.tar.gz: ec8f776bc35bb3c5abe8e887ccc6edd07da873d2f0eabbf9925bdbcf6732eba1188dcb5060f5912c6faedbea934879b4691d990338c3e7d22b38807acbf16a2a
6
+ metadata.gz: 6c7a5a283d57fc378864f8aa22236a6b58c590cb4218a6ff62783248e8052817a27ffd4d81d0812d0ec64699f6ddbb0addeda1fdbba82ecb8f1e1684786a1ac7
7
+ data.tar.gz: 0f10c22baa3d728be34ccd1a01b91901cae23ff32857255d4f66c7ed3ed3bf50988ca2ecb807b7c3f6d9a93c92e5e550ede3017a94e0e7365578ea11a7de8f04
@@ -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,29 @@
1
+ # splittable 0.0.8 (Oct 14, 2025)
2
+
3
+ * **Documentation Improvements**
4
+ * Complete README.md rewrite with better examples and real-world use cases
5
+ * Added comprehensive problem explanation with before/after examples
6
+ * Included e-commerce, invoice distribution, and subscription billing examples
7
+ * Added error handling documentation and development setup instructions
8
+ * Improved project structure documentation
9
+
10
+ * **Gemspec Enhancements**
11
+ * Updated summary and description for better clarity and professionalism
12
+ * Added explicit BigDecimal dependency declaration
13
+ * Enhanced metadata with bug tracker URI
14
+ * Fixed RubyGems metadata warnings
15
+
16
+ * **CI/CD Improvements**
17
+ * Fixed publish workflow to use correct Ruby version (3.4.6)
18
+ * Added proper dependency installation steps in release workflow
19
+ * Resolved Ruby version compatibility issues
20
+
21
+ * **Code Quality**
22
+ * Maintained 100% test coverage
23
+ * All existing functionality preserved and tested
24
+
25
+ *Marcelo Toledo*
26
+
1
27
  ## splittable 0.0.7 (Oct 14, 2025)
2
28
 
3
29
  * 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.8)
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,163 @@ 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.05, 0.03, 0.03] # Sum: 0.11 (truncated from 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.34, 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.00, installments: amounts)
93
+ # => [400.01, 350.00, 250.00]
94
+ # Total: $1,000.00 βœ…
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.00, 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.00 βœ…
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
+ # => NoMethodError: undefined method `[]' for nil:NilClass
61
115
  ```
62
116
 
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)
117
+ ## πŸ› οΈ Development
118
+
119
+ ### Setup
120
+ ```bash
121
+ git clone https://github.com/m4rcelotoledo/splittable.git
122
+ cd splittable
123
+ bundle install
66
124
  ```
67
125
 
68
- Result:
69
- ```ruby
70
- => [0.33334e2, 0.33333e2, 0.33333e2] # => [33.334, 33.333, 33.333]
126
+ ### Running Tests
127
+ ```bash
128
+ # Run all tests
129
+ bundle exec rspec
130
+
131
+ # Run with coverage
132
+ bundle exec rspec --format documentation
133
+
134
+ # Run specific test file
135
+ bundle exec rspec spec/splittable_spec.rb
71
136
  ```
72
137
 
73
- ## Development
138
+ ### Code Quality
139
+ ```bash
140
+ # Run RuboCop
141
+ bundle exec rubocop
74
142
 
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.
143
+ # Auto-fix RuboCop issues
144
+ bundle exec rubocop -a
145
+ ```
76
146
 
77
- To install this gem onto your local machine, run `bundle exec rake install`.
147
+ ### Interactive Console
148
+ ```bash
149
+ bundle exec bin/console
150
+ ```
78
151
 
79
- ## To Release
152
+ ### Project Structure
153
+ ```
154
+ lib/
155
+ β”œβ”€β”€ splittable.rb # Main module with public methods
156
+ β”œβ”€β”€ splittable/
157
+ β”‚ β”œβ”€β”€ version.rb # Gem version
158
+ β”‚ β”œβ”€β”€ division.rb # Division logic
159
+ β”‚ └── normalize.rb # Normalization logic
160
+ spec/
161
+ β”œβ”€β”€ spec_helper.rb # Test configuration
162
+ └── splittable_spec.rb # Test cases
163
+ ```
80
164
 
81
- Fill the `CHANGELOG.md` with relevants update.
165
+ ## πŸ“¦ Release Process
82
166
 
83
- To automatic release a new version, update the version number in `lib/splittable/version.rb` and merge it to `master` branch.
167
+ ### Automatic Release
168
+ 1. Update version in `lib/splittable/version.rb`
169
+ 2. Update `CHANGELOG.md` with relevant changes
170
+ 3. Merge to `master` branch
171
+ 4. GitHub Actions will automatically publish to RubyGems
84
172
 
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).
173
+ ### Manual Release
174
+ ```bash
175
+ # Update version and changelog first
176
+ bundle exec rake release
177
+ ```
86
178
 
87
- ## Contributing
179
+ ## 🀝 Contributing
180
+
181
+ 1. Fork the repository
182
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
183
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
184
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
185
+ 5. Open a Pull Request
88
186
 
89
187
  Bug reports and pull requests are welcome on GitHub at https://github.com/m4rcelotoledo/splittable/blob/master/CONTRIBUTING.md.
90
188
 
91
- ## Code of Conduct
189
+ ## πŸ“„ License
190
+
191
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
192
+
193
+ ## πŸ“š Code of Conduct
92
194
 
93
- Welcome on GitHub at https://github.com/m4rcelotoledo/splittable/blob/master/CODE_OF_CONDUCT.md.
195
+ This project follows the [Contributor Covenant](https://github.com/m4rcelotoledo/splittable/blob/master/CODE_OF_CONDUCT.md) code of conduct.
@@ -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.8'
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.8
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: []