formulas 0.1.1.1 → 0.1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05cc76051c2d5ff9889d39b8448fe5b1b5fabdb60703b9b4c1afd9a58aa72a87
4
- data.tar.gz: 01213c4a728219396108c266d8b4398d28829140957c4fb7e957ee401e20fd51
3
+ metadata.gz: 36695f1d8737ac436e8dec2608a6f420cac392360bfd7b45fe95fcb1363aefe0
4
+ data.tar.gz: d1e786d718f025ed8e424e454f25ba9dda392c25d8500a6b0d3a67ec7506ffcc
5
5
  SHA512:
6
- metadata.gz: 948b740e1a3e8965ab9991fdcf448081dfe896ff71fbd2f4f7fda2a98c356f37d2c741ef14ca19330168d5d93d211383659f1551fe0cc50b7bac74e5d5fde8bd
7
- data.tar.gz: 8bc92d9ea8b509ce304afaeabfdf4db5d443d4a0a542ca8e4ffb34f71652fdec9f79941a3028df5096647a93c57c6c7937e6ea5d953fae82bb4fb8fe3e5e673a
6
+ metadata.gz: b51a1482c97eaab4ee7eddd9d386e3e5f3eae378b1b4dc340af7cd8697eaa72a6175b26dd80c8c2e95c62e61421a2ee262ad6e5fb0ea3ec01bdfb6be77c77260
7
+ data.tar.gz: 80776734b000a0972c8272f58698f6a5130edd96c1596146753e8f40fd094312631a25aafbb7d7f23b84720c984ffa1bdb1552326550dc9cbdc25248fecec6aa
data/formulas.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'formulas'
3
- s.version = '0.1.1.1'
3
+ s.version = '0.1.1.2'
4
4
  s.summary = "formulas"
5
5
  s.description = "Home loan formulas"
6
6
  s.authors = ["formulas"]
data/lib/formulas.rb CHANGED
@@ -25,6 +25,13 @@ module Formulas
25
25
  FREQUENCIES = [ANNUALLY, WEEKLY, FORTNIGHTLY, MONTHLY]
26
26
 
27
27
  module FrequencyConversions
28
+ def convert_annually_to_annually(number)
29
+ number
30
+ end
31
+ alias :convert_weekly_to_weekly convert_annually_to_annually
32
+ alias :convert_fortnightly_to_fortnightly convert_annually_to_annually
33
+ alias :convert_monthly_to_monthly convert_annually_to_annually
34
+
28
35
  def convert_annually_to_weekly(number)
29
36
  number.to_f / 52
30
37
  end
@@ -60,5 +67,17 @@ module Formulas
60
67
  def convert_monthly_to_fortnightly(number)
61
68
  number.to_f * 12 / 26
62
69
  end
70
+
71
+ def convert_fortnightly_to_annually(number)
72
+ number.to_f * 26
73
+ end
74
+
75
+ def convert_fortnightly_to_weekly(number)
76
+ number.to_f / 2
77
+ end
78
+
79
+ def convert_fortnightly_to_monthly(number)
80
+ (number.to_f * 26) / 12
81
+ end
63
82
  end
64
83
  end
data/lib/formulas/paye.rb CHANGED
@@ -26,5 +26,9 @@ module Formulas
26
26
  def tax(request_frequency: Formulas::WEEKLY)
27
27
  calculate_tax(request_frequency)
28
28
  end
29
+
30
+ def levy
31
+ 0.0139
32
+ end
29
33
  end
30
34
  end
@@ -16,11 +16,11 @@ module Formulas
16
16
  attr_reader :frequency
17
17
 
18
18
  def initialize(pay:, frequency:)
19
- invalid_frequency unless FREQUENCIES.include?(frequency)
20
- raise ArgumentError, 'Gross pay must be numeric' unless Numeric === pay
21
-
22
19
  @pay = pay
23
- @frequency = frequency
20
+ @frequency = frequency.to_sym
21
+
22
+ invalid_frequency unless FREQUENCIES.include?(@frequency)
23
+ raise ArgumentError, 'Gross pay must be numeric' unless Numeric === pay
24
24
  end
25
25
 
