Class: RePricingNl::RentIncrementCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/re-pricing-nl/rent_increment_calculator.rb

Class Method Summary collapse

Class Method Details

.get_relative_date(year, month, delta, options = {}) ⇒ Object

Returns a date object that is delta months into the past/future



79
80
81
# File 'lib/re-pricing-nl/rent_increment_calculator.rb', line 79

def self.get_relative_date(year, month, delta, options = {})
  Date.new(year, month, 1).advance :months => delta
end

.get_rent_increment(options = {}) ⇒ Object

get_rent_increment

Mandatory arguments:

- month: The month in which the rent increase shall take place.
- year: The year in which the rent increase shall take place.

Optional arguments:

- cpi_value, a Hash with keys:
  - cpi_method: CPI method
  - period: CPI period
  - cpi_type: CPI type
  - base_year: CPI base year

The cpi_value option is passed to both DataWrapper.get_rent_increment calls as a parameter.

First, two dates are determined using DataWrapper: Date1 = CPI of specified year 4 months into the past Date2 = CPI of last year, also 4 months earlier

e.g. input = 2012-01-01

Then Date1 = 2011-09 Date2 = 2010-09

For Date1 and Date2, the index is determined through DataWrapper (returns a Float)

Date1 is then divided by Date2

E.g.

110.18/107.26 = 1.027 (2,7%)

Returns Float or nil.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/re-pricing-nl/rent_increment_calculator.rb', line 51

def self.get_rent_increment(options = {})
  OptionsChecker.check( options, [ :year, :month ] )
  
  year = options[:year]
  month = options[:month]
  
  raise "Month must be >= 1 and <= 12. You specified: #{month}" unless month >= 1 && month <= 12
  
  # 4 months into the past
  relative_date = get_relative_date(year, month, -4)
  back_date_year = relative_date.year
  back_date_month = relative_date.month
  
  # 4 months ago relative to the year and month specified
  date1 = RePricingNl::DataWrapper.get_cpi_index(options.merge({ :month => back_date_month, :year => back_date_year })) # Pass along the options as well
  # 1 year and 4 months ago, also relative to y and m specified.
  date2 = RePricingNl::DataWrapper.get_cpi_index(options.merge({ :month => back_date_month, :year => back_date_year - 1 }))
  
  ret = nil
  
  if !date1.nil? && !date2.nil?
    ret = ((date1 / date2) * 1000).round / 1000.0 # 1.8.7 doesn't have round(integer), 1.9.2 does
  end
  
  ret
end