Class: BusParser

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

Class Method Summary collapse

Class Method Details

.parse(message) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/mailParser.rb', line 135

def self.parse(message)
    
    @email = message
    buscarriers = ["bus eireann", "matthews"]
    trip = Trip.new
    trip.category = "bus"
    
    buscarriers.each do |word|
        if @email.body.include?(word)
            trip.carrier = word
        end
    end
    
     trip.confirmationNumber = @email.body.match(/[a-zA-Z]{3}\d{4}/)[0]
    string = @email.body.to_s
    
    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 = string.scan(/[A-Z]{3}\b/)
    trip.startLocation = locations[0]
    trip.endLocation = locations[1]
    
    dates = string.scan(/\d{2}\/\d{2}\/\d{2}/)
    trip.startDate = dates[0]
    trip.endDate = dates[1]
    
    return trip
    
end