mortgage_calculations 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,12 +1,13 @@
1
1
  module MortgageCalc
2
2
  class MortgageUtil
3
- attr_accessor :loan_amount, :interest_rate, :period, :fee
3
+ attr_accessor :loan_amount, :borrowed_fees, :interest_rate, :period, :fee
4
4
 
5
- def initialize(loan_amount, interest_rate, fee, period=360)
5
+ def initialize(loan_amount, interest_rate, fee, period=360, borrowed_fees=0)
6
6
  self.loan_amount = Float(loan_amount.to_s)
7
7
  self.interest_rate = Float(interest_rate.to_s)
8
8
  self.period = Integer(period.to_s)
9
9
  self.fee = Float(fee.to_s)
10
+ self.borrowed_fees = Float(borrowed_fees.to_s)
10
11
  end
11
12
 
12
13
  def apr
@@ -14,14 +15,11 @@ module MortgageCalc
14
15
  end
15
16
 
16
17
  def monthly_payment
17
- @monthly_payment ||= calculate_monthly_payment(self.loan_amount, monthly_interest_rate, self.period)
18
+ @monthly_payment ||= calculate_monthly_payment(self.loan_amount + self.borrowed_fees, monthly_interest_rate, self.period)
18
19
  end
19
20
 
20
- def monthly_payment_with_fees
21
- @monthly_payment_with_fees ||= calculate_monthly_payment(self.loan_amount + fee, monthly_interest_rate, self.period)
22
- end
23
-
24
- private
21
+ private
22
+
25
23
  def monthly_interest_rate
26
24
  self.interest_rate / 100 / 12
27
25
  end
@@ -29,7 +27,11 @@ module MortgageCalc
29
27
  def calculate_monthly_payment(amount, monthly_rate, period)
30
28
  amount * (monthly_rate/(1 - (1 + monthly_rate)**(-period)))
31
29
  end
32
-
30
+
31
+ def monthly_payment_with_fees
32
+ @monthly_payment_with_fees ||= calculate_monthly_payment(self.loan_amount + fee, monthly_interest_rate, self.period)
33
+ end
34
+
33
35
  # solves APR
34
36
  # [a (1 + a)^N] / [(1 + a)^N - 1] - P/C = 0
35
37
  # where a = APR/1200, N = period, P = monthly payment, C = loan_amount
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mortgage_calculations}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Perry Hertler"]
12
- s.date = %q{2011-02-14}
12
+ s.date = %q{2011-03-17}
13
13
  s.description = %q{Utilities for Mortgage related calculations (APR and Monthly Payments)}
14
14
  s.email = %q{perry@hertler.org}
15
15
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = %q{http://www.pathf.com/blogs/2010/02/mortcalc-gem/}
36
36
  s.licenses = ["MORExchange"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.7}
38
+ s.rubygems_version = %q{1.6.0}
39
39
  s.summary = %q{Utilities for Mortgage related calculations (APR and Monthly Payments)}
40
40
  s.test_files = [
41
41
  "spec/mortgage_calc/mortgage_util_spec.rb",
@@ -43,7 +43,6 @@ Gem::Specification.new do |s|
43
43
  ]
44
44
 
45
45
  if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
46
  s.specification_version = 3
48
47
 
49
48
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -69,6 +69,18 @@ module MortgageCalc
69
69
  @mortgage_util.period.class.should == Fixnum
70
70
  end
71
71
  end
72
+
73
+ context "when borrowed_fees is specified" do
74
+ before(:all) do
75
+ @mortgage_util = MortgageUtil.new(100_000, 6.0, 2_000, 360, 2_000)
76
+ end
77
+ it "should not use the borrowed_fees in APR calculation" do
78
+ @mortgage_util.apr.should be_within(0.00001).of(6.1857)
79
+ end
80
+ it "should use the borrowed_fees in monthly payment calculation" do
81
+ @mortgage_util.monthly_payment.should be_within(0.002).of(611.54)
82
+ end
83
+ end
72
84
  end
73
85
 
74
86
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mortgage_calculations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Perry Hertler
@@ -15,14 +15,12 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-14 00:00:00 -06:00
18
+ date: 2011-03-17 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
22
  type: :development
24
- name: rspec
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
26
24
  none: false
27
25
  requirements:
28
26
  - - ~>
@@ -33,12 +31,12 @@ dependencies:
33
31
  - 1
34
32
  - 0
35
33
  version: 2.1.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ name: rspec
38
36
  prerelease: false
37
+ - !ruby/object:Gem::Dependency
39
38
  type: :development
40
- name: cucumber
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ requirement: &id002 !ruby/object:Gem::Requirement
42
40
  none: false
43
41
  requirements:
44
42
  - - ">="
@@ -47,12 +45,12 @@ dependencies:
47
45
  segments:
48
46
  - 0
49
47
  version: "0"
50
- requirement: *id002
51
- - !ruby/object:Gem::Dependency
48
+ version_requirements: *id002
49
+ name: cucumber
52
50
  prerelease: false
51
+ - !ruby/object:Gem::Dependency
53
52
  type: :development
54
- name: bundler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ requirement: &id003 !ruby/object:Gem::Requirement
56
54
  none: false
57
55
  requirements:
58
56
  - - ~>
@@ -63,12 +61,12 @@ dependencies:
63
61
  - 0
64
62
  - 0
65
63
  version: 1.0.0
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
64
+ version_requirements: *id003
65
+ name: bundler
68
66
  prerelease: false
67
+ - !ruby/object:Gem::Dependency
69
68
  type: :development
70
- name: jeweler
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
69
+ requirement: &id004 !ruby/object:Gem::Requirement
72
70
  none: false
73
71
  requirements:
74
72
  - - ~>
@@ -79,12 +77,12 @@ dependencies:
79
77
  - 5
80
78
  - 1
81
79
  version: 1.5.1
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
80
+ version_requirements: *id004
81
+ name: jeweler
84
82
  prerelease: false
83
+ - !ruby/object:Gem::Dependency
85
84
  type: :development
86
- name: rcov
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
88
86
  none: false
89
87
  requirements:
90
88
  - - ">="
@@ -93,7 +91,9 @@ dependencies:
93
91
  segments:
94
92
  - 0
95
93
  version: "0"
96
- requirement: *id005
94
+ version_requirements: *id005
95
+ name: rcov
96
+ prerelease: false
97
97
  description: Utilities for Mortgage related calculations (APR and Monthly Payments)
98
98
  email: perry@hertler.org
99
99
  executables: []
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements: []
149
149
 
150
150
  rubyforge_project:
151
- rubygems_version: 1.3.7
151
+ rubygems_version: 1.6.0
152
152
  signing_key:
153
153
  specification_version: 3
154
154
  summary: Utilities for Mortgage related calculations (APR and Monthly Payments)