xml_contacts_extractor 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/xml_contacts_extractor/version.rb +1 -1
- data/lib/xml_contacts_extractor.rb +63 -59
- metadata +1 -1
@@ -1,88 +1,92 @@
|
|
1
1
|
require "xml_contacts_extractor/version"
|
2
2
|
require "nokogiri"
|
3
3
|
|
4
|
-
|
4
|
+
module XmlContactsExtractor
|
5
5
|
|
6
|
-
|
6
|
+
class Search
|
7
7
|
|
8
|
-
|
8
|
+
attr_accessor :first_name, :fname, :last_name, :lname, :email, :phone, :address, :city, :state, :zip, :ip_address
|
9
|
+
|
10
|
+
def extract_contacts(xml)
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
# Different possible variations
|
13
|
+
first_name_choices = ["first_name", "fname", "f_name", "firstname", "FirstName", "First", "name"]
|
14
|
+
last_name_choices = ["lastname", "last_name", "lname", "l_name", "LastName", "Last"]
|
15
|
+
email_choices = ["email", "email_address", "email_addy", "EmailAddress"]
|
16
|
+
address_choices = ["address", "address_1", "Addr1", "property_addr", "addr", "line1", "Address1", "address1"]
|
17
|
+
phone_choices = ["phone", "phone_number", "phone_num", "PhoneNumberValue", "Phone", "Phone1"]
|
18
|
+
ip_address_choices = ["ip_address", "ip_addy", "ip", "ipaddress"]
|
19
|
+
city_choices = ["city", "City"]
|
20
|
+
state_choices = ["state", "State", "StateProvCd", "state_province"]
|
21
|
+
zip_choices = ["zip", "Zip", "PostalCode", "postal_code", "ZIPCode"]
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
xml = xml.gsub(/\n|\\n|\\/, '')
|
24
|
+
xml_doc = Nokogiri::XML(xml)
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
# First name
|
27
|
+
first_name_choices.each do |f|
|
28
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @first_name.blank?
|
29
|
+
@first_name = @fname = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
30
|
+
end
|
28
31
|
end
|
29
|
-
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
# Last name
|
34
|
+
last_name_choices.each do |f|
|
35
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @last_name.blank?
|
36
|
+
@last_name = @lname = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
37
|
+
end
|
35
38
|
end
|
36
|
-
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
# Email
|
41
|
+
email_choices.each do |f|
|
42
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @email.blank?
|
43
|
+
@email = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
44
|
+
end
|
42
45
|
end
|
43
|
-
end
|
44
46
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
# Phone
|
48
|
+
phone_choices.each do |f|
|
49
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @phone.blank?
|
50
|
+
@phone = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
51
|
+
end
|
49
52
|
end
|
50
|
-
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
# Address
|
55
|
+
address_choices.each do |f|
|
56
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @address.blank?
|
57
|
+
@address = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
58
|
+
end
|
56
59
|
end
|
57
|
-
end
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
# City
|
62
|
+
city_choices.each do |f|
|
63
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @city.blank?
|
64
|
+
@city = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
65
|
+
end
|
63
66
|
end
|
64
|
-
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
68
|
+
# State
|
69
|
+
state_choices.each do |f|
|
70
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @state.blank?
|
71
|
+
@state = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
72
|
+
end
|
70
73
|
end
|
71
|
-
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
# Zip
|
76
|
+
zip_choices.each do |f|
|
77
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @zip.blank?
|
78
|
+
@zip = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
79
|
+
end
|
77
80
|
end
|
78
|
-
end
|
79
81
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
82
|
+
# IP Address
|
83
|
+
ip_address_choices.each do |f|
|
84
|
+
if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @ip_address.blank?
|
85
|
+
@ip_address = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
|
86
|
+
end
|
84
87
|
end
|
85
88
|
end
|
89
|
+
|
86
90
|
end
|
87
91
|
|
88
92
|
end
|