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