Class: Unavailability::UnavailableDates::Remove

Inherits:
Object
  • Object
show all
Defined in:
lib/unavailability/unavailable_dates/remove.rb

Instance Method Summary collapse

Constructor Details

#initialize(dateable, from, to) ⇒ Remove

Returns a new instance of Remove.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
# File 'lib/unavailability/unavailable_dates/remove.rb', line 4

def initialize(dateable, from, to)
  @dateable = dateable
  @from    = from
  @to      = to

  raise ArgumentError.new('from has to be a Date') unless @from.is_a?(Date)
  raise ArgumentError.new('to has to be a Date') unless @to.is_a?(Date)
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unavailability/unavailable_dates/remove.rb', line 17

def call
  if overlappings.empty?
    # do nothing
  else
    overlappings.each do |unavailability|
      update(unavailability, from, to)
    end
  end

  dateable
end

#unavailable_datesObject



13
14
15
# File 'lib/unavailability/unavailable_dates/remove.rb', line 13

def unavailable_dates
  dateable.unavailable_dates
end