Class: Rupee::BusinessDay

Inherits:
Object
  • Object
show all
Extended by:
FindInstance
Defined in:
lib/rupee/business_day.rb,
lib/rupee/business_day/actual.rb,
lib/rupee/business_day/previous.rb,
lib/rupee/business_day/following.rb,
lib/rupee/business_day/modified_previous.rb,
lib/rupee/business_day/modified_following.rb

Overview

A business day convention, used to determine the next business day should a calculated payment date fall on a non-working day

Constant Summary collapse

ACTUAL =

Actual business day convention

BusinessDay.new "Use date even if it's a non-business day" do |date, calendar|
  date
end
PREVIOUS =

Previous business day convention

BusinessDay.new "Roll to previous business day" do |date, calendar|
  while calendar.day_off?(date)
    date -= 1
  end

  date
end
FOLLOWING =

Following business day convention

BusinessDay.new "Roll to following business day" do |date, calendar|
  while calendar.day_off?(date)
    date += 1
  end

  date
end
MODIFIED_PREVIOUS =

Modified previous business day convention

BusinessDay.new "Roll to previous business day " +
  "unless it's in the previous month, then use following business day" do |date, calendar|
  month = date.month

  while calendar.day_off?(date) && date.month == month
    date -= 1
  end

  if date.month != month
    while calendar.day_off?(date)
      date += 1
    end
  else
    date
  end

  date
end
MODIFIED_FOLLOWING =

Modified following business day convention

BusinessDay.new "Roll to following business day " +
  "unless it's in the next month, then use previous business day" do |date, calendar|
  month = date.month

  while calendar.day_off?(date) && date.month == month
    date += 1
  end

  if date.month != month
    while calendar.day_off?(date)
      date -= 1
    end
  else
    date
  end

  date
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FindInstance

find

Constructor Details

#initialize(description, opts = {}, &block) ⇒ BusinessDay

Create a new business day object

Configuration options

  • :calendar - The calendar to use for calculating holidays and days off



24
25
26
27
# File 'lib/rupee/business_day.rb', line 24

def initialize(description, opts = {}, &block)
  @description = description
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

The formula for calculated the next business day



16
17
18
# File 'lib/rupee/business_day.rb', line 16

def block
  @block
end

#descriptionObject (readonly)

A description of the business day and where it’s often found



14
15
16
# File 'lib/rupee/business_day.rb', line 14

def description
  @description
end

Instance Method Details

#next_day(date, calendar) ⇒ Object

Calculates the next business day according to the calendar and the date given



31
32
33
# File 'lib/rupee/business_day.rb', line 31

def next_day(date, calendar)
  block.call date, calendar
end