Class: GymFinder::PostProcessor
- Inherits:
-
Object
- Object
- GymFinder::PostProcessor
- Defined in:
- lib/gym_finder/post_processor.rb
Instance Attribute Summary collapse
-
#slots ⇒ Object
readonly
Returns the value of attribute slots.
Instance Method Summary collapse
- #available ⇒ Object
- #hour_list(list) ⇒ Object
-
#initialize(slots) ⇒ PostProcessor
constructor
A new instance of PostProcessor.
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
#slots ⇒ Object (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
#available ⇒ Object
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 |