xml_contacts_extractor 0.0.3 → 0.0.4

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.
@@ -1,3 +1,3 @@
1
1
  module XmlContactsExtractor
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,88 +1,92 @@
1
1
  require "xml_contacts_extractor/version"
2
2
  require "nokogiri"
3
3
 
4
- class XmlContactsExtractor
4
+ module XmlContactsExtractor
5
5
 
6
- attr_accessor :first_name, :fname, :last_name, :lname, :email, :phone, :address, :city, :state, :zip, :ip_address
6
+ class Search
7
7
 
8
- def extract_contacts(xml)
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
- # Different possible variations
11
- first_name_choices = ["first_name", "fname", "f_name", "firstname", "FirstName", "First", "name"]
12
- last_name_choices = ["lastname", "last_name", "lname", "l_name", "LastName", "Last"]
13
- email_choices = ["email", "email_address", "email_addy", "EmailAddress"]
14
- address_choices = ["address", "address_1", "Addr1", "property_addr", "addr", "line1", "Address1", "address1"]
15
- phone_choices = ["phone", "phone_number", "phone_num", "PhoneNumberValue", "Phone", "Phone1"]
16
- ip_address_choices = ["ip_address", "ip_addy", "ip", "ipaddress"]
17
- city_choices = ["city", "City"]
18
- state_choices = ["state", "State", "StateProvCd", "state_province"]
19
- zip_choices = ["zip", "Zip", "PostalCode", "postal_code", "ZIPCode"]
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
- xml = xml.gsub(/\n|\\n|\\/, '')
22
- xml_doc = Nokogiri::XML(xml)
23
+ xml = xml.gsub(/\n|\\n|\\/, '')
24
+ xml_doc = Nokogiri::XML(xml)
23
25
 
24
- # First name
25
- first_name_choices.each do |f|
26
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @first_name.blank?
27
- @first_name = @fname = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # Last name
32
- last_name_choices.each do |f|
33
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @last_name.blank?
34
- @last_name = @lname = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # Email
39
- email_choices.each do |f|
40
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @email.blank?
41
- @email = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # Phone
46
- phone_choices.each do |f|
47
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @phone.blank?
48
- @phone = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # Address
53
- address_choices.each do |f|
54
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @address.blank?
55
- @address = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # City
60
- city_choices.each do |f|
61
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @city.blank?
62
- @city = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # State
67
- state_choices.each do |f|
68
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @state.blank?
69
- @state = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # Zip
74
- zip_choices.each do |f|
75
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @zip.blank?
76
- @zip = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
- # IP Address
81
- ip_address_choices.each do |f|
82
- if xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]") && @ip_address.blank?
83
- @ip_address = xml_doc.at_xpath("//*[contains(translate(name(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '#{f}')]").content.to_s
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml_contacts_extractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: