89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/mailParser.rb', line 89
def self.parse(message)
@email = message
railcarriers = ["dart", "northern commuter", "south eastern commuter", "south western commuter", "western commuter"]
stations = ["malahide", "heuston", "portlaoise", "portmarnock"]
trip = Trip.new
trip.category = "train"
railcarriers.each do |word|
if @email.body.include?(word)
trip.carrier = word
end
end
trip.confirmationNumber = @email.body.match(/\d{11}/)[0]
string = @email.body.to_s
times = string.scan(/\d:\d\d|\d\d:\d\d/)
trip.startTime = times[0]
trip.endTime = times[1]
first = true
stations.each do |word|
if @email.body.include?(word)
if first == true
trip.startLocation = word
first = false
else
trip.endLocation = word
first = true
end
end
end
dates = string.scan(/\d{2}\/\d{2}\/\d{2}/)
trip.startDate = dates[0]
trip.endDate = dates[1]
return trip
end
|