Class: Availability::Hourly

Inherits:
Daily show all
Extended by:
Createable
Defined in:
lib/availability/hourly.rb

Instance Attribute Summary

Attributes inherited from AbstractAvailability

#capacity, #duration, #exclusions, #interval, #residue, #start_time, #stops_by

Instance Method Summary collapse

Methods included from Createable

create, extended

Methods inherited from AbstractAvailability

#beginning, #corresponds_to?, #end_time, #initialize, #initialize_copy, #last_occurrence, #next_n_occurrences, #next_occurrence, #time_overlaps?

Methods included from FactoryMethods

#create, #once

Methods included from ClassMethods

#availability?, #beginning, #default_args, #subclass_for

Methods inherited from InstanceVariableComparability

#<=>

Constructor Details

This class inherits a constructor from Availability::AbstractAvailability

Instance Method Details

#includes?(time) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/availability/hourly.rb', line 17

def includes?(time)
  return true if super
  return false if residue_for(time) != residue
  hours_on_same_day = next_n_occurrences(24, time).select {|t| t.wday == time.wday && t <= time }
  hours_on_same_day.none? {|hour| exclusions.any?{|excl| excl.violated_by? hour}} &&
    hours_on_same_day.any?{|hour| time_overlaps? time, hour, hour + duration}
end

#interval_difference(this, that) ⇒ Object



8
9
10
11
# File 'lib/availability/hourly.rb', line 8

def interval_difference(this, that)
  first, second = [this, that].sort
  (second.to_i - first.to_i) / 1.hour
end

#move_by(time, amount) ⇒ Object



13
14
15
# File 'lib/availability/hourly.rb', line 13

def move_by(time, amount)
  time + amount.hours
end

#residue_for(time) ⇒ Object



25
26
27
# File 'lib/availability/hourly.rb', line 25

def residue_for(time)
  interval_difference(time, beginning.to_time).modulo(@interval)
end