ncirlMailParser 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/mailParser.rb +116 -27
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94d52ebac07b0f5d633b7fdd75f480b3c9febb13
|
4
|
+
data.tar.gz: 5351ba94feb30746c4c80bacbb63af66be401c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60fdd13d915b93bdf0f63b6f778919513f852d971bbed23fa79fc5fbde78eded6b90142d4b50eea9ca062933c7d902de45326b0e556176e7ef014ac263796ebf
|
7
|
+
data.tar.gz: 3ff4ef0fae07ea5ff6da1984c859ba29203edb9cb3903f339f06a523c9140bd20fadf3b8ab88f4a2a6a4fc46bdff2690f1024d26da96a9e9a5a1b09a1cae27a5
|
data/lib/mailParser.rb
CHANGED
@@ -1,62 +1,151 @@
|
|
1
1
|
module MailParser
|
2
|
+
|
2
3
|
def self.receive_mail(message)
|
3
4
|
|
5
|
+
@email = message
|
6
|
+
strategy = @strategies
|
7
|
+
|
8
|
+
|
9
|
+
@strategies = {}
|
10
|
+
@strategies['Plane'] = PlaneParser
|
11
|
+
@strategies['Train'] = TrainParser
|
12
|
+
@strategies['Bus'] = BusParser
|
13
|
+
|
4
14
|
puts "++++++++++++++++++++++++++++++++++"
|
5
15
|
puts message.body.inspect
|
6
16
|
puts "++++++++++++++++++++++++++++++++++"
|
7
|
-
|
8
|
-
@email = message
|
9
|
-
|
17
|
+
|
10
18
|
#take from DB
|
11
19
|
airplane = ["plane", "airplane", "flight"]
|
12
20
|
train = ["train", "rail"]
|
13
21
|
bus = ["bus"]
|
14
|
-
|
15
|
-
airlines = ["aer lingus", "asl airlines ireland", "cityjet", "norwegian air international", "ryanair", "stobard air"]
|
16
|
-
railcarriers = ["dart", "northern commuter", "south eastern commuter", "south western commuter", "western commuter"]
|
17
|
-
buscarriers = ["bus eireann", "matthews"]
|
18
22
|
|
19
|
-
trip = Trip.new
|
20
|
-
|
21
23
|
airplane.each do |word|
|
22
24
|
if @email.body.include?(word)
|
23
|
-
|
25
|
+
strategy = @strategies["Plane"]
|
24
26
|
end
|
25
27
|
end
|
26
28
|
train.each do |word|
|
27
29
|
if @email.body.include?(word)
|
28
|
-
|
30
|
+
strategy = @strategies["Train"]
|
29
31
|
end
|
30
32
|
end
|
31
33
|
bus.each do |word|
|
32
34
|
if @email.body.include?(word)
|
33
|
-
|
35
|
+
strategy = @strategies["Bus"]
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
trip = strategy.parse(message)
|
40
|
+
|
41
|
+
return trip
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class PlaneParser
|
47
|
+
|
48
|
+
#The plane parser looks for specific patterns for plane tickets.
|
49
|
+
def self.parse(message)
|
50
|
+
|
51
|
+
@email = message
|
52
|
+
#would Idealy have this as a database call
|
53
|
+
airlines = ["aer lingus", "asl airlines ireland", "cityjet", "norwegian air international", "ryanair", "stobard air"]
|
54
|
+
trip = Trip.new
|
55
|
+
trip.category = "plane"
|
56
|
+
|
57
|
+
airlines.each do |word|
|
58
|
+
if @email.body.include?(word)
|
40
59
|
trip.carrier = word
|
41
|
-
end
|
42
60
|
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#airline confirmation numbers are always 3 capital letters followed by 4 digits
|
64
|
+
trip.confirmationNumber = @email.body.match(/[A-Z]{3}\d{4}/)[0]
|
65
|
+
string = @email.body.to_s
|
66
|
+
|
67
|
+
#times are displayed as a 12 hour digital display ending with an a or p
|
68
|
+
times = string.scan(/(\d:\d\d[a|p]|\d\d:\d\d[a|p])/)
|
69
|
+
trip.startTime = times[0][0]
|
70
|
+
trip.endTime = times[1][0]
|
71
|
+
|
72
|
+
#locations are a 3 capital character format
|
73
|
+
locations = string.scan(/[A-Z]{3}\b/)
|
74
|
+
trip.startLocation = locations[0]
|
75
|
+
trip.endLocation = locations[1]
|
76
|
+
|
77
|
+
#dates use the 00/00/00 format
|
78
|
+
dates = string.scan(/\d{2}\/\d{2}\/\d{2}/)
|
79
|
+
trip.startDate = dates[0]
|
80
|
+
trip.endDate = dates[1]
|
81
|
+
|
82
|
+
return trip
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
43
86
|
|
44
|
-
|
45
|
-
|
46
|
-
|
87
|
+
class TrainParser
|
88
|
+
|
89
|
+
def self.parse(message)
|
90
|
+
|
91
|
+
@email = message
|
92
|
+
railcarriers = ["dart", "northern commuter", "south eastern commuter", "south western commuter", "western commuter"]
|
93
|
+
stations = ["malahide", "heuston", "portlaoise", "portmarnock"]
|
94
|
+
trip = Trip.new
|
95
|
+
trip.category = "train"
|
96
|
+
|
97
|
+
railcarriers.each do |word|
|
98
|
+
if @email.body.include?(word)
|
47
99
|
trip.carrier = word
|
48
|
-
end
|
49
100
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
101
|
+
end
|
102
|
+
|
103
|
+
#Train confirmation numbers are always 11 digits
|
104
|
+
trip.confirmationNumber = @email.body.match(/\d{11}/)[0]
|
105
|
+
string = @email.body.to_s
|
106
|
+
|
107
|
+
#times are displayed as a 24 hour digital display
|
108
|
+
times = string.scan(/\d:\d\d|\d\d:\d\d/)
|
109
|
+
trip.startTime = times[0]
|
110
|
+
trip.endTime = times[1]
|
111
|
+
|
112
|
+
first = true
|
113
|
+
stations.each do |word|
|
114
|
+
if @email.body.include?(word)
|
115
|
+
if first == true
|
116
|
+
trip.startLocation = word
|
117
|
+
first = false
|
118
|
+
else
|
119
|
+
trip.endLocation = word
|
120
|
+
first = true
|
55
121
|
end
|
56
122
|
end
|
57
123
|
end
|
58
124
|
|
59
|
-
|
125
|
+
dates = string.scan(/\d{2}\/\d{2}\/\d{2}/)
|
126
|
+
trip.startDate = dates[0]
|
127
|
+
trip.endDate = dates[1]
|
128
|
+
|
129
|
+
return trip
|
130
|
+
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class BusParser
|
135
|
+
def self.parse(message)
|
136
|
+
|
137
|
+
@email = message
|
138
|
+
buscarriers = ["bus eireann", "matthews"]
|
139
|
+
trip = Trip.new
|
140
|
+
trip.category = "bus"
|
141
|
+
|
142
|
+
buscarriers.each do |word|
|
143
|
+
if @email.body.include?(word)
|
144
|
+
trip.carrier = word
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
trip.confirmationNumber = @email.body.match(/[a-zA-Z]{3}\d{4}/)[0]
|
60
149
|
string = @email.body.to_s
|
61
150
|
|
62
151
|
times = string.scan(/(\d:\d\d[a|p]|\d\d:\d\d[a|p])/)
|
@@ -72,6 +161,6 @@ module MailParser
|
|
72
161
|
trip.endDate = dates[1]
|
73
162
|
|
74
163
|
return trip
|
75
|
-
|
164
|
+
|
76
165
|
end
|
77
166
|
end
|