26
26
  def pay(request_frequency: @frequency)
@@ -15,9 +15,9 @@ module Formulas
15
15
  #
16
16
  #
17
17
  module StudentLoanRepayment
18
- autoload :RepaymentBase, './lib/formulas/student_loan_repayment/repayment_base'
19
- autoload :FixRepaymentPerPeriod, './lib/formulas/student_loan_repayment/fix_repayment_per_period'
20
- autoload :PercentRepaymentPerThreshold, './lib/formulas/student_loan_repayment/percent_repayment_per_threshold'
18
+ autoload :RepaymentBase, 'formulas/student_loan_repayment/repayment_base'
19
+ autoload :FixRepaymentPerPeriod, 'formulas/student_loan_repayment/fix_repayment_per_period'
20
+ autoload :PercentRepaymentPerThreshold, 'formulas/student_loan_repayment/percent_repayment_per_threshold'
21
21
  attr_reader :repayment
22
22
 
23
23
  def initialize(income_strategy: , repayment_strategy:, rates:)
@@ -12,11 +12,11 @@ module Formulas
12
12
  FIX_RATE = 0.12
13
13
 
14
14
  DEFAULT_THRESHOLD = {
15
- weekly: [390, 52],
16
- fortnightly: [780, 26],
17
- four_weeks: [1560, 13],
18
- monthly: [1690, 12],
19
- annually: [20280, 1],
15
+ weekly: [390, 52],
16
+ fortnightly: [780, 26],
17
+ four_weeks: [1560, 13],
18
+ monthly: [1690, 12],
19
+ annually: [20280, 1],
20
20
  }
21
21
 
22
22
  def repayment
@@ -4,18 +4,32 @@ module Formulas
4
4
  class WithholdingTax
5
5
  include FrequencyConversions
6
6
 
7
+ attr_reader :origin_frequency
8
+
7
9
  def initialize(gross_pay, origin_frequency, tax_rate)
8
10
  @gross_pay = gross_pay
9
11
  @origin_frequency = origin_frequency
10
12
  @tax_rate = tax_rate
11
13
  end
12
14
 
15
+ def net_pay(request_frequency:)
16
+ annual_pay_after_tax = annual_gross_pay - calculate_tax(Formulas::ANNUALLY)
17
+
18
+ if respond_to?(:levy)
19
+ net_pay = annual_pay_after_tax - (annual_gross_pay * send(:levy))
20
+ end
21
+
22
+ return net_pay if request_frequency.to_s == Formulas::ANNUALLY.to_s
23
+
24
+ send("convert_annually_to_#{request_frequency}", net_pay).round(2)
25
+ end
26
+
13
27
  protected
14
28
 
15
29
  def calculate_tax(request_frequency)
16
30
  @request_frequency = request_frequency
17
31
 
18
- return annual_tax if request_frequency == Formulas::ANNUALLY
32
+ return annual_tax if request_frequency.to_s == Formulas::ANNUALLY.to_s
19
33
 
20
34
  send("convert_annually_to_#{request_frequency}", annual_tax).round(2)
21
35
  end
@@ -27,7 +41,7 @@ module Formulas
27
41
 
28
42
  if gross_pay_tax_index > 0
29
43
  @tax_rate[0..gross_pay_tax_index].each_with_index do |current, index|
30
- l = (index == gross_pay_tax_index) ? @gross_pay : current[0][1]
44
+ l = (index == gross_pay_tax_index) ? annual_gross_pay : current[0][1]
31
45
  annual_result += ((l - current[0][0]) * (current[1].to_f / 100))
32
46
  end
33
47
  end
@@ -35,7 +49,7 @@ module Formulas
35
49
  end
36
50
 
37
51
  def annual_gross_pay
38
- return @gross_pay if @origin_frequency == Formulas::ANNUALLY
52
+ return @gross_pay if @origin_frequency.to_s == Formulas::ANNUALLY.to_s
39
53
  send("convert_#{@origin_frequency}_to_annually", @gross_pay)
40
54
  end
41
55
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formulas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.1
4
+ version: 0.1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - formulas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-28 00:00:00.000000000 Z
11
+ date: 2021-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest