Module: InBusiness
- Defined in:
- lib/in_business.rb,
lib/in_business/version.rb
Constant Summary collapse
- VERSION =
'0.0.2'
Class Method Summary collapse
- .closed?(datetime) ⇒ Boolean
-
.days ⇒ Object
Maps values of [DateTime/Date/Time]#wday to English days.
- .holidays ⇒ Object
- .holidays=(array) ⇒ Object
- .hours ⇒ Object
- .hours=(hash) ⇒ Object
- .is_holiday?(date) ⇒ Boolean
- .open?(datetime) ⇒ Boolean
- .reset ⇒ Object
Class Method Details
.closed?(datetime) ⇒ Boolean
48 49 50 |
# File 'lib/in_business.rb', line 48 def self.closed?(datetime) !open?(datetime) end |
.days ⇒ Object
Maps values of [DateTime/Date/Time]#wday to English days
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/in_business.rb', line 57 def self.days { "0" => "sunday", "1" => "monday", "2" => "tuesday", "3" => "wednesday", "4" => "thursday", "5" => "friday", "6" => "saturday" } end |
.holidays ⇒ Object
9 10 11 |
# File 'lib/in_business.rb', line 9 def self.holidays @holidays end |
.holidays=(array) ⇒ Object
13 14 15 |
# File 'lib/in_business.rb', line 13 def self.holidays=(array) @holidays = array end |
.hours ⇒ Object
17 18 19 |
# File 'lib/in_business.rb', line 17 def self.hours @hours end |
.hours=(hash) ⇒ Object
21 22 23 |
# File 'lib/in_business.rb', line 21 def self.hours=(hash) @hours = OpenStruct.new(hash) end |
.is_holiday?(date) ⇒ Boolean
52 53 54 |
# File 'lib/in_business.rb', line 52 def self.is_holiday?(date) @holidays.include? date.to_date end |
.open?(datetime) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/in_business.rb', line 32 def self.open?(datetime) # If this is included in the list of holidays, return false return false if is_holiday? datetime # If we don't know the opening hours for datetime's day, assume we're closed return false unless hours.send(days[datetime.wday.to_s].to_sym) # We have opening hours, so check if the current time is within them if !hours.send(days[datetime.wday.to_s].to_sym).include? datetime.strftime("%H:%M") return false end true # It's not not open, so it must be open ;) end |
.reset ⇒ Object
25 26 27 28 29 30 |
# File 'lib/in_business.rb', line 25 def self.reset # Used for clearing the state of InBusiness between specs @holidays = [] @hours = OpenStruct.new true end |