Class: BusinessTime::BusinessDays

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(days) ⇒ BusinessDays

Returns a new instance of BusinessDays.



8
9
10
# File 'lib/business_time/business_days.rb', line 8

def initialize(days)
  @days = days
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



6
7
8
# File 'lib/business_time/business_days.rb', line 6

def days
  @days
end

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
15
16
17
# File 'lib/business_time/business_days.rb', line 12

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

#after(time = Time.current) ⇒ Object Also known as: from_now, since



19
20
21
# File 'lib/business_time/business_days.rb', line 19

def after(time = Time.current)
  non_negative_days? ? calculate_after(time, @days) : calculate_before(time, -@days)
end

#before(time = Time.current) ⇒ Object Also known as: ago, until



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

def before(time = Time.current)
  non_negative_days? ? calculate_before(time, @days) : calculate_after(time, -@days)
end