inflation 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/inflation/inflation.rb +10 -0
- data/lib/inflation/version.rb +1 -1
- data/spec/inflation_spec.rb +13 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -28,6 +28,10 @@ require 'inflation'
|
|
28
28
|
# Or, if you like more English sounding method chaining...
|
29
29
|
1.from_1800.to_2012
|
30
30
|
|
31
|
+
# Even better, you can use from_now and to_now instead of the year
|
32
|
+
1.from_now.to_2010
|
33
|
+
1.from_1898.to_now
|
34
|
+
|
31
35
|
# Return true if the year is supported.
|
32
36
|
1840.year?
|
33
37
|
=> true
|
data/lib/inflation/inflation.rb
CHANGED
@@ -14,11 +14,21 @@ class Numeric
|
|
14
14
|
self
|
15
15
|
end
|
16
16
|
|
17
|
+
def from_now
|
18
|
+
@from_year_cpi = CPI[Time.now.year.to_s]
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
17
22
|
def to(year=2012)
|
18
23
|
@to_year_cpi = CPI[year.to_s]
|
19
24
|
calculate_inflation
|
20
25
|
end
|
21
26
|
|
27
|
+
def to_now
|
28
|
+
@to_year_cpi = CPI[Time.now.year.to_s]
|
29
|
+
calculate_inflation
|
30
|
+
end
|
31
|
+
|
22
32
|
def method_missing(method, *args, &block)
|
23
33
|
if method =~ /^from_(\d*)$/
|
24
34
|
self.send(:from, /^from_(\d*)$/.match(method)[1].to_i)
|
data/lib/inflation/version.rb
CHANGED
data/spec/inflation_spec.rb
CHANGED
@@ -35,4 +35,17 @@ describe "Inflation" do
|
|
35
35
|
75.27.from_2000.to_2012.should == 100
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
context "#from_now" do
|
40
|
+
it "should calculate the inflation rate of the number from current year values" do
|
41
|
+
100.from_now.to_2000.should == 75.27
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#to_now" do
|
46
|
+
it "should calculate the inflation rate of the number to current year values" do
|
47
|
+
1.from_1850.to_now.should == 27.50
|
48
|
+
75.27.from_2000.to_now.should == 100
|
49
|
+
end
|
50
|
+
end
|
38
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inflation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.25
|
69
69
|
signing_key:
|
70
70
|
specification_version: 3
|
71
71
|
summary: Find out how much your dollar used to be worth.
|