inflation-calculator 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/inflation-calculator.rb +18 -8
- metadata +1 -1
data/lib/inflation-calculator.rb
CHANGED
@@ -105,26 +105,36 @@ class InflationCalc
|
|
105
105
|
2011 => 224.939,
|
106
106
|
2012 => 229.594,
|
107
107
|
2013 => 232.957,
|
108
|
-
2014 =>
|
108
|
+
2014 => 234.781}
|
109
109
|
end
|
110
110
|
|
111
|
-
def
|
111
|
+
def get_amount
|
112
112
|
print "Enter amount: "
|
113
|
-
amount = gets.chomp
|
113
|
+
@amount = gets.chomp
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_year
|
114
117
|
print "Pick a year from 1913 to 2013: "
|
115
|
-
year = gets.chomp.to_i
|
118
|
+
@year = gets.chomp.to_i
|
119
|
+
|
116
120
|
while true
|
117
|
-
if year < 1913 || year > 2013
|
121
|
+
if @year < 1913 || @year > 2013
|
118
122
|
print "The year must be from 1913 to 2013. Enter year: "
|
119
|
-
year = gets.chomp.to_i
|
123
|
+
@year = gets.chomp.to_i
|
124
|
+
|
120
125
|
else
|
121
126
|
break
|
122
127
|
end
|
123
128
|
end
|
124
|
-
|
125
|
-
|
129
|
+
end
|
130
|
+
|
131
|
+
def calculate
|
132
|
+
a = @amount.to_d * (cpi[2014].to_d / cpi[@year].to_d)
|
133
|
+
puts "$#{@amount} in #{@year} has the same buying power as $#{a.to_f.round(2)} in 2014."
|
126
134
|
|
127
135
|
end
|
128
136
|
end
|
129
137
|
f = InflationCalc.new
|
138
|
+
f.get_amount
|
139
|
+
f.get_year
|
130
140
|
f.calculate
|