Class: BusinessTime::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/business_time/config.rb

Overview

controls the behavior of this gem. You can change the beginning_of_workday, end_of_workday, and the list of holidays manually, or with a yaml file and the load method.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.beginning_of_workdayObject

You can set this yourself, either by the load method below, or by saying

BusinessTime::Config.beginning_of_workday = "8:30 am"

someplace in the initializers of your application.



12
13
14
# File 'lib/business_time/config.rb', line 12

def beginning_of_workday
  @beginning_of_workday
end

.end_of_workdayObject

You can set this yourself, either by the load method below, or by saying

BusinessTime::Config.end_of_workday = "5:30 pm"

someplace in the initializers of your application.



18
19
20
# File 'lib/business_time/config.rb', line 18

def end_of_workday
  @end_of_workday
end

.holidaysObject

You can set this yourself, either by the load method below, or by saying

BusinessTime::Config.holidays << my_holiday_date_object

someplace in the initializers of your application.



24
25
26
# File 'lib/business_time/config.rb', line 24

def holidays
  @holidays
end

Class Method Details

.load(filename) ⇒ Object

loads the config data from a yaml file written as:

business_time:
  beginning_od_workday: 8:30 am
  end_of_workday: 5:30 pm
  holidays:
    - Jan 1st, 2010
    - July 4th, 2010
    - Dec 25th, 2010


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/business_time/config.rb', line 43

def self.load(filename)
  self.reset
  data = YAML::load(File.open(filename))
  self.beginning_of_workday = data["business_time"]["beginning_of_workday"]
  self.end_of_workday = data["business_time"]["end_of_workday"]
  data["business_time"]["holidays"].each do |holiday|
    self.holidays <<
      Time.zone ? Time.zone.parse(holiday) : Time.parse(holiday)
  end
  
end

.resetObject



28
29
30
31
32
# File 'lib/business_time/config.rb', line 28

def self.reset
  self.holidays = []
  self.beginning_of_workday = "9:00 am"
  self.end_of_workday = "5:00 pm"
end