compounding 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eaada2a3507d635e5b87e25b806f8981726c9af90ca80d629f7d96f3134cea33
4
+ data.tar.gz: 6e82ae3325750f2d7c380ee196786321c60dc52e64f824381d3e58780ea4a593
5
+ SHA512:
6
+ metadata.gz: 2b25856e5e1215ee621bd86cb10ac9923a816eab70fb956f7b55014f967d21c9b060f50b9aeddb85ea958f2936b9bcebc4279ea0b7d2dc23e5c2a4ce3430aef4
7
+ data.tar.gz: 4fc66e073af3973039489bf055133c725bfd9fc0a3a9a57f4feac60a26a3bd90b92c01e52dfb9e121415db72ab142ad3a424966f07b455686a0ade043e0db3d0
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-02-25
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Jason Kim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Compounding
2
+
3
+
4
+ A Ruby Gem for calculating compound interest
5
+
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add compounding
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install compounding
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ calculation_result = Compounding::Calculator.calculate(principal, rate, time, compounding_frequency)
21
+ ```
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/serv/compounding.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,34 @@
1
+ module Compounding
2
+ class CalculationResult
3
+ attr_reader :principal, :rate, :time, :compounding_frequency, :periods, :interest, :total
4
+
5
+ # time can be any unit of time, e.g. years, months, days, etc.
6
+ def initialize(principal, rate, time, compounding_frequency)
7
+ @principal = principal
8
+ @rate = rate
9
+ @time = time
10
+ @compounding_frequency = compounding_frequency
11
+ @periods = nil
12
+ end
13
+
14
+ def calculate
15
+ @interest = (1 + @rate / @compounding_frequency)**(@compounding_frequency * @time)
16
+ @total = @principal + @interest
17
+ populate_periods
18
+ end
19
+
20
+ def populate_periods
21
+ total_number_of_periods = @compounding_frequency * @time
22
+ @periods = []
23
+ previous_total = @principal
24
+
25
+ for n in 1..total_number_of_periods
26
+ period_interest = previous_total * @rate / @compounding_frequency
27
+ previous_total += period_interest
28
+ @periods.push(DTO::Period.new(n, previous_total, period_interest, previous_total))
29
+ end
30
+
31
+ @periods
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Mortgagerb
2
+ class Calculator
3
+ def self.calculate(principal, rate, time, compounding_frequency)
4
+ cr = CalculationResult.new(principal, rate, time, compounding_frequency)
5
+ cr.calculate
6
+ cr
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Compounding
2
+ module DTO
3
+ class Period
4
+ attr_reader :period_id, :previous_total, :interest, :total
5
+
6
+ def initialize(period_id, previous_total, interest, total)
7
+ @period_id = period_id
8
+ @previous_total = previous_total
9
+ @interest = interest
10
+ @total = total
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Compounding
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "compounding/version"
4
+
5
+ require_relative "compounding/calculator"
6
+ require_relative "compounding/calculation_result"
7
+
8
+ require_relative "compounding/dto/period"
9
+
10
+ module Compounding
11
+ class Error < StandardError; end
12
+ # Your code goes here...
13
+ end
@@ -0,0 +1,4 @@
1
+ module Compounding
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compounding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Kim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-02-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Calculate compound interest
14
+ email:
15
+ - iamjsonkim@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/compounding.rb
26
+ - lib/compounding/calculation_result.rb
27
+ - lib/compounding/calculator.rb
28
+ - lib/compounding/dto/period.rb
29
+ - lib/compounding/version.rb
30
+ - sig/compounding.rbs
31
+ homepage: https://github.com/serv/compounding
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/serv/compounding
36
+ source_code_uri: https://github.com/serv/compounding
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.5.16
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Calculate compound interest
56
+ test_files: []