nametoemail 0.0.1

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/nametoemail.rb +134 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a2678498e2312e68252bcc8f8f71c74d98bb2829
4
+ data.tar.gz: 1a0d40844372c04e542f5c7230edd8287ea0d70c
5
+ SHA512:
6
+ metadata.gz: 4a99fbebdb5c0f1a1c199ed665139817cdd32dfa87da4ebd5bcc464091eef0c9db1f1b0cffac53bd0c25c7c0a39ec7e283884c42039c30aced23fb00d0fd0f55
7
+ data.tar.gz: 7a392513b4c19336c03c6bd6bec415e8e62c59cc114c6e5a791a78969178b2a80ce99d08df70e280e9c9415d484ebe738dd49ef5bfa8cade68fcd164252c4906
@@ -0,0 +1,134 @@
1
+ require 'json'
2
+
3
+ class NameToEmail
4
+ def initialize(input, namefield, presetdomain, chosendomain, urlfield, formattype)
5
+ @input = JSON.parse(input)
6
+ @namefield = namefield
7
+ @urlfield = urlfield
8
+ @presetdomain = presetdomain
9
+ @chosendomain = chosendomain
10
+ @emaillist = Array.new
11
+ @formattype = formattype
12
+ end
13
+
14
+ # Get emails of all formats
15
+ def genemails
16
+ nametrack = Array.new
17
+
18
+ @input.each do |i|
19
+ # Parse domain
20
+ if @presetdomain == false
21
+ domain = parseurl(i[@urlfield])
22
+ else
23
+ domain = @chosendomain
24
+ end
25
+
26
+ if i[@namefield] && domain
27
+ name = parsename(i[@namefield])
28
+
29
+ # Check if combination already exists
30
+ if name && domain
31
+ namedomain = name[0] + name[1] + domain
32
+ if !(nametrack.include? namedomain)
33
+ nametrack.push(namedomain)
34
+
35
+ if @formattype == "all"
36
+ itememails = tryallformats(name, domain)
37
+ else
38
+ itememails = tryoneformat(name, domain, @formattype)
39
+ end
40
+
41
+ i["emails"] = itememails
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # Get emails in all formats
49
+ def tryallformats(name, domain)
50
+ itememails = Array.new
51
+
52
+ # Generate emails
53
+ itememails.push(firstlastdot(name[0], name[1], domain))
54
+ itememails.push(firstinitiallastname(name[0], name[1], domain))
55
+ itememails.push(firstunderscorelast(name[0], name[1], domain))
56
+ itememails.push(lastnamefirstinitial(name[0], name[1], domain))
57
+ itememails.push(justlast(name[1], domain))
58
+ itememails.each do |e|
59
+ @emaillist.push(e)
60
+ end
61
+
62
+ return itememails
63
+ end
64
+
65
+ # Gets all emails of one format
66
+ def tryoneformat(name, domain, format)
67
+ email = ""
68
+
69
+ case format
70
+ when "firstlastdot" then email = firstlastdot(name[0], name[1], domain)
71
+ when "firstinitiallastname" then email = firstinitiallastname(name[0], name[1], domain)
72
+ when "firstunderscorelast" then email = firstunderscorelast(name[0], name[1], domain)
73
+ when "lastnamefirstinitial" then email = lastnamefirstinitial(name[0], name[1], domain)
74
+ when "justlast" then email = justlast(name[1], domain)
75
+ else email = nil
76
+ end
77
+
78
+ @emaillist.push(email)
79
+ return email
80
+ end
81
+
82
+ # Emails of the form lastname@domain
83
+ def justlast(lastname, domain)
84
+ return lastname + "@" + domain
85
+ end
86
+
87
+ # Emails of form firstname.lastname@domain
88
+ def firstlastdot(firstname, lastname, domain)
89
+ return firstname + "." + lastname + "@" + domain
90
+ end
91
+
92
+ # Emails of the form lastnamefirstinitial
93
+ def lastnamefirstinitial(firstname, lastname, domain)
94
+ return lastname + firstname[0] + "@" + domain
95
+ end
96
+
97
+ # Emails of the form firstinitiallastname@domain
98
+ def firstinitiallastname(firstname, lastname, domain)
99
+ return firstname[0] + lastname + "@" + domain
100
+ end
101
+
102
+ # Emails of the form firstname_lastname@domain
103
+ def firstunderscorelast(firstname, lastname, domain)
104
+ return firstname + "_" + lastname + "@" + domain
105
+ end
106
+
107
+ # Parse url to get just the domain
108
+ def parseurl(url)
109
+ parsed = url.gsub("http://", "").gsub("www.", "")
110
+ split = parsed.split("/")
111
+ if split[0]
112
+ return split[0]
113
+ end
114
+ end
115
+
116
+ # Gets first and last name and removes certain characters
117
+ def parsename(name)
118
+ splitn = name.split(" ")
119
+ first = splitn.first.gsub("'", "").gsub("-", "").gsub(".", "")
120
+ last = splitn.last.gsub("'", "").gsub("-", "").gsub(".", "")
121
+ narray = [first.downcase, last.downcase]
122
+ return narray
123
+ end
124
+
125
+ # Get list of just emails
126
+ def emaillist
127
+ return JSON.pretty_generate(@emaillist)
128
+ end
129
+
130
+ # Get JSON with emails appended
131
+ def jsonwithemails
132
+ return JSON.pretty_generate(@input)
133
+ end
134
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nametoemail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - M. C. McGrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gets a list of possible email addresses.
14
+ email: shidash@shidash.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/nametoemail.rb
20
+ homepage: https://github.com/TransparencyToolkit/NameToEmail
21
+ licenses:
22
+ - GPL
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.0.14
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Gets a list of possible email addresses.
44
+ test_files: []
45
+ has_rdoc: