class GymFinder::PostProcessor

Attributes

slots[R]

Public Class Methods

new(slots) click to toggle source
# File lib/gym_finder/post_processor.rb, line 8
def initialize(slots)
  @slots = slots
end

Public Instance Methods

available() click to toggle source
# 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) click to toggle source
# 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