ncirlMailParser 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/mailParser.rb +77 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a19b574c3c1d2b1157a9ebf6d5b5e30649608d0e
4
+ data.tar.gz: bd1fcdfae2c26db2ac4b0eacf7092ec103c00db0
5
+ SHA512:
6
+ metadata.gz: 9a609d4adbcecaa2fb923d682e5e72e4794121634ef1a7abd64019d97a3f79ea249c6726afc78e029d765de877b860a4ca67776b5aada5528206e04179a85d7e
7
+ data.tar.gz: 931f103fa76d1da26402f1793c80b805551b55c5a62b3c1515d813dabad3ad2d03556af86a192aea1055735c1421acbab854ba3d9f7360193fa1fca113486ddc
data/lib/mailParser.rb ADDED
@@ -0,0 +1,77 @@
1
+ module MailParser
2
+ def self.receive_mail(message)
3
+
4
+ puts "++++++++++++++++++++++++++++++++++"
5
+ puts message.body.inspect
6
+ puts "++++++++++++++++++++++++++++++++++"
7
+
8
+ @email = message
9
+
10
+ #take from DB
11
+ airplane = ["plane", "airplane", "flight"]
12
+ train = ["train", "rail"]
13
+ 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
+
19
+ trip = Trip.new
20
+
21
+ airplane.each do |word|
22
+ if @email.body.include?(word)
23
+ trip.type = "plane"
24
+ end
25
+ end
26
+ train.each do |word|
27
+ if @email.body.include?(word)
28
+ trip.type = "train"
29
+ end
30
+ end
31
+ bus.each do |word|
32
+ if @email.body.include?(word)
33
+ trip.type = "bus"
34
+ end
35
+ end
36
+
37
+ if trip.type == "plane"
38
+ airlines.each do |word|
39
+ if @email.body.include?(word)
40
+ trip.carrier = word
41
+ end
42
+ end
43
+
44
+ elsif trip.type == "train"
45
+ railcarriers.each do |word|
46
+ if @email.body.include?(word)
47
+ trip.carrier = word
48
+ end
49
+ end
50
+
51
+ elsif trip.type == "bus"
52
+ buscarriers.each do |word|
53
+ if @email.body.include?(word)
54
+ trip.carrier = word
55
+ end
56
+ end
57
+ end
58
+
59
+ trip.confirmationNumber = @email.body.match(/[a-zA-Z]{3}\d{4}/)[0]
60
+ string = @email.body.to_s
61
+
62
+ times = string.scan(/(\d:\d\d[a|p]|\d\d:\d\d[a|p])/)
63
+ trip.startTime = times[0][0]
64
+ trip.endTime = times[1][0]
65
+
66
+ locations = string.scan(/[A-Z]{3}\b/)
67
+ trip.startLocation = locations[0]
68
+ trip.endLocation = locations[1]
69
+
70
+ dates = string.scan(/\d{2}\/\d{2}\/\d{2}/)
71
+ trip.startDate = dates[0]
72
+ trip.endDate = dates[1]
73
+
74
+ return trip
75
+
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ncirlMailParser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John o Bruachail
8
+ - Duwayne Petty
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mailman
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: returns the created trip
29
+ email: johnobruachail@hotmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/mailParser.rb
35
+ homepage: http://rubygems.org/gems/ncirlMailParser
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.8
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: parse's an incoming email for trip details
58
+ test_files: []