Class: GymFinder::PostProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/gym_finder/post_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(slots) ⇒ PostProcessor

Returns a new instance of PostProcessor.



8
9
10
# File 'lib/gym_finder/post_processor.rb', line 8

def initialize(slots)
  @slots = slots
end

Instance Attribute Details

#slotsObject (readonly)

Returns the value of attribute slots.



7
8
9
# File 'lib/gym_finder/post_processor.rb', line 7

def slots
  @slots
end

Instance Method Details

#availableObject



12
13
14
# File 'lib/gym_finder/post_processor.rb', line 12

def available
  PostProcessor.new(@slots.select { |slot| slot.time_slot.status == 'available' })
end

#hour_list(list) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gym_finder/post_processor.rb', line 16

def hour_list(list)
  results = []
  @slots.group_by { |slot| [slot.gym, slot.date] }.each do |_, slots|
    list.each do |hours|
      if Set.new(hours).subset?(Set.new(slots.map { |slot| slot.time_slot.time }))
        results.concat(slots.select { |slot| hours.include? slot.time_slot.time })
      end
    end
  end
  PostProcessor.new(results)
end