compound_interest 0.1.0 → 0.1.2

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: adf78a6367fa405f9122ffc009a83a22c133628e184add4f93b414ab41a097fa
4
- data.tar.gz: f6ac5b2d30cdae713cbf722bc6db16d7b37ceb6a396f05efeb052ddd422eb7fc
3
+ metadata.gz: df8b81354e52c9ac8a615c7cf146f44474e0d8f7447857490a751c429528f962
4
+ data.tar.gz: e2f75bcff6ea663f7b7588add3b4542cc9a6d4808ba9cf69ec36400627a34716
5
5
  SHA512:
6
- metadata.gz: fb6bc286299633f0ff66c8341e14e162a57c2a54ceb94910a1131591fc3737809af1b482c281b17ac3ed73f56c6e07b0281d32c9fe2f45f0786077c7c88c29c9
7
- data.tar.gz: 119b5909e7e5a74c5d7f09c7931299dbef370be52baa594493736c9a3f6f5e6bfd5d4a1bfa08bb4ecc0dc26b300082da75e66851ce7e193c0f29a2006f71510b
6
+ metadata.gz: 6b72066feb74abeb0981ca3a933d2f59480f2ea1bc0a90fe5eab2ee5d0f6ec7fd32f6f40068543525c8a2f58dc3a330545ce60e9b71b667a07a09aa52463d3f0
7
+ data.tar.gz: 3c769c1b2f69f54167850675c6a7109ac864fd573789841cf7094c7beeea21afb32bada54dc6cf1ce7d0eff5ff83f579968ff65fd4e66be9159956b7dac48855
data/.rubocop.yml CHANGED
@@ -1,5 +1,8 @@
1
+ require: rubocop-rake
2
+
1
3
  AllCops:
2
4
  TargetRubyVersion: 2.5
5
+ NewCops: enable
3
6
 
4
7
  Style/StringLiterals:
5
8
  Enabled: true
@@ -8,7 +11,7 @@ Style/StringLiterals:
8
11
  Style/StringLiteralsInInterpolation:
9
12
  Enabled: true
10
13
  EnforcedStyle: double_quotes
11
-
14
+
12
15
  Style/Documentation:
13
16
  Enabled: false
