inflation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/inflation.gemspec +21 -0
- data/lib/inflation.rb +3 -0
- data/lib/inflation/cpi.rb +217 -0
- data/lib/inflation/inflation.rb +36 -0
- data/lib/inflation/version.rb +3 -0
- data/spec/inflation_spec.rb +38 -0
- metadata +73 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Damian Mastylo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Inflation
|
2
|
+
|
3
|
+
This simple gem makes it easy to calculate how much different amounts of money
|
4
|
+
would be worth in certain years. Years from 1800 - 2012 are supported.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'inflation'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install inflation
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'inflation'
|
24
|
+
|
25
|
+
# Return the value (rounded to 2 decimal points)
|
26
|
+
1.from(1800).to(2012)
|
27
|
+
|
28
|
+
# Or, if you like more English sounding method chaining...
|
29
|
+
1.from_1800.to_2012
|
30
|
+
|
31
|
+
# Return true if the year is supported.
|
32
|
+
1840.year?
|
33
|
+
=> true
|
34
|
+
|
35
|
+
1784.year?
|
36
|
+
=> false
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/inflation.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'inflation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "inflation"
|
8
|
+
gem.version = Inflation::VERSION
|
9
|
+
gem.authors = ["Damian Mastylo"]
|
10
|
+
gem.email = ["dmastylo@codequarry.net"]
|
11
|
+
gem.description = %q{ Find out how much money was worth any year from 1800 to now. }
|
12
|
+
gem.summary = %q{ Find out how much your dollar used to be worth. }
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.add_development_dependency "rspec"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
data/lib/inflation.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
class Numeric
|
2
|
+
CPI = {
|
3
|
+
'1800' => 51,
|
4
|
+
'1801' => 50,
|
5
|
+
'1802' => 43,
|
6
|
+
'1803' => 45,
|
7
|
+
'1804' => 45,
|
8
|
+
'1805' => 45,
|
9
|
+
'1806' => 47,
|
10
|
+
'1807' => 44,
|
11
|
+
'1808' => 48,
|
12
|
+
'1809' => 47,
|
13
|
+
'1810' => 47,
|
14
|
+
'1811' => 50,
|
15
|
+
'1812' => 51,
|
16
|
+
'1813' => 58,
|
17
|
+
'1814' => 63,
|
18
|
+
'1815' => 55,
|
19
|
+
'1816' => 51,
|
20
|
+
'1817' => 48,
|
21
|
+
'1818' => 46,
|
22
|
+
'1819' => 46,
|
23
|
+
'1820' => 42,
|
24
|
+
'1821' => 40,
|
25
|
+
'1822' => 40,
|
26
|
+
'1823' => 36,
|
27
|
+
'1824' => 33,
|
28
|
+
'1825' => 34,
|
29
|
+
'1826' => 34,
|
30
|
+
'1827' => 34,
|
31
|
+
'1828' => 33,
|
32
|
+
'1829' => 32,
|
33
|
+
'1830' => 32,
|
34
|
+
'1831' => 32,
|
35
|
+
'1832' => 30,
|
36
|
+
'1833' => 29,
|
37
|
+
'1834' => 30,
|
38
|
+
'1835' => 31,
|
39
|
+
'1836' => 33,
|
40
|
+
'1837' => 34,
|
41
|
+
'1838' => 32,
|
42
|
+
'1839' => 32,
|
43
|
+
'1840' => 30,
|
44
|
+
'1841' => 31,
|
45
|
+
'1842' => 29,
|
46
|
+
'1843' => 28,
|
47
|
+
'1844' => 28,
|
48
|
+
'1845' => 28,
|
49
|
+
'1846' => 27,
|
50
|
+
'1847' => 28,
|
51
|
+
'1848' => 26,
|
52
|
+
'1849' => 25,
|
53
|
+
'1850' => 25,
|
54
|
+
'1851' => 25,
|
55
|
+
'1852' => 25,
|
56
|
+
'1853' => 25,
|
57
|
+
'1854' => 27,
|
58
|
+
'1855' => 28,
|
59
|
+
'1856' => 27,
|
60
|
+
'1857' => 28,
|
61
|
+
'1858' => 26,
|
62
|
+
'1859' => 27,
|
63
|
+
'1860' => 27,
|
64
|
+
'1861' => 27,
|
65
|
+
'1862' => 30,
|
66
|
+
'1863' => 37,
|
67
|
+
'1864' => 47,
|
68
|
+
'1865' => 46,
|
69
|
+
'1866' => 44,
|
70
|
+
'1867' => 42,
|
71
|
+
'1868' => 40,
|
72
|
+
'1869' => 40,
|
73
|
+
'1870' => 38,
|
74
|
+
'1871' => 36,
|
75
|
+
'1872' => 36,
|
76
|
+
'1873' => 36,
|
77
|
+
'1874' => 34,
|
78
|
+
'1875' => 33,
|
79
|
+
'1876' => 32,
|
80
|
+
'1877' => 32,
|
81
|
+
'1878' => 29,
|
82
|
+
'1879' => 28,
|
83
|
+
'1880' => 29,
|
84
|
+
'1881' => 29,
|
85
|
+
'1882' => 29,
|
86
|
+
'1883' => 28,
|
87
|
+
'1884' => 27,
|
88
|
+
'1885' => 27,
|
89
|
+
'1886' => 27,
|
90
|
+
'1887' => 27,
|
91
|
+
'1888' => 27,
|
92
|
+
'1889' => 27,
|
93
|
+
'1890' => 27,
|
94
|
+
'1891' => 27,
|
95
|
+
'1892' => 27,
|
96
|
+
'1893' => 27,
|
97
|
+
'1894' => 26,
|
98
|
+
'1895' => 25,
|
99
|
+
'1896' => 25,
|
100
|
+
'1897' => 25,
|
101
|
+
'1898' => 25,
|
102
|
+
'1899' => 25,
|
103
|
+
'1900' => 25,
|
104
|
+
'1901' => 25,
|
105
|
+
'1902' => 26,
|
106
|
+
'1903' => 27,
|
107
|
+
'1904' => 27,
|
108
|
+
'1905' => 27,
|
109
|
+
'1906' => 27,
|
110
|
+
'1907' => 28,
|
111
|
+
'1908' => 27,
|
112
|
+
'1909' => 27,
|
113
|
+
'1910' => 28,
|
114
|
+
'1911' => 28,
|
115
|
+
'1912' => 29,
|
116
|
+
'1913' => 29.7,
|
117
|
+
'1914' => 30.1,
|
118
|
+
'1915' => 30.4,
|
119
|
+
'1916' => 32.7,
|
120
|
+
'1917' => 38.5,
|
121
|
+
'1918' => 45.2,
|
122
|
+
'1919' => 52.1,
|
123
|
+
'1920' => 60.2,
|
124
|
+
'1921' => 53.6,
|
125
|
+
'1922' => 50.3,
|
126
|
+
'1923' => 51.2,
|
127
|
+
'1924' => 51.5,
|
128
|
+
'1925' => 52.7,
|
129
|
+
'1926' => 53.2,
|
130
|
+
'1927' => 52.2,
|
131
|
+
'1928' => 51.6,
|
132
|
+
'1929' => 51.6,
|
133
|
+
'1930' => 50.2,
|
134
|
+
'1931' => 45.7,
|
135
|
+
'1932' => 41.0,
|
136
|
+
'1933' => 38.9,
|
137
|
+
'1934' => 40.2,
|
138
|
+
'1935' => 41.2,
|
139
|
+
'1936' => 41.7,
|
140
|
+
'1937' => 43.2,
|
141
|
+
'1938' => 42.3,
|
142
|
+
'1939' => 41.8,
|
143
|
+
'1940' => 42.1,
|
144
|
+
'1941' => 44.2,
|
145
|
+
'1942' => 49.1,
|
146
|
+
'1943' => 52.0,
|
147
|
+
'1944' => 52.9,
|
148
|
+
'1945' => 54.1,
|
149
|
+
'1946' => 58.6,
|
150
|
+
'1947' => 67.1,
|
151
|
+
'1948' => 72.2,
|
152
|
+
'1949' => 71.5,
|
153
|
+
'1950' => 72.3,
|
154
|
+
'1951' => 78.0,
|
155
|
+
'1952' => 79.8,
|
156
|
+
'1953' => 80.4,
|
157
|
+
'1954' => 80.7,
|
158
|
+
'1955' => 80.5,
|
159
|
+
'1956' => 81.7,
|
160
|
+
'1957' => 84.4,
|
161
|
+
'1958' => 86.7,
|
162
|
+
'1959' => 87.6,
|
163
|
+
'1960' => 88.9,
|
164
|
+
'1961' => 89.8,
|
165
|
+
'1962' => 90.9,
|
166
|
+
'1963' => 92.0,
|
167
|
+
'1964' => 93.2,
|
168
|
+
'1965' => 94.7,
|
169
|
+
'1966' => 97.5,
|
170
|
+
'1967' => 100.2,
|
171
|
+
'1968' => 104.5,
|
172
|
+
'1969' => 110.2,
|
173
|
+
'1970' => 116.7,
|
174
|
+
'1971' => 121.7,
|
175
|
+
'1972' => 125.7,
|
176
|
+
'1973' => 133.4,
|
177
|
+
'1974' => 148.2,
|
178
|
+
'1975' => 161.7,
|
179
|
+
'1976' => 171.0,
|
180
|
+
'1977' => 182.1,
|
181
|
+
'1978' => 196.0,
|
182
|
+
'1979' => 218.1,
|
183
|
+
'1980' => 247.6,
|
184
|
+
'1981' => 273.2,
|
185
|
+
'1982' => 290.0,
|
186
|
+
'1983' => 299.3,
|
187
|
+
'1984' => 312.2,
|
188
|
+
'1985' => 323.2,
|
189
|
+
'1986' => 329.4,
|
190
|
+
'1987' => 341.4,
|
191
|
+
'1988' => 355.4,
|
192
|
+
'1989' => 372.5,
|
193
|
+
'1990' => 392.6,
|
194
|
+
'1991' => 409.3,
|
195
|
+
'1992' => 421.7,
|
196
|
+
'1993' => 434.1,
|
197
|
+
'1994' => 445.4,
|
198
|
+
'1995' => 457.9,
|
199
|
+
'1996' => 471.3,
|
200
|
+
'1997' => 482.4,
|
201
|
+
'1998' => 489.8,
|
202
|
+
'1999' => 500.6,
|
203
|
+
'2000' => 517.5,
|
204
|
+
'2001' => 532.1,
|
205
|
+
'2002' => 540.5,
|
206
|
+
'2003' => 552.8,
|
207
|
+
'2004' => 567.6,
|
208
|
+
'2005' => 586.9,
|
209
|
+
'2006' => 605.8,
|
210
|
+
'2007' => 623.1,
|
211
|
+
'2008' => 647.0,
|
212
|
+
'2009' => 644.7,
|
213
|
+
'2010' => 655.3,
|
214
|
+
'2011' => 676.0,
|
215
|
+
'2012' => 687.5
|
216
|
+
}
|
217
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Numeric
|
2
|
+
attr_accessor :from_year_cpi, :to_year_cpi
|
3
|
+
|
4
|
+
def years
|
5
|
+
CPI.keys
|
6
|
+
end
|
7
|
+
|
8
|
+
def year?
|
9
|
+
CPI.keys.include?(self.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def from(year=1800)
|
13
|
+
@from_year_cpi = CPI[year.to_s]
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def to(year=2012)
|
18
|
+
@to_year_cpi = CPI[year.to_s]
|
19
|
+
calculate_inflation
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing(method, *args, &block)
|
23
|
+
if method =~ /^from_(\d*)$/
|
24
|
+
self.send(:from, /^from_(\d*)$/.match(method)[1].to_i)
|
25
|
+
elsif method =~ /^to_(\d*)$/
|
26
|
+
self.send(:to, /^to_(\d*)$/.match(method)[1].to_i)
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def calculate_inflation
|
34
|
+
(self * (@to_year_cpi / @from_year_cpi)).round(2)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'inflation'
|
2
|
+
|
3
|
+
describe "Inflation" do
|
4
|
+
context "#years" do
|
5
|
+
it "should return an Array of years" do
|
6
|
+
years = 2500.years
|
7
|
+
years.should be_a Array
|
8
|
+
years.length.should be > 10
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "#year?" do
|
13
|
+
it "should return true for a year that can be calculated" do
|
14
|
+
year = 1803.year?
|
15
|
+
year.should be true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return false for a year that cannot be calculated" do
|
19
|
+
year = 1700.year?
|
20
|
+
year.should be false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "#from" do
|
25
|
+
it "should be chainable" do
|
26
|
+
100.from_2010.should be_a Fixnum
|
27
|
+
20054.40.from_1970.should be_a Float
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "#to" do
|
32
|
+
it "should calculate the inflation rate of the number" do
|
33
|
+
1.from_1850.to_2012.should == 27.50
|
34
|
+
100.from_2012.to_2000.should == 75.27
|
35
|
+
75.27.from_2000.to_2012.should == 100
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inflation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Damian Mastylo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ! ' Find out how much money was worth any year from 1800 to now. '
|
31
|
+
email:
|
32
|
+
- dmastylo@codequarry.net
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- inflation.gemspec
|
43
|
+
- lib/inflation.rb
|
44
|
+
- lib/inflation/cpi.rb
|
45
|
+
- lib/inflation/inflation.rb
|
46
|
+
- lib/inflation/version.rb
|
47
|
+
- spec/inflation_spec.rb
|
48
|
+
homepage: ''
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.24
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Find out how much your dollar used to be worth.
|
72
|
+
test_files:
|
73
|
+
- spec/inflation_spec.rb
|