flightcheck 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/flightcheck.rb +56 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5648fb618f9441ef33e3a1bff16d418cdb8d61c3
4
- data.tar.gz: d2d069e30c372f2388a8ba2f4782e9ae43b2422a
3
+ metadata.gz: 5e305044fb746cf2c50727f31bd1075b81022186
4
+ data.tar.gz: b1a3d8eeeea3f267364310c44223a7f7ea7e3d77
5
5
  SHA512:
6
- metadata.gz: 20a9c2c0da573f964270277e37b3c07638b2c6f1009bbb4369bf03562854bde50fa3ff4d8bfb63bd0a1f4b793d4bfe448ff5b7130933780048449b76d9a2ad85
7
- data.tar.gz: 918596fe39ffc9d7e6c9e6e686aae35b85f192fadab1da47147c19726b93cab934cb3b32cf9bb3e384ce3e4df2350af1359b490952f5b8dbbee97c1198ee9397
6
+ metadata.gz: 279499c474d34255037df1d884266d7b0a3a2888f2551a8d61d2deb4a0c82edf72f4b7588c18cce3fae06cb581cf89d48cf1df2e2fd098e933e6f9e02c940398
7
+ data.tar.gz: f5ddcfbfd85609bdfbdf2e4fc772c81acabe4db8fd3138ac5247bfbfeb3c2236af5fdb59cc3f7342667e88844826c27df3b0128e1a2c13dfdc659a10e7a9db45
data/lib/flightcheck.rb CHANGED
@@ -1,39 +1,79 @@
1
1
  require 'mechanize'
2
2
 
3
3
  class Flight
4
- attr_reader :flightNumber, :departureDate, :title, :status, :url, :raw_airline_iata, :airline_iata, :departure_airport, :arrival_airport
5
-
6
- def initialize(flightNumber, departureDate)
7
- @flightNumber = flightNumber
8
- @departureDate = departureDate
9
- @url = "http://www.flightstats.com/go/FlightStatus/flightStatusByFlight.do?airline=&flightNumber=#{flightNumber}&departureDate=#{departureDate}"
10
- @airline_iata = nil
11
- @departure_airport = nil
12
- @arrival_airport = nil
4
+ attr_reader :flight_number, :departure_date, :title, :status, :route, :url, :raw_airline_iata, :airline_iata, :departure_airport, :arrival_airport
5
+
6
+ ## Initialize
7
+ def initialize(flight_number, departure_date)
8
+
9
+ # Flight number
10
+ # e.g. "BA2589"
11
+ @flight_number = flight_number
12
+
13
+ # Departure date
14
+ # e.g. "2014-05-29"
15
+ @departure_date = departure_date
16
+
17
+ # FlightStats URL
18
+ @url = "http://www.flightstats.com/go/FlightStatus/flightStatusByFlight.do?airline=&flightNumber=#{flight_number}&departureDate=#{departure_date}"
13
19
  end
14
20
 
21
+ ## Use Mechanize to scrape all flight information
15
22
  def check
23
+
24
+ # Instantiate a new Mechanize object
16
25
  a = Mechanize.new
26
+
27
+ # Visit the flightstats URL to scrape information
17
28
  a.get(@url) do |page|
29
+
30
+ # Page title contains the basic information for the flight
31
+ # e.g. "(BA) British Airways 2589 Flight Status"
18
32
  @title = page.search("head > title").text.strip
33
+
34
+ # Flight status
35
+ # e.g. "Landed - Delayed 103 minutes"
19
36
  @status = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.statusBlock > div.statusType").text.strip
20
- end
21
37
 
22
- puts @title
23
- puts @status
38
+ # Flight route
39
+ # e.g. "(VCE) Venice, IT to (LGW) London, EN, GB"
40
+ @route = page.search("#mainAreaLeftColumn > div.uiComponent674.flightStatusByFlightBlock > div > div.route").text.strip
41
+
42
+ end
24
43
 
25
44
  ## Airline IATA
26
- # Extract raw airline iata and convert to string to avoid
45
+ # Extract raw airline iata and convert to string to avoid
27
46
  # TypeError: no implicit conversion of MatchData intro String
28
47
  @raw_airline_iata = /\(\w+\)/.match(@title).to_s
29
48
 
30
- # Extract the airline IATA without the paraentheses
49
+ # Extract the airline IATA without the parentheses
31
50
  @airline_iata = /\w+/.match(@raw_airline_iata)
32
51
 
33
52
  ## Departure airport IATA
34
- # Code here
53
+ # @raw_departure_airport_iata = /\w+/.match(@route).to_s
35
54
 
36
55
  ## Arrival airport IATA
37
56
  # Code here
57
+
58
+ ## Flight route
59
+ # Cleanup the scraped route information
60
+
61
+ # Delete all "\t" from the string
62
+ @route.delete!("\t")
63
+
64
+ # Substitue all "\n\n" with " "
65
+ @route.gsub!("\n\n", " ")
66
+
67
+ # Substitue all "\n" with " "
68
+ @route.gsub!("\n", " ")
69
+
70
+ # Substitue all " " with " "
71
+ @route.gsub!(" ", " ")
72
+
73
+ ## Information
74
+ # Print all relevant information to te console
75
+ puts @title
76
+ puts @status
77
+ puts @route
38
78
  end
39
- end
79
+ 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.5
4
+ version: 0.0.6
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-25 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize