Class: BusinessTime::BusinessHours

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/business_time/business_hours.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hours) ⇒ BusinessHours

Returns a new instance of BusinessHours.



7
8
9
# File 'lib/business_time/business_hours.rb', line 7

def initialize(hours)
  @hours = hours
end

Instance Attribute Details

#hoursObject (readonly)

Returns the value of attribute hours.



5
6
7
# File 'lib/business_time/business_hours.rb', line 5

def hours
  @hours
end

Instance Method Details

#<=>(other) ⇒ Object



11
12
13
14
15
16
# File 'lib/business_time/business_hours.rb', line 11

def <=>(other)
  if other.class != self.class
    raise ArgumentError.new("#{self.class.to_s} can't be compared with #{other.class.to_s}")
  end
  self.hours <=> other.hours
end

#after(time) ⇒ Object Also known as: since



26
27
28
# File 'lib/business_time/business_hours.rb', line 26

def after(time)
  non_negative_hours? ? calculate_after(time, @hours) : calculate_before(time, -@hours)
end

#agoObject



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

def ago
  Time.zone ? before(Time.zone.now) : before(Time.now)
end

#before(time) ⇒ Object



31
32
33
# File 'lib/business_time/business_hours.rb', line 31

def before(time)
  non_negative_hours? ? calculate_before(time, @hours) : calculate_after(time, -@hours)
end

#from_nowObject



22
23
24
# File 'lib/business_time/business_hours.rb', line 22

def from_now
  Time.zone ?  after(Time.zone.now) : after(Time.now)
end