splittable 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish_release.yml +25 -0
- data/.github/workflows/ruby.yml +8 -5
- data/.gitignore +3 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +28 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +12 -13
- data/README.md +24 -0
- data/lib/splittable.rb +6 -31
- data/lib/splittable/division.rb +29 -0
- data/lib/splittable/normalize.rb +20 -0
- data/lib/splittable/version.rb +1 -1
- data/splittable.gemspec +5 -2
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb837f528d6f26ba39664a98ccc95671c5a30d0148f0f8d17ee840154c49cebb
|
4
|
+
data.tar.gz: cf4595a1d4c52fb03ad82c6d7dd12e34df852120901235ed7fad28141f7ddebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94ed8b8ca4ec6216a37a369e5d4efdb9e183b10cf6e6ed1d8a72f9482319ed28330550a7200e55948451e527f6674112188a530bcc718981546ec5ae34bb4036
|
7
|
+
data.tar.gz: 889f51d82f678fa595d201b18c5eefcc01af4422c4802499d1ff6ce7f1dfa5c5ca0c5069ae82a5ec27ad79b7996c4428f813c86b790df3b36224057956a7e906
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Publish Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
tags:
|
8
|
+
- v*
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
publish:
|
12
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
|
18
|
+
- name: Release Gem
|
19
|
+
uses: marcelotoledo5000/publish-rubygems-action@master
|
20
|
+
env:
|
21
|
+
GITHUB_TOKEN: ${{secrets.BUNDLE_GITHUB__COM}}
|
22
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_RELEASE}}
|
23
|
+
GIT_EMAIL: automated_release@useblu.com.br
|
24
|
+
GIT_NAME: 'Automated Release'
|
25
|
+
RELEASE_COMMAND: bundle exec rake release
|
data/.github/workflows/ruby.yml
CHANGED
@@ -10,24 +10,27 @@ on:
|
|
10
10
|
jobs:
|
11
11
|
build:
|
12
12
|
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
13
16
|
|
14
17
|
steps:
|
15
18
|
- uses: actions/checkout@v2
|
16
19
|
|
17
20
|
- name: Set up Ruby version specified in `.ruby-version`
|
18
21
|
with:
|
19
|
-
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
20
23
|
uses: eregon/use-ruby-action@master
|
21
24
|
|
22
25
|
- name: Install dependencies
|
23
26
|
run: bundle install --jobs 4 --retry 3
|
24
27
|
|
25
|
-
- name: Run
|
28
|
+
- name: Run tests with RSpec
|
26
29
|
env:
|
27
30
|
RAILS_ENV: test
|
28
|
-
run: bundle exec
|
31
|
+
run: bundle exec rspec
|
29
32
|
|
30
|
-
- name: Run
|
33
|
+
- name: Run Rubocop
|
31
34
|
env:
|
32
35
|
RAILS_ENV: test
|
33
|
-
run: bundle exec
|
36
|
+
run: bundle exec rubocop --config .rubocop.yml
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
## splittable 0.0.5 (Feb 02, 2021)
|
2
|
+
|
3
|
+
* Add precision parameter to division and normilize methods
|
4
|
+
|
5
|
+
*Ítalo Matos*
|
6
|
+
|
7
|
+
## splittable 0.0.4 (Jan 29, 2021)
|
8
|
+
|
9
|
+
* Fix publish_release job
|
10
|
+
|
11
|
+
*Marcelo Toledo*
|
12
|
+
|
13
|
+
## splittable 0.0.3 (Jan 29, 2021)
|
14
|
+
|
15
|
+
* Separate Division code
|
16
|
+
* Separate Normalize code
|
17
|
+
* Update actions to use ruby versions 2.5, 2.6 and 3.0
|
18
|
+
* Add a badge to README.md
|
19
|
+
* Updated some gems versions
|
20
|
+
|
21
|
+
*Eduardo Fiorezi, Marcelo Toledo*
|
22
|
+
|
23
|
+
## splittable 0.0.2 (Jan 25, 2021)
|
24
|
+
|
25
|
+
* Update description for rubygems.org
|
26
|
+
* Add rubgems badge to README.md
|
27
|
+
|
28
|
+
*Marcelo Toledo*
|
1
29
|
|
2
30
|
## splittable 0.0.1 (Jan 14, 2021)
|
3
31
|
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
splittable (0.0.
|
4
|
+
splittable (0.0.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
ast (2.4.
|
9
|
+
ast (2.4.2)
|
10
|
+
bigdecimal (3.0.0)
|
10
11
|
byebug (11.1.3)
|
11
12
|
coderay (1.1.3)
|
12
13
|
diff-lcs (1.4.4)
|
@@ -23,7 +24,7 @@ GEM
|
|
23
24
|
pry (~> 0.13.0)
|
24
25
|
rainbow (3.0.0)
|
25
26
|
rake (13.0.3)
|
26
|
-
regexp_parser (2.
|
27
|
+
regexp_parser (2.1.1)
|
27
28
|
rexml (3.2.4)
|
28
29
|
rspec (3.10.0)
|
29
30
|
rspec-core (~> 3.10.0)
|
@@ -34,11 +35,11 @@ GEM
|
|
34
35
|
rspec-expectations (3.10.1)
|
35
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
37
|
rspec-support (~> 3.10.0)
|
37
|
-
rspec-mocks (3.10.
|
38
|
+
rspec-mocks (3.10.2)
|
38
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
40
|
rspec-support (~> 3.10.0)
|
40
|
-
rspec-support (3.10.
|
41
|
-
rubocop (1.
|
41
|
+
rspec-support (3.10.2)
|
42
|
+
rubocop (1.11.0)
|
42
43
|
parallel (~> 1.10)
|
43
44
|
parser (>= 3.0.0.0)
|
44
45
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -47,14 +48,14 @@ GEM
|
|
47
48
|
rubocop-ast (>= 1.2.0, < 2.0)
|
48
49
|
ruby-progressbar (~> 1.7)
|
49
50
|
unicode-display_width (>= 1.4.0, < 3.0)
|
50
|
-
rubocop-ast (1.4.
|
51
|
+
rubocop-ast (1.4.1)
|
51
52
|
parser (>= 2.7.1.5)
|
52
|
-
rubocop-performance (1.
|
53
|
+
rubocop-performance (1.10.0)
|
53
54
|
rubocop (>= 0.90.0, < 2.0)
|
54
55
|
rubocop-ast (>= 0.4.0)
|
55
56
|
rubocop-rake (0.5.1)
|
56
57
|
rubocop
|
57
|
-
rubocop-rspec (2.
|
58
|
+
rubocop-rspec (2.2.0)
|
58
59
|
rubocop (~> 1.0)
|
59
60
|
rubocop-ast (>= 1.1.0)
|
60
61
|
ruby-progressbar (1.11.0)
|
@@ -70,6 +71,7 @@ PLATFORMS
|
|
70
71
|
ruby
|
71
72
|
|
72
73
|
DEPENDENCIES
|
74
|
+
bigdecimal (~> 3.0)
|
73
75
|
pry-byebug (~> 3.9)
|
74
76
|
rake (~> 13.0.3)
|
75
77
|
rspec (~> 3.10)
|
@@ -80,8 +82,5 @@ DEPENDENCIES
|
|
80
82
|
simplecov
|
81
83
|
splittable!
|
82
84
|
|
83
|
-
RUBY VERSION
|
84
|
-
ruby 2.6.6p146
|
85
|
-
|
86
85
|
BUNDLED WITH
|
87
|
-
2.2.
|
86
|
+
2.2.7
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Splittable
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/splittable.svg)](https://badge.fury.io/rb/splittable)
|
4
|
+
[![Ruby](https://github.com/Pagnet/splittable/workflows/Ruby/badge.svg?branch=master)](https://github.com/Pagnet/splittable/actions?query=workflow%3ARuby)
|
5
|
+
|
3
6
|
## Goal
|
4
7
|
|
5
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.
|
@@ -33,6 +36,17 @@ Result: the total truncated value was divided by the number of plots informed an
|
|
33
36
|
```ruby
|
34
37
|
=> [0.5e-1, 0.3e-1, 0.3e-1] # => [0.05, 0.03, 0.03]
|
35
38
|
```
|
39
|
+
Default precision is 2 decimal places, but, you can customize this with precision parameter:
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
Splittable.division(value: 10, quantity: 3, precision: 3)
|
43
|
+
```
|
44
|
+
|
45
|
+
Result:
|
46
|
+
```ruby
|
47
|
+
=> [0.3334e1, 0.3333e1, 0.3333e1] # => [0.334, 0.333, 0.333]
|
48
|
+
```
|
49
|
+
|
36
50
|
|
37
51
|
Using `normalize` method:
|
38
52
|
|
@@ -46,6 +60,16 @@ Result: all values are truncated and them the difference is attributed in the fi
|
|
46
60
|
=> [0.3524e2, 0.2143e2, 0.4333e2] # => [35.24, 21.43, 43.33]
|
47
61
|
```
|
48
62
|
|
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)
|
66
|
+
```
|
67
|
+
|
68
|
+
Result:
|
69
|
+
```ruby
|
70
|
+
=> [0.33334e2, 0.33333e2, 0.33333e2] # => [33.334, 33.333, 33.333]
|
71
|
+
```
|
72
|
+
|
49
73
|
## Development
|
50
74
|
|
51
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.
|
data/lib/splittable.rb
CHANGED
@@ -1,47 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'splittable/version'
|
4
|
+
require 'splittable/division'
|
5
|
+
require 'splittable/normalize'
|
4
6
|
require 'bigdecimal/util'
|
5
7
|
|
6
8
|
module Splittable
|
7
9
|
class << self
|
8
10
|
# receive total value and to quantity installments are required to equal division
|
9
11
|
# just the first installment will receive the difference cents
|
10
|
-
def division(value:, quantity:)
|
11
|
-
|
12
|
-
params_validation!(@quantity)
|
13
|
-
partial_value = (@value / @quantity).truncate(2)
|
14
|
-
decimal_difference = @value - (@quantity * partial_value)
|
15
|
-
installments = [partial_value] * @quantity
|
16
|
-
installments[0] += decimal_difference
|
17
|
-
|
18
|
-
installments
|
12
|
+
def division(value:, quantity:, precision: 2)
|
13
|
+
Splittable::Division.new(value: value, quantity: quantity, precision: precision).call
|
19
14
|
end
|
20
15
|
|
21
16
|
# receive total value and specific value of installments are required to specific division
|
22
17
|
# just the first installment will receive the difference cents
|
23
|
-
def normalize(value:, installments:)
|
24
|
-
|
25
|
-
decimal_difference = @value - @installments.sum
|
26
|
-
@installments[0] += decimal_difference
|
27
|
-
|
28
|
-
@installments
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_accessor :value, :quantity, :installments
|
34
|
-
|
35
|
-
def params_validation!(quantity)
|
36
|
-
return if quantity.positive?
|
37
|
-
|
38
|
-
raise ArgumentError, 'quantity should be positive'
|
39
|
-
end
|
40
|
-
|
41
|
-
def convert_params!(value: nil, quantity: nil, installments: nil)
|
42
|
-
@value = BigDecimal(value.truncate(2), 15) unless value.nil?
|
43
|
-
@quantity = BigDecimal(quantity.to_i, 15) unless quantity.nil?
|
44
|
-
@installments = installments.map { |installment| BigDecimal(installment.round(2), 15) } unless installments.nil?
|
18
|
+
def normalize(value:, installments:, precision: 2)
|
19
|
+
Splittable::Normalize.new(value: value, installments: installments, precision: precision).call
|
45
20
|
end
|
46
21
|
end
|
47
22
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Splittable::Division
|
4
|
+
def initialize(value:, quantity:, precision: 2)
|
5
|
+
@precision = precision
|
6
|
+
@value = BigDecimal(value, 15).truncate(precision)
|
7
|
+
@quantity = BigDecimal(quantity.to_i, 15)
|
8
|
+
|
9
|
+
check_quantity_as_positive_value!
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
partial_value = (value / quantity).truncate(precision)
|
14
|
+
installments = [partial_value] * quantity
|
15
|
+
installments[0] += value - installments.sum.to_d
|
16
|
+
|
17
|
+
installments
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :value, :quantity, :precision
|
23
|
+
|
24
|
+
def check_quantity_as_positive_value!
|
25
|
+
return if quantity.positive?
|
26
|
+
|
27
|
+
raise ArgumentError, 'quantity should be positive'
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Splittable::Normalize
|
4
|
+
def initialize(value:, installments:, precision: 2)
|
5
|
+
@value = BigDecimal(value, 15).truncate(precision)
|
6
|
+
@installments = installments.map { |installment| BigDecimal(installment.round(precision), 15) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
decimal_difference = value - installments.sum
|
11
|
+
installments[0] += decimal_difference
|
12
|
+
|
13
|
+
installments
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :value
|
19
|
+
attr_accessor :installments
|
20
|
+
end
|
data/lib/splittable/version.rb
CHANGED
data/splittable.gemspec
CHANGED
@@ -10,8 +10,11 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.license = 'MIT'
|
12
12
|
|
13
|
-
spec.summary = 'Calculate division and normalize parcels.'
|
14
|
-
spec.description = '
|
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.'
|
15
18
|
spec.homepage = 'https://github.com/Pagnet/splittable'
|
16
19
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.3')
|
17
20
|
|
metadata
CHANGED
@@ -1,17 +1,21 @@
|
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Brandão
|
8
8
|
- Marcelo Toledo
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01
|
12
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: |-
|
15
|
+
This gem solves the problem of several decimal places in divisions
|
16
|
+
where the result must be presented in cents, that is converting the
|
17
|
+
division result to only two decimal places and the difference is
|
18
|
+
attributed to the first plot.
|
15
19
|
email:
|
16
20
|
- arthur_aebc@hotmail.com
|
17
21
|
- marcelotoledo5000@gmail.com
|
@@ -23,6 +27,7 @@ files:
|
|
23
27
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
24
28
|
- ".github/ISSUE_TEMPLATE/security_vulnerability.md"
|
25
29
|
- ".github/PULL_REQUEST_TEMPLATE.md"
|
30
|
+
- ".github/workflows/publish_release.yml"
|
26
31
|
- ".github/workflows/ruby.yml"
|
27
32
|
- ".gitignore"
|
28
33
|
- ".rspec"
|
@@ -39,6 +44,8 @@ files:
|
|
39
44
|
- bin/console
|
40
45
|
- bin/setup
|
41
46
|
- lib/splittable.rb
|
47
|
+
- lib/splittable/division.rb
|
48
|
+
- lib/splittable/normalize.rb
|
42
49
|
- lib/splittable/version.rb
|
43
50
|
- sonar-project.properties
|
44
51
|
- splittable.gemspec
|
@@ -49,7 +56,7 @@ metadata:
|
|
49
56
|
homepage_uri: https://github.com/Pagnet/splittable
|
50
57
|
source_code_uri: https://github.com/Pagnet/splittable
|
51
58
|
changelog_uri: https://github.com/Pagnet/splittable/blob/master/CHANGELOG.md
|
52
|
-
post_install_message:
|
59
|
+
post_install_message:
|
53
60
|
rdoc_options: []
|
54
61
|
require_paths:
|
55
62
|
- lib
|
@@ -64,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
71
|
- !ruby/object:Gem::Version
|
65
72
|
version: '0'
|
66
73
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
74
|
+
rubygems_version: 3.1.4
|
75
|
+
signing_key:
|
69
76
|
specification_version: 4
|
70
|
-
summary: Calculate division and normalize parcels.
|
77
|
+
summary: Calculate division and normalize parcels to use just cents.
|
71
78
|
test_files: []
|