Class: PlaneParser
- Inherits:
-
Object
- Object
- PlaneParser
- Defined in:
- lib/mailParser.rb
Class Method Summary collapse
-
.parse(message) ⇒ Object
The plane parser looks for specific patterns for plane tickets.
Class Method Details
.parse(message) ⇒ Object
The plane parser looks for specific patterns for plane tickets.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mailParser.rb', line 49 def self.parse() @email = #would Idealy have this as a database call airlines = ["aer lingus", "asl airlines ireland", "cityjet", "norwegian air international", "ryanair", "stobard air"] trip = Trip.new trip.category = "plane" airlines.each do |word| if @email.body.include?(word) trip.carrier = word end end #airline confirmation numbers are always 3 capital letters followed by 4 digits trip.confirmationNumber = @email.body.match(/[A-Z]{3}\d{4}/)[0] string = @email.body.to_s #times are displayed as a 12 hour digital display ending with an a or p times = string.scan(/(\d:\d\d[a|p]|\d\d:\d\d[a|p])/) trip.startTime = times[0][0] trip.endTime = times[1][0] #locations are a 3 capital character format locations = string.scan(/[A-Z]{3}\b/) trip.startLocation = locations[0] trip.endLocation = locations[1] #dates use the 00/00/00 format dates = string.scan(/\d{2}\/\d{2}\/\d{2}/) trip.startDate = dates[0] trip.endDate = dates[1] return trip end |