Class: Roxbury::BusinessDay

Inherits:
Object
  • Object
show all
Defined in:
lib/roxbury/business_day.rb

Overview

Wraps a specific date with its working hours schedule

Instance Method Summary collapse

Constructor Details

#initialize(date, working_hours) ⇒ BusinessDay

Returns a new instance of BusinessDay.



4
5
6
7
# File 'lib/roxbury/business_day.rb', line 4

def initialize date, working_hours
  @date = date
  @working_hours = working_hours
end

Instance Method Details

#at_beginningObject



29
30
31
# File 'lib/roxbury/business_day.rb', line 29

def at_beginning
  @working_hours.at_beginning @date
end

#at_endObject



33
34
35
# File 'lib/roxbury/business_day.rb', line 33

def at_end
  @working_hours.at_end @date
end

#ends_before?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


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

def ends_before? timestamp
  same_day?(timestamp) && @working_hours.ends_before?(timestamp)
end

#include?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/roxbury/business_day.rb', line 17

def include? timestamp
  same_day?(timestamp) && @working_hours.include?(timestamp)
end

#number_of_working_hours(*args) ⇒ Object



9
10
11
# File 'lib/roxbury/business_day.rb', line 9

def number_of_working_hours *args
  @working_hours.quantity *args
end

#same_day?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/roxbury/business_day.rb', line 13

def same_day? timestamp
  timestamp.to_date == @date.to_date
end

#starts_after?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/roxbury/business_day.rb', line 21

def starts_after? timestamp
  same_day?(timestamp) && @working_hours.starts_after?(timestamp)
end