flightcheck 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/flightcheck.rb +54 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdb7135f2e28deaff5f27571923eb7b603fc58ec
4
- data.tar.gz: e3d30b474b4bc5a2b2e199eaa1ca1975d8e746f6
3
+ metadata.gz: 8d7279bcf039e1885bbd60fd2fb7d808a8592c70
4
+ data.tar.gz: 5fe29ad744055798a6a52fb33f92c29c319e181c
5
5
  SHA512:
6
- metadata.gz: ef8e83ffee2b4f3657f47a378af5c697bb1a2c7e2bdedb6871b91b931f45e39bfa55d19a338f0d68009babdc12bec9bee0283a0ee6bf13bf0910156bd61e6318
7
- data.tar.gz: d7c12d9d9bcc327af9038842499334d274f650c9cea3dccd823d396a6a069b4f47f82a6bcd71de5ffa731a41a903649cbbaf7b43ed69b0cd61c05225f042d5f3
6
+ metadata.gz: d5cd02f37e734ca4db3f6594a69cd1c2bf7cbcdcfa3c5bb6f64e48fc8083faf7639797183cb8c5d441cd3f8a5e3a429cb083c21430bc518621f5d10537177de1
7
+ data.tar.gz: 1219acd2740153dc1c266d42014c453e876e0003248235bdee13f19457a6b51c146b3f6ebbaacb4dd4b187c4b1ace3eb64979727c6b79ab71b103608730bca38
data/lib/flightcheck.rb CHANGED
@@ -4,11 +4,11 @@ class Flight
4
4
  attr_reader :flight_number, :departure_date, :title, :status, :route, :url,
5
5
  :raw_airline_iata, :airline_iata, :route_array, :departure_airport_iata,
6
6
  :departure_airport_city, :departure_country_iata, :arriving_airport_iata,
7
- :arriving_airport_city, :arriving_country_iata
7
+ :arriving_airport_city, :arriving_country_iata, :multiple_segments,
8
+ :segment_1, :segment_2, :selected_segment, :segment_1, :segment_2
8
9
 
9
10
  ## Initialize
10
11
  def initialize(flight_number, departure_date)
11
-
12
12
  # Flight number
13
13
  # e.g. "BA2589"
14
14
  @flight_number = flight_number
@@ -23,25 +23,63 @@ class Flight
23
23
 
24
24
  ## Use Mechanize to scrape all flight information
25
25
  def check
26
-
27
26
  # Instantiate a new Mechanize object
28
27
  a = Mechanize.new
29
28
 
30
29
  # Visit the flightstats URL to scrape information
31
30
  a.get(@url) do |page|
32
-
33
- # Page title contains the basic information for the flight
34
- # e.g. "(BA) British Airways 2589 Flight Status"
35
- @title = page.search("head > title").text.strip
36
-
37
- # Flight status
38
- # e.g. "Landed - Delayed 103 minutes"
39
- @status = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.statusBlock > div.statusType").text.strip
40
-
41
- # Flight route
42
- # e.g. "(VCE) Venice, IT to (LGW) London, EN, GB"
43
- @route = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.route").text.strip
44
-
31
+ # Check if flight has multiple segments
32
+ # Returns a boolean value
33
+ @multiple_segments = page.search("//*[@id='mainAreaLeftColumn']/div/div/text()").text.strip === "This flight has multiple segments. Please select a segment from the list." ? true : false
34
+
35
+ if @multiple_segments == true
36
+
37
+ @segment_1 = page.search("//*[@id='mainAreaLeftColumn']/div/div/p[1]/a").text.strip
38
+ @segment_2 = page.search("//*[@id='mainAreaLeftColumn']/div/div/p[2]/a").text.strip
39
+
40
+ puts "This flight has two flight segments,"
41
+ puts "please select the correct one"
42
+ puts "========================================"
43
+ puts "Segment 1: #{@segment_1}"
44
+ puts "Segment 2: #{@segment_2}"
45
+ puts "----------------------------------------"
46
+ print "1 or 2? Make your choice: "
47
+ @selected_segment = gets.chomp
48
+
49
+ if @selected_segment == "1"
50
+ @segment_1 = page.links[0].click
51
+
52
+ # Page title contains the basic information for the flight
53
+ # e.g. "(BA) British Airways 2589 Flight Status"
54
+ @title = @segment_1.search("head > title").text.strip
55
+
56
+ # Flight status
57
+ # e.g. "Landed - Delayed 103 minutes"
58
+ @status = @segment_1.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.statusBlock > div.statusType").text.strip
59
+
60
+ # Flight route
61
+ # e.g. "(VCE) Venice, IT to (LGW) London, EN, GB"
62
+ @route = @segment_1.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.route").text.strip
63
+
64
+ elsif @selected_segment == "2"
65
+ @segment_2 = page.links[1].click
66
+
67
+ # Page title contains the basic information for the flight
68
+ # e.g. "(BA) British Airways 2589 Flight Status"
69
+ @title = @segment_2.search("head > title").text.strip
70
+
71
+ # Flight status
72
+ # e.g. "Landed - Delayed 103 minutes"
73
+ @status = @segment_2.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.statusBlock > div.statusType").text.strip
74
+
75
+ # Flight route
76
+ # e.g. "(VCE) Venice, IT to (LGW) London, EN, GB"
77
+ @route = @segment_2.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.route").text.strip
78
+
79
+ else
80
+ puts "The input was unknown. Please use '1' for segment 1 and '2' for segment 2"
81
+ end
82
+ end
45
83
  end
46
84
 
47
85
  ## Airline IATA
@@ -87,8 +125,5 @@ class Flight
87
125
  puts @title
88
126
  puts @status
89
127
  puts @route
90
-
91
-
92
-
93
128
  end
94
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flightcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Narek Aramjan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize