Class: Teecket

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

Class Method Summary collapse

Class Method Details

.search(params) ⇒ Object



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
# File 'lib/teecket.rb', line 16

def self.search(params)
  flights = [
    "AirAsia",
    "Firefly",
    "MalaysiaAirlines",
    "MalindoAir"
  ]

  results = []
  threads = []
  flights.each do |flight|
    threads << Thread.new do
      klass = Object.const_get(flight)

      scrapper = klass.new(from: params[:from],
                           to: params[:to],
                           date: params[:date])

      scrapper.search

      results = results + scrapper.fares
    end
  end

  ThreadsWait.all_waits(*threads)

  results
end