inss_calculator 0.2.0 → 0.3.1

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: 99650a459cf38cf5808305aa5bb4391627093ecf850a2e228467670d3fa00a8a
4
- data.tar.gz: 11515ca86f1827f58f457cf163a5ec451641432a4a21ad15f2016cf88f838c8c
3
+ metadata.gz: 930151d58edfe02aeb3b597a2b51b569cba243a6560c56a5d345869f498570ab
4
+ data.tar.gz: 665e637c5662127e28ddd1785fde22697f315f71954106b03a3d33d52b764ae7
5
5
  SHA512:
6
- metadata.gz: e1125652fa665658f4fd091a1d4ac9722ead666ebfda59d652d64872cad95c16820c0d5d1deb7c901c29f77f93b16fc59d34805c1873cfb69d1284bbb62131bc
7
- data.tar.gz: '0793f8defcdffd87c0e58c225f94c7331269430a6b2e83fe506271ef3799ff2d822498e75a4686d736b04fb9a65d2365b447ec18ff99d2d0606dd46062649e0f'
6
+ metadata.gz: ca58062897e260e5c1c4e8863d95f16d9cbc9179645119ecdf5bd7b3af1d1b279577cf8b7602a0ad2292b496b095c0431123725f5b904aef639b8bff1ff75c28
7
+ data.tar.gz: 4a8f8ef91bbab45fc4dd03b3169a962d98a075dfed9ddc90f2c681ec66f1e43fb6a231712e8b54188d62be2b4c224bac2206df8e9bfeb2d6d29c810699b05014
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.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -19,6 +19,30 @@ calculator.contribution => 258.81
19
19
  calculator.salary => 3000.0
20
20
  calculator.net_salary => 2741.19
21
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
+ ```
22
46
 
23
47
  ## Nota sobre trabalhar com números decimais em Ruby
24
48
 
@@ -15,11 +15,11 @@ module InssCalculator
15
15
  SecondDiscountCalculator.new(salary).contribution,
16
16
  ThirdDiscountCalculator.new(salary).contribution,
17
17
  FourthDiscountCalculator.new(salary).contribution
18
- ].reduce(:+).truncate(2)
18
+ ].reduce(:+).round(2)
19
19
  end
20
20
 
21
21
  def net_salary
22
- salary - contribution
22
+ (salary - contribution).round(2)
23
23
  end
24
24
  end
25
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.2.0'
4
+ VERSION = '0.3.1'
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.2.0
4
+ version: 0.3.1
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-07-02 00:00:00.000000000 Z
11
+ date: 2024-07-09 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.