| 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 | # File 'lib/reservation/event_filter.rb', line 13
def filter_events options
  from = options["from"]
  upto = options["upto"]
  context = options["context"]
  schedule = options["schedule"]
  events = ::Reservation.events
  if from
    from = from.is_a?(String) ? Date.parse(from) : from.to_date
    events = events.since(from)
  end
  if upto
    upto = upto.is_a?(String) ? parse_time_for_upto(upto) : upto.to_time if upto
    events = events.upto(upto) if upto
  end
  if context
    context = [context] unless context.is_a? Array
    context = context.uniq
    events = context.inject(events) { |ee, ctx|
      ee.reserved_for(ctx)
    }
  end
  if schedule
    schedule = ::Reservation::Schedule::Weekly.new schedule
    events = schedule.filter events
  end
  events
end
 |