Class: BusinessTime::BusinessDays
- Inherits:
-
Object
- Object
- BusinessTime::BusinessDays
- Includes:
- Comparable
- Defined in:
- lib/business_time/business_days.rb
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #after(time = Time.current) ⇒ Object (also: #from_now, #since)
- #before(time = Time.current) ⇒ Object (also: #ago, #until)
-
#initialize(days) ⇒ BusinessDays
constructor
A new instance of BusinessDays.
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
#days ⇒ Object (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 |