class BusinessPeriod::Base

Constants

SEPARATOR

Public Instance Methods

calculate_period(to_date, options = nil) click to toggle source
# File lib/business_period/base.rb, line 11
def calculate_period(to_date, options = nil)
  magic_number = 15 - config.work_days.size
  days_to_add = days_to_seconds(to_date * magic_number)
  start_date = options[:primary_day] || Time.now
  finish = start_date + days_to_add
  start_date.to_date..finish.to_date
end
config() click to toggle source
# File lib/business_period/base.rb, line 7
def config
  @config ||= Config
end
day_is_holiday?(day) click to toggle source
# File lib/business_period/base.rb, line 33
def day_is_holiday?(day)
  holidays.flatten.include? holiday_month_with_day(day.month, day.day)
end
holiday_month_with_day(month, day) click to toggle source
# File lib/business_period/base.rb, line 29
def holiday_month_with_day(month, day)
  [month, day].join(SEPARATOR)
end
holidays() click to toggle source
# File lib/business_period/base.rb, line 19
def holidays
  @holidays ||= begin
    holidays_config.each_with_object([]) do |row, container|
      container << row.last.map do |days|
        holiday_month_with_day(row.first, days['mday'])
      end
    end
  end
end

Private Instance Methods

days_to_seconds(days) click to toggle source
# File lib/business_period/base.rb, line 47
def days_to_seconds(days)
  days * 60 * 60 * 24
end
holiday_config() click to toggle source
# File lib/business_period/base.rb, line 43
def holiday_config
  [File.dirname(__FILE__), "../../config/holidays/#{config.locale}.yml"]
end
holidays_config() click to toggle source
# File lib/business_period/base.rb, line 39
def holidays_config
  @holidays_config ||= YAML.load_file(File.join(holiday_config)).fetch('months')
end