email_predictor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc3838f87246bf751929a1a07b00a62cf648efd7
4
+ data.tar.gz: 683347dace43d89d75630ffb7f442c4650c3b6d7
5
+ SHA512:
6
+ metadata.gz: a0edcd07228ff5348e4916bde3d1ad59f18c6dcc90a5a3f491fc9930b913a0a55620e2c9ba1602f8fe779679ed961ce9bedab5114ae149d65743edadb624fda5
7
+ data.tar.gz: 1e5e6c64a48d2d9a02e8a4d03c301b4a14bc22bee60c7ba938c5ea6efac316f721e0aedf3fad3f26e7b0d2ccdbb6557700540ea3e5fb0577b8f1b356fd2a4465
@@ -0,0 +1,17 @@
1
+ module EmailPredictor
2
+ class Base
3
+
4
+ attr_reader :name
5
+
6
+ def initialize(opts)
7
+ @name = opts[:name].downcase
8
+ end
9
+
10
+ #Validate that the name should be in format of firstname lastname
11
+ def validate!
12
+ unless @name.split(" ").count.eql?(2)
13
+ raise TypeError.new("Oops, the name is not in valid format. Should be like 'Firstname lastname', Eg: John Ferguson")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,66 @@
1
+ #This is responsible for predicting the rules on the knowledge of existing data.
2
+ # Usage
3
+
4
+ # EmailPredictor::DataAnalyser.all
5
+ # This gives the analysis for all the existing records
6
+
7
+ # To find for a particular company
8
+ # Usage
9
+ # EmailPredictor::DataAnalyser.find('google')
10
+ module EmailPredictor
11
+
12
+ class DataAnalyser
13
+
14
+ attr_reader :company,:rules
15
+
16
+ def initialize(opts)
17
+ @company = opts[:company]
18
+ @rules = opts[:rules]
19
+ end
20
+
21
+ class << self
22
+ def all
23
+ collection = []
24
+ group_by_company.each_pair do |key,value|
25
+ collection << new(company: key,rules: get_rules(value))
26
+ end
27
+ collection
28
+ end
29
+
30
+
31
+ def get_rules(employees)
32
+ EmailPredictor::Rules.get(employees)
33
+ end
34
+
35
+ #Sample dataset
36
+ #TODO: should be flexible and via a .yml or .json file
37
+ def dataset
38
+ {
39
+ 'John Ferguson' => 'john.ferguson@alphasights.com',
40
+ 'Damon Aw' => 'damon.aw@alphasights.com',
41
+ 'Linda Li' => 'linda.li@alphasights.com',
42
+ 'Larry Page' => 'larry.p@google.com',
43
+ 'Sergey Brin' => 's.brin@google.com',
44
+ 'Steve Jobs' => 's.j@apple.com'
45
+ }
46
+ end
47
+
48
+ def find(company)
49
+ all.find {|i| i.company == company}
50
+ end
51
+
52
+ # We need to group the dataset by the company and the number of people associated with
53
+ # it
54
+ def group_by_company
55
+ hsh = Hash.new
56
+ dataset.each_pair do |key,value|
57
+ company = value.split('@')[1].split('.')[0] #get the company name
58
+ username = value.split('@')[0]
59
+ hsh[company] ||= []
60
+ hsh[company] << { name: key,username: username }
61
+ end
62
+ hsh
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,43 @@
1
+ #This is reponsible for the call to the engine.
2
+ # A sample usage can look like
3
+
4
+ # EmailPredictor::Predictor.predict(name: 'Ankit Gupta',company: 'google')
5
+
6
+ module EmailPredictor
7
+ class Predictor < Base
8
+
9
+ attr_reader :company,:predicted_emails,:message
10
+
11
+ def initialize(opts = {})
12
+ super
13
+ @company = opts[:company]
14
+ @predicted_emails = []
15
+ validate!
16
+ end
17
+
18
+ class << self
19
+ def predict(opts)
20
+ obj = new(opts).predict
21
+ obj
22
+ end
23
+ end
24
+
25
+ def predict
26
+ obj = EmailPredictor::Rules.new(name: @name)
27
+ unless applicable_rules.empty?
28
+ applicable_rules.collect do |rule|
29
+ @predicted_emails << "#{obj.send(rule)}@#{@company}.com"
30
+ @message = 'Successfully predicted emails.'
31
+ end
32
+ else
33
+ @message = "Prediction cannot be done for #{@name.titleize} as we don't have any historical data for #{@company} company."
34
+ end
35
+ self
36
+ end
37
+
38
+ def applicable_rules
39
+ data_analyser = EmailPredictor::DataAnalyser.find(@company)
40
+ data_analyser ? data_analyser.rules : []
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,78 @@
1
+ # This is responsible for the prediction of existing data
2
+ module EmailPredictor
3
+ class Rules < Base
4
+
5
+ attr_reader :name,:username
6
+
7
+ def initialize(opts = {})
8
+ super
9
+ @username = opts[:username]
10
+ validate!
11
+ end
12
+
13
+ def some_fake_rule
14
+ "Holla!"
15
+ end
16
+
17
+ def first_name_dot_last_name
18
+ "#{first_name}.#{last_name}"
19
+ end
20
+
21
+ def first_name_dot_last_initial
22
+ "#{first_name}.#{last_name_initial}"
23
+ end
24
+
25
+ def first_initial_dot_last_name
26
+ "#{first_name_initial}.#{last_name}"
27
+ end
28
+
29
+ def first_initial_dot_last_initial
30
+ "#{first_name_initial}.#{last_name_initial}"
31
+ end
32
+
33
+ def first_name
34
+ @name.split(' ').first
35
+ end
36
+
37
+ def last_name
38
+ @name.split(' ').last
39
+ end
40
+
41
+ def first_name_initial
42
+ first_name[0,1]
43
+ end
44
+
45
+ def last_name_initial
46
+ last_name[0,1]
47
+ end
48
+
49
+ def username_first
50
+ @username.split('.').first
51
+ end
52
+
53
+ def username_last
54
+ @username.split('.').last
55
+ end
56
+
57
+ def predict
58
+ if first_name.eql?(username_first) && last_name.eql?(username_last)
59
+ 'first_name_dot_last_name'
60
+ elsif first_name_initial.eql?(username_first) && last_name.eql?(username_last)
61
+ 'first_initial_dot_last_name'
62
+ elsif first_name_initial.eql?(username_first) && last_name_initial.eql?(username_last)
63
+ 'first_initial_dot_last_initial'
64
+ elsif first_name.eql?(username_first) && last_name_initial.eql?(username_last)
65
+ 'first_name_dot_last_initial'
66
+ end
67
+ end
68
+
69
+ class << self
70
+ def get(employees)
71
+ employees.collect do |employee|
72
+ rule = new(employee)
73
+ rule.predict
74
+ end.uniq
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ require 'active_support/inflector'
2
+ require 'email_predictor/base'
3
+ require 'email_predictor/data_analyser'
4
+ require 'email_predictor/predictor'
5
+ require 'email_predictor/rules'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_predictor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ankit8898
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.2.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec-collection_matchers
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.2
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.1.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '10.4'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 10.4.2
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.4'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 10.4.2
73
+ - !ruby/object:Gem::Dependency
74
+ name: activesupport
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.2'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.2.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.2.0
93
+ description: Predict emails on a historical pattern for a company
94
+ email: ankit.gupta8898@gmail.com
95
+ executables: []
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - lib/email_predictor.rb
100
+ - lib/email_predictor/base.rb
101
+ - lib/email_predictor/data_analyser.rb
102
+ - lib/email_predictor/predictor.rb
103
+ - lib/email_predictor/rules.rb
104
+ homepage: https://rubygems.org/gems/email_predictor
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message: Thanks for installing!
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: This is an email predictor!
128
+ test_files: []