Class: BusinessDays::BusinessDayDuration
- Inherits:
-
Object
- Object
- BusinessDays::BusinessDayDuration
- Defined in:
- lib/business_days.rb
Instance Method Summary collapse
- #+(time) ⇒ Object
- #calculate_duration(time, operation) ⇒ Object
-
#initialize(days) ⇒ BusinessDayDuration
constructor
A new instance of BusinessDayDuration.
Constructor Details
#initialize(days) ⇒ BusinessDayDuration
Returns a new instance of BusinessDayDuration.
8 9 10 |
# File 'lib/business_days.rb', line 8 def initialize(days) @days = days end |
Instance Method Details
#+(time) ⇒ Object
22 23 24 |
# File 'lib/business_days.rb', line 22 def +(time) calculate_duration(time, :+) end |
#calculate_duration(time, operation) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/business_days.rb', line 12 def calculate_duration(time, operation) business_days = time.is_business_day? ? 1 : 0 while business_days <= @days if (time = time.send(operation, 1.day)).is_business_day? business_days += 1 end end time end |