Skip to content

Instantly share code, notes, and snippets.

@jmoon90
Last active December 29, 2015 17:58
Show Gist options
  • Select an option

  • Save jmoon90/7707400 to your computer and use it in GitHub Desktop.

Select an option

Save jmoon90/7707400 to your computer and use it in GitHub Desktop.
require 'pry'
class HomePurchaseOption
attr_accessor :equity_after_sale
def initialize(property)
@i = 0
@property = property
@mortgage_balance = {}
equity_after_sale
required_mortgage
end
def equity_after_sale
@property.each do |ind_prop|
@mortgage_balance[ind_prop["Address"]] = ind_prop["Selling Price"].to_i - ind_prop["Down Payment"].to_i
end
end
def required_mortgage
@mortgage_balance.each do |balance|
puts "***#{balance[0]}***"
puts "Mortage: $#{balance[1]}"
insurance_cost(2, balance[0], balance[1])
end
end
def insurance_cost(years, home, balance)
if pmi_required?(@property[@i]) == true
puts "#{years} years of Insurance: #{years * balance * 0.005}\n "
else
puts "#{years} years of Insurance: 0\n "
end
end
def pmi_required?(property)
@i += 1
true if property["Property Value"].to_i * 0.2 > property["Down Payment"].to_i
end
end
require 'CSV'
class IndividualProperty
attr_reader :choose_csv_file
def initialize
csv_file = "property_details.csv"
#csv_file = choose_csv_file
@property = []
read_each_csv(csv_file)
HomePurchaseOption.new(@property)
end
def choose_csv_file
puts "What csv file would you like to read?"
print "> "
#csv_file = gets.chomp
end
def read_each_csv(csv_file)
CSV.foreach("#{csv_file}", headers: :true) do |individual_property|
individual_property
@property << individual_property
end
end
end
Address Property Value Selling Price Down Payment
43 Fenmore Lane 439000 419000 20000
58 Johnson Way 512000 524000 105000
32 Silver Lane 485000 490000 97000
45 Fenway Drive 465000 460000 93000
54 Denise Drive 445000 450000 98000
require_relative "individual_property"
require_relative "home_purchase_option"
IndividualProperty.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment