Class: Availabiliter::TimeFrame
- Inherits:
-
Object
- Object
- Availabiliter::TimeFrame
- Defined in:
- lib/availabiliter/timeframe.rb
Overview
A TimeFrame is an object representing several DateRange instances. It can have a start. It can have only one endless DateRange.
Instance Attribute Summary collapse
-
#date_ranges ⇒ Object
readonly
Returns the value of attribute date_ranges.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Instance Method Summary collapse
- #availabilities ⇒ Object
-
#initialize(array, start_date = nil) ⇒ TimeFrame
constructor
A new instance of TimeFrame.
Constructor Details
#initialize(array, start_date = nil) ⇒ TimeFrame
Returns a new instance of TimeFrame.
11 12 13 14 15 16 |
# File 'lib/availabiliter/timeframe.rb', line 11 def initialize(array, start_date = nil) @start_date = start_date @date_ranges = build_date_ranges(array) raise ArgumentError unless valid? end |
Instance Attribute Details
#date_ranges ⇒ Object (readonly)
Returns the value of attribute date_ranges.
9 10 11 |
# File 'lib/availabiliter/timeframe.rb', line 9 def date_ranges @date_ranges end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
9 10 11 |
# File 'lib/availabiliter/timeframe.rb', line 9 def start_date @start_date end |
Instance Method Details
#availabilities ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/availabiliter/timeframe.rb', line 18 def availabilities return [start_date..nil] if date_ranges.empty? return build_availabilities if start_date.nil? availabilities = build_availabilities start_date < first_date_range.start_date ? availabilities.unshift(first_availability) : availabilities end |