3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/mailParser.rb', line 3
def self.receive_mail(message)
@email = message
strategy = @strategies
@strategies = {}
@strategies['Plane'] = PlaneParser
@strategies['Train'] = TrainParser
@strategies['Bus'] = BusParser
puts "++++++++++++++++++++++++++++++++++"
puts message.body.inspect
puts "++++++++++++++++++++++++++++++++++"
airplane = ["plane", "airplane", "flight"]
train = ["train", "rail"]
bus = ["bus"]
airplane.each do |word|
if @email.body.include?(word)
strategy = @strategies["Plane"]
end
end
train.each do |word|
if @email.body.include?(word)
strategy = @strategies["Train"]
end
end
bus.each do |word|
if @email.body.include?(word)
strategy = @strategies["Bus"]
end
end
trip = strategy.parse(message)
return trip
end
|