Class: Unavailability::UnavailableDates::Add

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

Instance Method Summary collapse

Constructor Details

#initialize(dateable, from, to) ⇒ Add

Returns a new instance of Add.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
# File 'lib/unavailability/unavailable_dates/add.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
28
29
30
31
32
# File 'lib/unavailability/unavailable_dates/add.rb', line 17

def call
  if overlappings.empty?
    unavailable_dates.create(
      from: from,
      to: to
    )
  else
    overlappings.each do |unavailability|
      update(unavailability, from, to)
    end

    merge(overlappings)
  end

  dateable
end

#unavailable_datesObject



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

def unavailable_dates
  dateable.unavailable_dates
end