splittable 0.0.2 → 0.0.3

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: 833ea6cdda26baeca68d106309a33f14b4d74e65455c3435325c38763b192634
4
- data.tar.gz: e9b7541a8c607ef61391d0df865153fa2ed7e5096a8d7a549f27203c34a5c67e
3
+ metadata.gz: 9f9785e87a5381e8601e2c63b84d374222701bbfafeec4ba879a671fca0d9334
4
+ data.tar.gz: e5c9df2e54ff33850e2efec6dcd766dc611509f5a5db5be1fbe2d40ddefb34d0
5
5
  SHA512:
6
- metadata.gz: b34f0da34a89af96d72927ae40e0c12dc35bd11de7b8f5ca9003973bfb557e23ec29b6b6b0cdcd7f349c708730440205df816500431de81fd1fddeb0240a3fe0
7
- data.tar.gz: 3353de9bba0f637aede703abe8cceacb597632f661430ba337a8fad541293b821567bce9c34a313dd99dc8e43afbd9f9ef5243c51e13f4c3ddde0a6034cb8a66
6
+ metadata.gz: c8b7795e1266f819dd59b10532b0c981f04568a7bac3162a48e5d43384ef083d84322ab2639aa704eb26f7687d472f5d47489de15a2c550a8a5cf2405542184e
7
+ data.tar.gz: c6f575e57453fcf85d2b2c98accd8a3f4bfc969f73c8f0e19dbbef950e134f658c8904b413f65c37489c6ecdcda8cb234008db5ed24ba822090d385fc2d2a634
@@ -0,0 +1,22 @@
1
+ name: Publish Gem
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ tags:
8
+ - v*
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+
16
+ - name: Release Gem
17
+ if: contains(github.ref, 'refs/tags/v')
18
+ uses: cadwallion/publish-rubygems-action@master
19
+ env:
20
+ GITHUB_TOKEN: ${{secrets.BUNDLE_GITHUB__COM}}
21
+ RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_RELEASE}}
22
+ RELEASE_COMMAND: bundle exec rake release
@@ -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
- ruby-version: 2.6.6
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 Rubocop
28
+ - name: Run tests with RSpec
26
29
  env:
27
30
  RAILS_ENV: test
28
- run: bundle exec rubocop --config .rubocop.yml
31
+ run: bundle exec rspec
29
32
 
30
- - name: Run tests with RSpec
33
+ - name: Run Rubocop
31
34
  env:
32
35
  RAILS_ENV: test
33
- run: bundle exec rspec
36
+ run: bundle exec rubocop --config .rubocop.yml
@@ -1 +1 @@
1
- 2.6.6
1
+ 3.0.0
@@ -1,3 +1,13 @@
1
+ ## splittable 0.0.3 (Jan 29, 2021)
2
+
3
+ * Separate Division code
4
+ * Separate Normalize code
5
+ * Update actions to use ruby versions 2.5, 2.6 and 3.0
6
+ * Add badge to README.md
7
+ * Updated some gems versions
8
+
9
+ *Eduardo Fiorezi, Marcelo Toledo*
10
+
1
11
  ## splittable 0.0.2 (Jan 25, 2021)
2
12
 
3
13
  * Update description for rubygems.org
data/Gemfile CHANGED
@@ -2,10 +2,9 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- ruby '2.6.6'
6
-
7
5
  gemspec
8
6
 
7
+ gem 'bigdecimal', '~> 3.0'
9
8
  gem 'pry-byebug', '~> 3.9'
10
9
  gem 'rake', '~> 13.0.3'
11
10
  gem 'rspec', '~> 3.10'
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splittable (0.0.2)
4
+ splittable (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.1)
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)
@@ -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.1)
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.1)
41
- rubocop (1.8.1)
41
+ rspec-support (3.10.2)
42
+ rubocop (1.9.0)
42
43
  parallel (~> 1.10)
43
44
  parser (>= 3.0.0.0)
44
45
  rainbow (>= 2.2.2, < 4.0)
@@ -47,7 +48,7 @@ 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.0)
51
+ rubocop-ast (1.4.1)
51
52
  parser (>= 2.7.1.5)
52
53
  rubocop-performance (1.9.2)
53
54
  rubocop (>= 0.90.0, < 2.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.5
86
+ 2.2.7
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Splittable
2
2
 
3
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)
4
5
 
5
6
  ## Goal
6
7
 
@@ -1,6 +1,8 @@
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
@@ -8,40 +10,13 @@ module Splittable
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
12
  def division(value:, quantity:)
11
- convert_params!(value: value, quantity: quantity)
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
13
+ Splittable::Division.new(value: value, quantity: quantity).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
18
  def normalize(value:, installments:)
24
- convert_params!(value: value, installments: installments)
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?
19
+ Splittable::Normalize.new(value: value, installments: installments).call
45
20
  end
46
21
  end
47
22
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Splittable::Division
4
+ def initialize(value:, quantity:)
5
+ @value = BigDecimal(value, 15).truncate(2)
6
+ @quantity = BigDecimal(quantity.to_i, 15)
7
+
8
+ check_quantity_as_positive_value!
9
+ end
10
+
11
+ def call
12
+ partial_value = (value / quantity).truncate(2)
13
+ installments = [partial_value] * quantity
14
+ installments[0] += value - installments.sum.to_d
15
+
16
+ installments
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :value, :quantity
22
+
23
+ def check_quantity_as_positive_value!
24
+ return if quantity.positive?
25
+
26
+ raise ArgumentError, 'quantity should be positive'
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Splittable::Normalize
4
+ def initialize(value:, installments:)
5
+ @value = BigDecimal(value, 15).truncate(2)
6
+ @installments = installments.map { |installment| BigDecimal(installment.round(2), 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Splittable
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Brandão
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-01-25 00:00:00.000000000 Z
12
+ date: 2021-01-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |-
15
15
  This gem solves the problem of several decimal places in divisions
@@ -27,6 +27,7 @@ files:
27
27
  - ".github/ISSUE_TEMPLATE/feature_request.md"
28
28
  - ".github/ISSUE_TEMPLATE/security_vulnerability.md"
29
29
  - ".github/PULL_REQUEST_TEMPLATE.md"
30
+ - ".github/workflows/publish_release.yml"
30
31
  - ".github/workflows/ruby.yml"
31
32
  - ".gitignore"
32
33
  - ".rspec"
@@ -43,6 +44,8 @@ files:
43
44
  - bin/console
44
45
  - bin/setup
45
46
  - lib/splittable.rb
47
+ - lib/splittable/division.rb
48
+ - lib/splittable/normalize.rb
46
49
  - lib/splittable/version.rb
47
50
  - sonar-project.properties
48
51
  - splittable.gemspec
@@ -68,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0'
70
73
  requirements: []
71
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.2.3
72
75
  signing_key:
73
76
  specification_version: 4
74
77
  summary: Calculate division and normalize parcels to use just cents.