Class: Artic::Calendar
- Inherits:
-
Object
- Object
- Artic::Calendar
- Defined in:
- lib/artic/calendar.rb
Overview
A calendar keeps track of both your availabilities and your occupations.
Instance Attribute Summary collapse
- #availabilities ⇒ Collection::AvailabilityCollection readonly
-
#occupations ⇒ Object
readonly
Returns the value of attribute occupations.
Instance Method Summary collapse
-
#available_slots_on(dow_or_date) ⇒ Object
Returns the slots available on the given day of the week or date, including any slots that might be occupied on the given date.
-
#free_slots_on(date) ⇒ Object
Returns the slots free on the given date, computed by calling Occupation#bisect on each of the availability slots.
-
#initialize ⇒ Calendar
constructor
Initializes the calendar.
Constructor Details
#initialize ⇒ Calendar
Initializes the calendar.
15 16 17 18 |
# File 'lib/artic/calendar.rb', line 15 def initialize @availabilities = Collection::AvailabilityCollection.new @occupations = Collection::OccupationCollection.new end |
Instance Attribute Details
#availabilities ⇒ Collection::AvailabilityCollection (readonly)
12 13 14 |
# File 'lib/artic/calendar.rb', line 12 def availabilities @availabilities end |
#occupations ⇒ Object (readonly)
Returns the value of attribute occupations.
12 |
# File 'lib/artic/calendar.rb', line 12 attr_reader :availabilities, :occupations |
Instance Method Details
#available_slots_on(dow_or_date) ⇒ Object
Returns the slots available on the given day of the week or date, including any slots that might be occupied on the given date.
If the passed argument is an instance of Date
but no availabilities have been defined for that specific date, returns any availabilities defined for that day of the week.
36 37 38 39 40 41 42 |
# File 'lib/artic/calendar.rb', line 36 def available_slots_on(dow_or_date) if !availabilities.identifier?(dow_or_date) && dow_or_date.is_a?(Date) && availabilities.identifier?(dow_or_date.strftime('%A').downcase) return available_slots_on(dow_or_date.strftime('%A').downcase) end availabilities.normalize dow_or_date end |
#free_slots_on(date) ⇒ Object
Returns the slots free on the given date, computed by calling Occupation#bisect on each of the availability slots.
52 53 54 55 56 57 58 59 |
# File 'lib/artic/calendar.rb', line 52 def free_slots_on(date) normalized_occupations = occupations.normalize(date) availabilities = available_slots_on(date).flat_map do |availability| normalized_occupations.bisect(availability) end Collection::AvailabilityCollection.new availabilities end |