re-pricing-nl 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2011-11-22
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ development_notes.txt
6
+ Rakefile
7
+ lib/re-pricing-nl/cpi_value.rb
8
+ lib/re-pricing-nl/data_wrapper.rb
9
+ lib/re-pricing-nl/rent_increment_calculator.rb
10
+ lib/re-pricing-nl/data_wrapper.rb
11
+ lib/re-pricing-nl.rb
12
+ script/console
13
+ script/destroy
14
+ script/generate
15
+ test/test_helper.rb
16
+ test/test_re-pricing-nl.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on re-pricing-nl, see http://re-pricing-nl.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ = re-pricing-nl
2
+
3
+ * http://github.com/cmdjohnson/re-pricing-nl
4
+
5
+ == DESCRIPTION:
6
+
7
+ Real Estate Price change module for the Netherlands.
8
+
9
+ In the Netherlands, one of the ways to index rent prices is to multiply the price with the Dutch Bureau of Statistics' (CBS, http://www.cbs.nl/) Consumer Price Index (CPI).
10
+ The CPI is a float number larger than 1.0 that indicates the multiplication factor with which the old rent is to be multiplied.
11
+ A Web service was set up at https://cpi-nl.heroku.com/ that serves these CPI numbers.
12
+
13
+ == FEATURES/PROBLEMS:
14
+
15
+ Query CPI numbers from the CpiNL web service to facilitate automatic rent indexation.
16
+
17
+ == SYNOPSIS:
18
+
19
+ RePricingNl::RentIncrementCalculator.get_rent_increment( :month => 1, :year => 2012 ) # => 1.027
20
+
21
+ == REQUIREMENTS:
22
+
23
+ Gems required:
24
+ - activeresource
25
+ - activesupport
26
+ - options_checker
27
+
28
+ == INSTALL:
29
+
30
+ $ sudo gem install re-pricing-nl
31
+
32
+ == LICENSE:
33
+
34
+ (The MIT License)
35
+
36
+ Copyright (c) 2011 Commander Johnson <commanderjohnson@gmail.com>
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/re-pricing-nl'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 're-pricing-nl' do
14
+ self.developer 'Commander Johnson', 'commanderjohnson@gmail.com'
15
+ #self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = ['options_checker', 'activeresource', 'activesupport' ]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,61 @@
1
+ re-pricing-nl
2
+ --------------------------------------------------------------------------------
3
+
4
+ CPI = Consumer Price Index
5
+
6
+ DataWrapper < IntegrationWrapper
7
+ ===
8
+ - get_cpi_index(options)
9
+
10
+ Returns a float > 1.0 (e.g. 1.025 = 2,5%) that specifies the CPI for this period.
11
+
12
+ Mandatory arguments:
13
+ - month: Month for the CPI.
14
+ - year: Year for the CPI.
15
+
16
+ Optional arguments:
17
+ - cpi_value, a Hash with keys:
18
+ - cpi_method: CPI method
19
+ - period: CPI period
20
+ - cpi_type: CPI type
21
+ - base_year: CPI base year
22
+
23
+ Returns Float or nil if not available.
24
+
25
+ RentIncrementCalculator
26
+ ===
27
+ - get_rent_increment(options)
28
+
29
+ Mandatory arguments:
30
+ - month: The month in which the rent increase shall take place.
31
+ - year: The year in which the rent increase shall take place.
32
+
33
+ Optional arguments:
34
+ - cpi_value, a Hash with keys:
35
+ - cpi_method: CPI method
36
+ - period: CPI period
37
+ - cpi_type: CPI type
38
+ - base_year: CPI base year
39
+
40
+ The cpi_value option is passed to both DataWrapper.get_rent_increment calls as a parameter.
41
+
42
+ First, two dates are determined using DataWrapper:
43
+ Date1 = CPI of specified year 4 months into the past
44
+ Date2 = CPI of last year, also 4 months earlier
45
+
46
+ e.g. input = 2012-01-01
47
+
48
+ Then
49
+ Date1 = 2011-09
50
+ Date2 = 2010-09
51
+
52
+ For Date1 and Date2, the index is determined through DataWrapper (returns a Float)
53
+
54
+ Date1 is then divided by Date2
55
+
56
+ E.g.
57
+
58
+ 110.18/107.26 = 1.027 (2,7%)
59
+
60
+ Returns Float or nil.
61
+
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module RePricingNl
5
+ VERSION = '0.0.1'
6
+ end
@@ -0,0 +1,12 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ require 'rubygems'
5
+ require 'active_resource'
6
+
7
+ module RePricingNl
8
+ class CpiValue < ActiveResource::Base
9
+ #self.site = "http://localhost:3000/frontend/"
10
+ self.site = "https://cpi-nl.heroku.com/frontend/"
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ require 'rubygems'
5
+ require 'options_checker'
6
+ require 'active_resource'
7
+ require 're-pricing-nl/cpi_value'
8
+
9
+ module RePricingNl
10
+ class DataWrapper
11
+ ENDPOINT = "https://cpi-nl.heroku.com/frontend/cpi_values"
12
+
13
+ ##############################################################################
14
+ # get_cpi_index
15
+ #
16
+ # Returns a float > 1.0 (e.g. 1.025 = 2,5%) that specifies the CPI for this period.
17
+ #
18
+ # Mandatory arguments:
19
+ # - month: Month for the CPI.
20
+ # - year: Year for the CPI.
21
+ #
22
+ # Optional arguments:
23
+ # - cpi_value, a Hash with keys:
24
+ # - cpi_method: CPI method
25
+ # - period: CPI period
26
+ # - cpi_type: CPI type
27
+ # - base_year: CPI base year
28
+ #
29
+ # Returns Float or nil if not available.
30
+ ##############################################################################
31
+
32
+ def self.get_cpi_index(options = {})
33
+ OptionsChecker.check options, [ :month, :year ]
34
+
35
+ ret = nil
36
+
37
+ # Get the resource from the web service
38
+ # And mould it into a CpiValue object.
39
+ cpi_value = CpiValue.new(
40
+ CpiValue.get(
41
+ :show, :cpi_value => options))
42
+ # +_+ #
43
+ ret = cpi_value.index # Nice :D
44
+
45
+ ret
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,84 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ # To change this template, choose Tools | Templates
5
+ # and open the template in the editor.
6
+
7
+ require 'rubygems'
8
+ require 'options_checker'
9
+ require 're-pricing-nl/data_wrapper'
10
+ require 'date'
11
+
12
+ module RePricingNl
13
+ class RentIncrementCalculator
14
+ ############################################################################
15
+ # get_rent_increment
16
+ #
17
+ # Mandatory arguments:
18
+ # - month: The month in which the rent increase shall take place.
19
+ # - year: The year in which the rent increase shall take place.
20
+ #
21
+ # Optional arguments:
22
+ # - cpi_value, a Hash with keys:
23
+ # - cpi_method: CPI method
24
+ # - period: CPI period
25
+ # - cpi_type: CPI type
26
+ # - base_year: CPI base year
27
+ #
28
+ # The cpi_value option is passed to both DataWrapper.get_rent_increment calls as a parameter.
29
+ #
30
+ # First, two dates are determined using DataWrapper:
31
+ # Date1 = CPI of specified year 4 months into the past
32
+ # Date2 = CPI of last year, also 4 months earlier
33
+ #
34
+ # e.g. input = 2012-01-01
35
+ #
36
+ # Then
37
+ # Date1 = 2011-09
38
+ # Date2 = 2010-09
39
+ #
40
+ # For Date1 and Date2, the index is determined through DataWrapper (returns a Float)
41
+ #
42
+ # Date1 is then divided by Date2
43
+ #
44
+ # E.g.
45
+ #
46
+ # 110.18/107.26 = 1.027 (2,7%)
47
+ #
48
+ # Returns Float or nil.
49
+ ############################################################################
50
+
51
+ def self.get_rent_increment(options = {})
52
+ OptionsChecker.check( options, [ :year, :month ] )
53
+
54
+ year = options[:year]
55
+ month = options[:month]
56
+
57
+ raise "Month must be >= 1 and <= 12. You specified: #{month}" unless month >= 1 && month <= 12
58
+
59
+ # 4 months into the past
60
+ relative_date = get_relative_date(year, month, -4)
61
+ back_date_year = relative_date.year
62
+ back_date_month = relative_date.month
63
+
64
+ # 4 months ago relative to the year and month specified
65
+ date1 = RePricingNl::DataWrapper.get_cpi_index(options.merge({ :month => back_date_month, :year => back_date_year })) # Pass along the options as well
66
+ # 1 year and 4 months ago, also relative to y and m specified.
67
+ date2 = RePricingNl::DataWrapper.get_cpi_index(options.merge({ :month => back_date_month, :year => back_date_year - 1 }))
68
+
69
+ ret = nil
70
+
71
+ if !date1.nil? && !date2.nil?
72
+ ret = ((date1 / date2) * 1000).round / 1000.0 # 1.8.7 doesn't have round(integer), 1.9.2 does
73
+ end
74
+
75
+ ret
76
+ end
77
+
78
+ # Returns a date object that is delta months into the past/future
79
+ def self.get_relative_date(year, month, delta, options = {})
80
+ Date.new(year, month, 1).advance :months => delta
81
+ end
82
+ end
83
+ end
84
+
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/re-pricing-nl.rb'}"
9
+ puts "Loading re-pricing-nl gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/re-pricing-nl'
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require 're-pricing-nl/data_wrapper'
4
+ require 're-pricing-nl/rent_increment_calculator'
5
+
6
+ class TestRePricingNl < Test::Unit::TestCase
7
+ def setup
8
+ # Offline tests:
9
+ # rake test
10
+ # Online tests:
11
+ # TEST_MODE="online" rake test
12
+ @mode = ENV['TEST_MODE'] || "offline"
13
+ # Uncomment this if you want online tests
14
+ #@mode = "online"
15
+ end
16
+
17
+ ##############################################################################
18
+ # normal "offline" tests
19
+ ##############################################################################
20
+
21
+ def test_get_relative_date
22
+ map = [
23
+ # old date -- increment (can also be negative) -- expected result
24
+ [ [ 4, 2004 ], 4, [ 8, 2004 ] ],
25
+ [ [ 3, 2004 ], -3, [ 12, 2003 ] ],
26
+ [ [ 11, 2001], 3, [ 2, 2002 ] ],
27
+ [ [ 1, 2001], -22, [ 3, 1999 ] ],
28
+ [ [ 10, 2010], 15, [ 1, 2012 ] ]
29
+ ]
30
+
31
+ for ma_ in map
32
+ ret = RePricingNl::RentIncrementCalculator.get_relative_date(ma_[0][1], ma_[0][0], ma_[1])
33
+ assert_not_nil ret
34
+ assert_equal Date, ret.class
35
+ assert_equal ma_[2][0], ret.month
36
+ assert_equal ma_[2][1], ret.year
37
+ end
38
+ end
39
+
40
+ ##############################################################################
41
+ # online tests
42
+ ##############################################################################
43
+
44
+ # ONLINE test that WILL use your INTERNET
45
+ def test_get_cpi_index
46
+ return nil if @mode.eql?("offline")
47
+
48
+ ret = RePricingNl::DataWrapper.get_cpi_index :month => 3, :year => Time.now.year
49
+
50
+ assert_not_nil ret
51
+ assert_equal Float, ret.class
52
+ end
53
+
54
+ def test_get_rent_increment
55
+ return nil if @mode.eql?("offline")
56
+
57
+ ret = RePricingNl::RentIncrementCalculator.get_rent_increment( :month => 1, :year => 2012 )
58
+
59
+ assert_not_nil ret
60
+ assert_equal Float, ret.class
61
+ assert_equal 1.027, ret
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: re-pricing-nl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Commander Johnson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-28 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: options_checker
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activeresource
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: activesupport
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: hoe
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 47
72
+ segments:
73
+ - 2
74
+ - 8
75
+ - 0
76
+ version: 2.8.0
77
+ type: :development
78
+ version_requirements: *id004
79
+ description: |-
80
+ Real Estate Price change module for the Netherlands.
81
+
82
+ In the Netherlands, one of the ways to index rent prices is to multiply the price with the Dutch Bureau of Statistics' (CBS, http://www.cbs.nl/) Consumer Price Index (CPI).
83
+ The CPI is a float number larger than 1.0 that indicates the multiplication factor with which the old rent is to be multiplied.
84
+ A Web service was set up at https://cpi-nl.heroku.com/ that serves these CPI numbers.
85
+ email:
86
+ - commanderjohnson@gmail.com
87
+ executables: []
88
+
89
+ extensions: []
90
+
91
+ extra_rdoc_files:
92
+ - History.txt
93
+ - Manifest.txt
94
+ - PostInstall.txt
95
+ - development_notes.txt
96
+ files:
97
+ - History.txt
98
+ - Manifest.txt
99
+ - PostInstall.txt
100
+ - README.rdoc
101
+ - development_notes.txt
102
+ - Rakefile
103
+ - lib/re-pricing-nl/cpi_value.rb
104
+ - lib/re-pricing-nl/data_wrapper.rb
105
+ - lib/re-pricing-nl/rent_increment_calculator.rb
106
+ - lib/re-pricing-nl.rb
107
+ - script/console
108
+ - script/destroy
109
+ - script/generate
110
+ - test/test_helper.rb
111
+ - test/test_re-pricing-nl.rb
112
+ has_rdoc: true
113
+ homepage: http://github.com/cmdjohnson/re-pricing-nl
114
+ licenses: []
115
+
116
+ post_install_message:
117
+ rdoc_options:
118
+ - --main
119
+ - README.rdoc
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ requirements: []
141
+
142
+ rubyforge_project: re-pricing-nl
143
+ rubygems_version: 1.3.7
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Real Estate Price change module for the Netherlands
147
+ test_files:
148
+ - test/test_helper.rb
149
+ - test/test_re-pricing-nl.rb