14
17
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compound_interest (0.1.0)
4
+ compound_interest (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -39,6 +39,11 @@ GEM
39
39
  unicode-display_width (>= 1.4.0, < 3.0)
40
40
  rubocop-ast (1.5.0)
41
41
  parser (>= 3.0.1.1)
42
+ rubocop-rake (0.5.1)
43
+ rubocop
44
+ rubocop-rspec (2.3.0)
45
+ rubocop (~> 1.0)
46
+ rubocop-ast (>= 1.1.0)
42
47
  ruby-progressbar (1.11.0)
43
48
  unicode-display_width (2.0.0)
44
49
 
@@ -51,6 +56,8 @@ DEPENDENCIES
51
56
  rake (~> 13.0)
52
57
  rspec (~> 3.0)
53
58
  rubocop (~> 1.7)
59
+ rubocop-rake (~> 0.5)
60
+ rubocop-rspec (~> 2.3)
54
61
 
55
62
  BUNDLED WITH
56
63
  2.2.17
data/README.md CHANGED
@@ -25,8 +25,11 @@ Or install it yourself as:
25
25
  In order to calculate compound interest, add this lines to your project:
26
26
  ```ruby
27
27
  require "compound_interest"
28
-
28
+ ```
29
+ ```ruby
29
30
  compound_interest = CompoundInterest::Calculation
31
+ ```
32
+ ```ruby
30
33
  compound_interest.calculate(params)
31
34
  ```
32
35
  method .calculate accept Hash like this:
@@ -31,6 +31,8 @@ Gem::Specification.new do |spec|
31
31
  # Uncomment to register a new dependency of your gem
32
32
  # spec.add_dependency "example-gem", "~> 1.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.2"
34
+ spec.add_development_dependency "rubocop-rake", "~> 0.5"
35
+ spec.add_development_dependency "rubocop-rspec", "~> 2.3"
34
36
 
35
37
  # For more information and examples about making a new gem, checkout our
36
38
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,39 +1,54 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CompoundInterest
2
4
  class Calculation
3
5
  def self.calculate(params)
4
- raise "Argument must be Hash" if params.class != Hash
5
- if params[:initial_payment].nil?
6
- raise ArgumentError, "Argument must include :initial_payment"
7
- elsif params[:term].nil?
8
- raise ArgumentError, "Argument must include :term"
9
- elsif params[:interest_rate].nil?
10
- raise ArgumentError, "Argument must include :interest_rate"
11
- elsif [:capitalization_periodicity].nil?
12
- raise ArgumentError, "Argument must include :capitalization_periodicity"
13
- end
6
+ raise_error(params)
14
7
 
15
- initial_payment = params[:initial_payment]
8
+ @initial_payment = params[:initial_payment]
16
9
  # number of terms
17
- term = params[:term]
18
- # ineterest rate per term
19
- interest_rate = params[:interest_rate].to_f / 100
10
+ @term = params[:term]
11
+ # interest rate per term
12
+ @interest_rate = params[:interest_rate].to_f / 100
20
13
  # number of interest payments for the term
21
- capitalization_periodicity = params[:capitalization_periodicity]
22
- payment = params[:payment] || 0
14
+ @capitalization_periodicity = params[:capitalization_periodicity]
15
+ @payment = params[:payment] || 0
23
16
  # number of payments for the term
24
- payment_periodicity = params[:payment_periodicity]
17
+ @payment_periodicity = params[:payment_periodicity]
25
18
 
26
- calculation = (1.0 + interest_rate / capitalization_periodicity)**(term * capitalization_periodicity)
27
- result = initial_payment * calculation
28
- if payment > 0
29
- times = (payment_periodicity * term).to_i
30
- payment_result = 0
31
- (1..times).each do |i|
32
- payment_result += payment * calculation - ((capitalization_periodicity / payment_periodicity) * i)
33
- end
34
- result = result + payment_result - payment
35
- end
36
19
  result
37
20
  end
21
+
22
+ def self.result
23
+ result = @initial_payment * compound_interest_formula
24
+ result = periodical_payment_calculation if @payment.positive?
25
+ result
26
+ end
27
+
28
+ def self.periodical_payment_calculation
29
+ times = (@payment_periodicity * @term).to_i
30
+ payment_result = 0
31
+ (1..times).each do |i|
32
+ payment_result += @payment * compound_interest_formula(i)
33
+ end
34
+ payment_result
35
+ end
36
+
37
+ def self.compound_interest_formula(num = 0)
38
+ if num.zero?
39
+ (1.0 + @interest_rate / @capitalization_periodicity)**(@term * @capitalization_periodicity)
40
+ else
41
+ (1.0 + @interest_rate / @capitalization_periodicity)**((@term * @capitalization_periodicity) -
42
+ (@capitalization_periodicity / @payment_periodicity * num))
43
+ end
44
+ end
45
+
46
+ def self.raise_error(params)
47
+ raise "Argument must be Hash" if params.class != Hash
48
+ raise ArgumentError, "Argument must include :initial_payment" if params[:initial_payment].nil?
49
+ raise ArgumentError, "Argument must include :term" if params[:term].nil?
50
+ raise ArgumentError, "Argument must include :interest_rate" if params[:interest_rate].nil?
51
+ raise ArgumentError, "Argument must include :capitalization_periodicity" if [:capitalization_periodicity].nil?
52
+ end
38
53
  end
39
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompoundInterest
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compound_interest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - VovaK0-23
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
27
55
  description:
28
56
  email:
29
57
  - 71105454+VovaK0-23@users.noreply.github.com