inss_calculator 0.1.0 → 0.3.0

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: '081930097824d4c7e1e4efcf7c5a6c7990d9924623aa7ec639bd336a117ef5c1'
4
- data.tar.gz: b8e8198725de7d98ea26d3cef88a67686264237e64c6f009db56c4893bdc092a
3
+ metadata.gz: e12311e6e06783b04c8602f840b94674b7fbb935a20c86c302de4c3801d899fd
4
+ data.tar.gz: 8798314565756151e4821114d5c27dde36c33285eb453cb59a6e84c6ecc66530
5
5
  SHA512:
6
- metadata.gz: f1cd887972ba503b1ceb5e944b185b19fa1d6bad72e5796643bdcb8328a2831a5d87ae7797105d99c0bd6d31998c65be6d76cae72a9afc3e5c79e56567ce4120
7
- data.tar.gz: 1b2891ffac9e28121aafd6253eda8f89a6b53db2dba71ec2c0cb5699e4110679ea8821d65293727ccd4f2ab7ac8c433758bcbf2928e8b9c6179429088ac66b94
6
+ metadata.gz: 48c832e1fb4bc2543b72bb9f78f87fbb98eb6a0dc129b9c927422da978bfff8f688f9f45587630887a5be9fded9a8c2ee5267eee929d28e0309b1d0e0be8dad8
7
+ data.tar.gz: 695c126b9665d5efb414f9c7b8e1339394e6798b2ecb40cb5b20b6120e447129217ceca69bc5e5b16a42bf9faf47fa193c1b2bdb92c6ca12548353a3ff94cbe9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- inss_calculator (0.1.0)
4
+ inss_calculator (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1 +1,58 @@
1
1
  # InssCalculator
2
+
3
+ Calculadora do desconto do INSS sobre o salário bruto 2024
4
+
5
+ ## Instalation
6
+
7
+ ```
8
+ bundle add inss_calculator
9
+ ```
10
+
11
+ Não conhecia [esse comando?](https://bundler.io/v2.5/man/bundle-add.1.html) Ele adiciona ao seu Gemfile a gem e ainda a instala.
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ gross_salary = 3000
17
+ calculator = InssCalculator::DiscountPrevidenceCalculator.new(gross_salary)
18
+ calculator.contribution => 258.81
19
+ calculator.salary => 3000.0
20
+ calculator.net_salary => 2741.19
21
+ ```
22
+ ### Precisas realizar uma query ao Banco de Dados por grupo de faixa salarial?
23
+
24
+ InssCalculator providencia as seguintes constantes:
25
+
26
+ ```
27
+ InssCalculator::FIRST_SALARY_BASE = 0.0
28
+ InssCalculator::FIRST_SALARY_LIMIT = 1412.0
29
+
30
+ InssCalculator::SECOND_SALARY_BASE = 1412.01
31
+ InssCalculator::SECOND_SALARY_LIMIT = 2666.68
32
+
33
+ InssCalculator::THIRD_SALARY_BASE = 2666.69
34
+ InssCalculator::THIRD_SALARY_LIMIT = 4000.03
35
+
36
+ InssCalculator::FOURTH_SALARY_BASE = 4000.04
37
+ InssCalculator::FOURTH_SALARY_LIMIT = 7786.02
38
+
39
+ ```
40
+
41
+ Desta forma, uma requisição que busca somente a primeira faixa salarial seria:
42
+
43
+ ```
44
+ YourModel.where("salary <= ?", InssCalculator::FIRST_SALARY_LIMIT)
45
+ ```
46
+
47
+ ## Nota sobre trabalhar com números decimais em Ruby
48
+
49
+ Após investigar os resultados dos exemplos contábeis, concluiu-se que os números são truncados.
50
+
51
+ Cada faixa salarial trunca seu resultado final após aplicar a sua alíquota correspondente.
52
+
53
+ Por isso o uso do método `.truncate` ao invés de um arredondamento ao final de cada cálculo parcial.
54
+
55
+ Para mais detalhes, veja a regra e o exemplo [deste site](https://www.contabilizei.com.br/contabilidade-online/desconto-inss/)
56
+
57
+
58
+ ### Feito com amor, feito com Ruby S2
@@ -17,5 +17,9 @@ module InssCalculator
17
17
  FourthDiscountCalculator.new(salary).contribution
18
18
  ].reduce(:+).truncate(2)
19
19
  end
20
+
21
+ def net_salary
22
+ salary - contribution
23
+ end
20
24
  end
21
25
  end
@@ -5,14 +5,29 @@ module InssCalculator
5
5
  # In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
6
6
  class FirstDiscountCalculator < DiscountCalculatorBase
7
7
  QUOTATION = 0.075
8
- SALARY_BASE = 0.00
9
- SALARY_LIMIT = 1412.0
10
- FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
11
8
 
12
9
  def contribution
13
- return FULL_CONTRIBUTION if salary > SALARY_LIMIT
10
+ return full_contribution if salary > salary_limit
14
11
 
15
- (salary * QUOTATION).truncate(2)
12
+ calculate_contribution
13
+ end
14
+
15
+ private
16
+
17
+ def calculate_contribution
18
+ ((salary - salary_base) * QUOTATION).truncate(2)
19
+ end
20
+
21
+ def full_contribution
22
+ ((salary_limit - salary_base) * QUOTATION).truncate(2)
23
+ end
24
+
25
+ def salary_limit
26
+ InssCalculator::FIRST_SALARY_LIMIT
27
+ end
28
+
29
+ def salary_base
30
+ InssCalculator::FIRST_SALARY_BASE
16
31
  end
17
32
  end
18
33
  end
@@ -5,16 +5,31 @@ module InssCalculator
5
5
  # In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
6
6
  class FourthDiscountCalculator < DiscountCalculatorBase
7
7
  QUOTATION = 0.14
8
- SALARY_BASE = 4000.04
9
- SALARY_LIMIT = 7786.02
10
- FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
11
8
 
12
9
  def contribution
13
- return NO_CONTRIBUTION if salary <= SALARY_BASE
10
+ return NO_CONTRIBUTION if salary < salary_base
14
11
 
15
- return FULL_CONTRIBUTION if salary > SALARY_LIMIT
12
+ return full_contribution if salary > salary_limit
16
13
 
17
- ((salary - SALARY_BASE) * QUOTATION).truncate(2)
14
+ calculate_contribution
15
+ end
16
+
17
+ private
18
+
19
+ def calculate_contribution
20
+ ((salary - salary_base) * QUOTATION).truncate(2)
21
+ end
22
+
23
+ def full_contribution
24
+ ((salary_limit - salary_base) * QUOTATION).truncate(2)
25
+ end
26
+
27
+ def salary_limit
28
+ InssCalculator::FOURTH_SALARY_LIMIT
29
+ end
30
+
31
+ def salary_base
32
+ InssCalculator::FOURTH_SALARY_BASE
18
33
  end
19
34
  end
20
35
  end
@@ -5,16 +5,31 @@ module InssCalculator
5
5
  # In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
6
6
  class SecondDiscountCalculator < DiscountCalculatorBase
7
7
  QUOTATION = 0.09
8
- SALARY_BASE = 1412.0
9
- SALARY_LIMIT = 2666.68
10
- FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
11
8
 
12
9
  def contribution
13
- return NO_CONTRIBUTION if salary <= SALARY_BASE
10
+ return NO_CONTRIBUTION if salary < salary_base
14
11
 
15
- return FULL_CONTRIBUTION if salary > SALARY_LIMIT
12
+ return full_contribution if salary > salary_limit
16
13
 
17
- ((salary - SALARY_BASE) * QUOTATION).truncate(2)
14
+ calculate_contribution
15
+ end
16
+
17
+ private
18
+
19
+ def calculate_contribution
20
+ ((salary - salary_base) * QUOTATION).truncate(2)
21
+ end
22
+
23
+ def full_contribution
24
+ ((salary_limit - salary_base) * QUOTATION).truncate(2)
25
+ end
26
+
27
+ def salary_limit
28
+ InssCalculator::SECOND_SALARY_LIMIT
29
+ end
30
+
31
+ def salary_base
32
+ InssCalculator::SECOND_SALARY_BASE
18
33
  end
19
34
  end
20
35
  end
@@ -5,16 +5,31 @@ module InssCalculator
5
5
  # In case the salary is beyond this limit, it will use its quotation apply inside the range salary limit
6
6
  class ThirdDiscountCalculator < DiscountCalculatorBase
7
7
  QUOTATION = 0.12
8
- SALARY_BASE = 2666.68
9
- SALARY_LIMIT = 4000.03
10
- FULL_CONTRIBUTION = ((SALARY_LIMIT - SALARY_BASE) * QUOTATION).truncate(2)
11
8
 
12
9
  def contribution
13
- return NO_CONTRIBUTION if salary <= SALARY_BASE
10
+ return NO_CONTRIBUTION if salary < salary_base
14
11
 
15
- return FULL_CONTRIBUTION if salary > SALARY_LIMIT
12
+ return full_contribution if salary > salary_limit
16
13
 
17
- ((salary - SALARY_BASE) * QUOTATION).truncate(2)
14
+ calculate_contribution
15
+ end
16
+
17
+ private
18
+
19
+ def calculate_contribution
20
+ ((salary - salary_base) * QUOTATION).truncate(2)
21
+ end
22
+
23
+ def full_contribution
24
+ ((salary_limit - salary_base) * QUOTATION).truncate(2)
25
+ end
26
+
27
+ def salary_limit
28
+ InssCalculator::THIRD_SALARY_LIMIT
29
+ end
30
+
31
+ def salary_base
32
+ InssCalculator::THIRD_SALARY_BASE
18
33
  end
19
34
  end
20
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InssCalculator
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -11,4 +11,15 @@ require_relative 'inss_calculator/fourth_discount_calculator'
11
11
  module InssCalculator
12
12
  class Error < StandardError; end
13
13
  # Your code goes here...
14
+ FIRST_SALARY_BASE = 0.0
15
+ FIRST_SALARY_LIMIT = 1412.0
16
+
17
+ SECOND_SALARY_BASE = 1412.01
18
+ SECOND_SALARY_LIMIT = 2666.68
19
+
20
+ THIRD_SALARY_BASE = 2666.69
21
+ THIRD_SALARY_LIMIT = 4000.03
22
+
23
+ FOURTH_SALARY_BASE = 4000.04
24
+ FOURTH_SALARY_LIMIT = 7786.02
14
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inss_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Felipe Souza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-27 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Calcula o valor a descontar de acordo com a faixa salarial. Os novos
14
14
  valores corrente em 2024.