emi_calculator 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 +7 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +34 -0
- data/README.md +138 -0
- data/Rakefile +4 -0
- data/emi_calculator.gemspec +39 -0
- data/lib/emi_calculator/calculator.rb +53 -0
- data/lib/emi_calculator/version.rb +5 -0
- data/lib/emi_calculator.rb +9 -0
- data/sig/emi_calculator.rbs +4 -0
- metadata +57 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f9be6a670978ef42888bdcbbc970480a8693e5f6c41c55590ec6182ba5afcf95
|
|
4
|
+
data.tar.gz: 6113d40fc91eef4606cab7579061c933592f7e01cb163285eeacf77e91bc2554
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b4a78c76af107d0eea333f53686c0fa5c87d40fc007ffe7f374e84c87c40e7d830494c9a8590fddcd7ad3450c7d054c6417d1f3bcea864cd4c36e416e3fb5b84
|
|
7
|
+
data.tar.gz: c44fb389484527d0008cb20c5472ae1c2ed1072ccdbdd7b9ac78a7efad554af6157b051bd3cb4be18b80f402224e9ea213a125920c3726fdf8fb8e206fe4f8e7
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
emi_calculator (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.6.2)
|
|
10
|
+
rake (13.3.0)
|
|
11
|
+
rspec (3.13.1)
|
|
12
|
+
rspec-core (~> 3.13.0)
|
|
13
|
+
rspec-expectations (~> 3.13.0)
|
|
14
|
+
rspec-mocks (~> 3.13.0)
|
|
15
|
+
rspec-core (3.13.5)
|
|
16
|
+
rspec-support (~> 3.13.0)
|
|
17
|
+
rspec-expectations (3.13.5)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.13.0)
|
|
20
|
+
rspec-mocks (3.13.6)
|
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
+
rspec-support (~> 3.13.0)
|
|
23
|
+
rspec-support (3.13.6)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
x86_64-linux
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
emi_calculator!
|
|
30
|
+
rake (~> 13.0)
|
|
31
|
+
rspec
|
|
32
|
+
|
|
33
|
+
BUNDLED WITH
|
|
34
|
+
2.4.12
|
data/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# 💰 EmiCalculator
|
|
2
|
+
|
|
3
|
+
A lightweight Ruby gem for calculating **Loan EMIs**, **Total Interest**, and **Amortization Schedules** with ease.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🚀 Features
|
|
8
|
+
|
|
9
|
+
- 🧮 Calculate monthly EMI (Equated Monthly Installment)
|
|
10
|
+
- 💵 Get total payment and total interest
|
|
11
|
+
- 📅 Generate detailed amortization schedules
|
|
12
|
+
- 🧑💻 Easy to integrate with Rails or standalone Ruby projects
|
|
13
|
+
- ✅ Tested with RSpec
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 📦 Installation
|
|
18
|
+
|
|
19
|
+
Add this line to your application's Gemfile:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
gem 'emi_calculator'
|
|
23
|
+
```
|
|
24
|
+
Then execute
|
|
25
|
+
```ruby
|
|
26
|
+
$ bundle install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or Install Directly
|
|
30
|
+
```ruby
|
|
31
|
+
$ gem install emi_calculator
|
|
32
|
+
```
|
|
33
|
+
## 🧮 Usage
|
|
34
|
+
```ruby
|
|
35
|
+
require 'emi_calculator'
|
|
36
|
+
|
|
37
|
+
calculator = EmiCalculator::Calculator.new(
|
|
38
|
+
principal: 500_000, # Loan amount
|
|
39
|
+
annual_rate: 10, # Annual interest rate (in %)
|
|
40
|
+
tenure_months: 60 # Loan period in months
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
calculator.emi
|
|
44
|
+
# => 10624.45
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
calculator.total_payment
|
|
48
|
+
# => 637467.0
|
|
49
|
+
|
|
50
|
+
calculator.total_interest
|
|
51
|
+
# => 137467.0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
schedule = calculator.amortization_schedule
|
|
55
|
+
|
|
56
|
+
schedule.first(3)
|
|
57
|
+
# => [
|
|
58
|
+
# {:month=>1, :emi=>10624.45, :interest=>4166.67, :principal=>6457.78, :balance=>493542.22},
|
|
59
|
+
# {:month=>2, :emi=>10624.45, :interest=>4112.85, :principal=>6511.60, :balance=>487030.62},
|
|
60
|
+
# {:month=>3, :emi=>10624.45, :interest=>4058.59, :principal=>6565.86, :balance=>480464.76}
|
|
61
|
+
# ]
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 🧰 Development
|
|
66
|
+
|
|
67
|
+
Run the following to set up your local environment:
|
|
68
|
+
```ruby
|
|
69
|
+
$ bin/setup
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
You can open an interactive console with:
|
|
73
|
+
```ruby
|
|
74
|
+
$ bin/console
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
To install this gem locally:
|
|
78
|
+
```ruby
|
|
79
|
+
$ bundle exec rake install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To release a new version:
|
|
83
|
+
```ruby
|
|
84
|
+
$ bundle exec rake release
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This will:
|
|
88
|
+
|
|
89
|
+
Build the .gem file
|
|
90
|
+
|
|
91
|
+
Create a new Git tag
|
|
92
|
+
|
|
93
|
+
Push commits and the tag
|
|
94
|
+
|
|
95
|
+
Publish the gem to RubyGems.org
|
|
96
|
+
|
|
97
|
+
## 📘 Example Project
|
|
98
|
+
```ruby
|
|
99
|
+
require 'emi_calculator'
|
|
100
|
+
|
|
101
|
+
loan = EmiCalculator::Calculator.new(
|
|
102
|
+
principal: 250000,
|
|
103
|
+
annual_rate: 8.5,
|
|
104
|
+
tenure_months: 36
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
puts "Monthly EMI: ₹#{loan.emi}"
|
|
108
|
+
puts "Total Payment: ₹#{loan.total_payment}"
|
|
109
|
+
puts "Total Interest: ₹#{loan.total_interest}"
|
|
110
|
+
```
|
|
111
|
+
## 🤝 Contributing
|
|
112
|
+
|
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<your-username>/emi_calculator
|
|
114
|
+
.
|
|
115
|
+
|
|
116
|
+
Fork it
|
|
117
|
+
```
|
|
118
|
+
Create your feature branch (git checkout -b my-new-feature)
|
|
119
|
+
|
|
120
|
+
Commit your changes (git commit -am 'Add new feature')
|
|
121
|
+
|
|
122
|
+
Push to the branch (git push origin my-new-feature)
|
|
123
|
+
|
|
124
|
+
Create a new Pull Request
|
|
125
|
+
```
|
|
126
|
+
## 🧑💼 Author
|
|
127
|
+
```
|
|
128
|
+
Ravi Shankar Singhal
|
|
129
|
+
Senior Backend Developer — Ruby on Rails
|
|
130
|
+
📧 ravi.singhal2308@gmail.com
|
|
131
|
+
|
|
132
|
+
🌐 https://github.com/RaviShankarSinghal
|
|
133
|
+
```
|
|
134
|
+
## 🪪 License
|
|
135
|
+
|
|
136
|
+
The gem is available as open source under the terms of the MIT License
|
|
137
|
+
.
|
|
138
|
+
---
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/emi_calculator/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "emi_calculator"
|
|
7
|
+
spec.version = EmiCalculator::VERSION
|
|
8
|
+
spec.authors = ["Ravi Shankar Singhal"]
|
|
9
|
+
spec.email = ["ravi.singhal2308@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A simple Ruby gem to calculate loan EMI (Equated Monthly Installment)."
|
|
12
|
+
spec.description = "This gem provides methods to calculate EMI, total interest, and total payment amount for a given loan principal, interest rate, and tenure."
|
|
13
|
+
spec.homepage = "https://github.com/RaviShankarSinghal/emi_calculator"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
16
|
+
|
|
17
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/RaviShankarSinghal/emi_calculator"
|
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/RaviShankarSinghal/emi_calculator/blob/main/CHANGELOG.md"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
# Uncomment to register a new dependency of your gem
|
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
36
|
+
|
|
37
|
+
# For more information and examples about making a new gem, check out our
|
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
39
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module EmiCalculator
|
|
2
|
+
class Calculator
|
|
3
|
+
attr_reader :principal, :annual_rate, :tenure_months
|
|
4
|
+
|
|
5
|
+
def initialize(principal:, annual_rate:, tenure_months:)
|
|
6
|
+
@principal = principal.to_f
|
|
7
|
+
@annual_rate = annual_rate.to_f
|
|
8
|
+
@tenure_months = tenure_months.to_i
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def monthly_rate
|
|
12
|
+
annual_rate/ 12/ 100
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def emi
|
|
16
|
+
r = monthly_rate
|
|
17
|
+
n = tenure_months
|
|
18
|
+
p = principal
|
|
19
|
+
|
|
20
|
+
return 0.00 if r.zero? || n.zero?
|
|
21
|
+
|
|
22
|
+
rate = p * r * ((1+r)**n) / (((1+r)**n) - 1)
|
|
23
|
+
rate.round(2)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def total_payment
|
|
27
|
+
emi * tenure_months
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def total_interest
|
|
31
|
+
total_payment - principal
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def amortization_schedule
|
|
35
|
+
schedule = []
|
|
36
|
+
balance = principal
|
|
37
|
+
r = monthly_rate
|
|
38
|
+
(1..tenure_months).each do |month|
|
|
39
|
+
interest = balance * r
|
|
40
|
+
principal_component = emi - interest
|
|
41
|
+
balance -= principal_component
|
|
42
|
+
schedule << {
|
|
43
|
+
month: month,
|
|
44
|
+
emi: emi.round(3),
|
|
45
|
+
interest: interest.round(3),
|
|
46
|
+
principal: principal_component.round(3),
|
|
47
|
+
balance: balance.positive? ? balance.round(3) : 0.000
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
schedule
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: emi_calculator
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ravi Shankar Singhal
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-10-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: This gem provides methods to calculate EMI, total interest, and total
|
|
14
|
+
payment amount for a given loan principal, interest rate, and tenure.
|
|
15
|
+
email:
|
|
16
|
+
- ravi.singhal2308@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- ".rspec"
|
|
22
|
+
- Gemfile
|
|
23
|
+
- Gemfile.lock
|
|
24
|
+
- README.md
|
|
25
|
+
- Rakefile
|
|
26
|
+
- emi_calculator.gemspec
|
|
27
|
+
- lib/emi_calculator.rb
|
|
28
|
+
- lib/emi_calculator/calculator.rb
|
|
29
|
+
- lib/emi_calculator/version.rb
|
|
30
|
+
- sig/emi_calculator.rbs
|
|
31
|
+
homepage: https://github.com/RaviShankarSinghal/emi_calculator
|
|
32
|
+
licenses:
|
|
33
|
+
- MIT
|
|
34
|
+
metadata:
|
|
35
|
+
homepage_uri: https://github.com/RaviShankarSinghal/emi_calculator
|
|
36
|
+
source_code_uri: https://github.com/RaviShankarSinghal/emi_calculator
|
|
37
|
+
changelog_uri: https://github.com/RaviShankarSinghal/emi_calculator/blob/main/CHANGELOG.md
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 2.6.0
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
requirements: []
|
|
53
|
+
rubygems_version: 3.3.7
|
|
54
|
+
signing_key:
|
|
55
|
+
specification_version: 4
|
|
56
|
+
summary: A simple Ruby gem to calculate loan EMI (Equated Monthly Installment).
|
|
57
|
+
test_files: []
|