simple_scrubber 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/lib/simple_scrubber/version.rb +1 -1
- data/lib/simple_scrubber.rb +5 -3
- data/spec/lib/simple_scrubber_spec.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2eb3ecf54a68ceee7de3509e8d8a80736f38021
|
4
|
+
data.tar.gz: a1eb05a4e24cd70546563b948e8e65cce5142846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 038a65e9c88b53eae2ff0ac2de0287e5c770096af0fc809180e344d585ab0969d26c86d901f63a177a126ff2199cdecf9de23fb246ae21d0c670ea12b0c54485
|
7
|
+
data.tar.gz: 2f3972b0af4680c8a6de58acce5dca0ebd30f6e58373383c407b14abf871e4dd757c9af07ef386e42ccd9793d4a96f1f76a28aaaa88270f0b1cebbc214c65cbb
|
data/lib/simple_scrubber.rb
CHANGED
@@ -3,13 +3,15 @@ require "simple_scrubber/version"
|
|
3
3
|
module SimpleScrubber
|
4
4
|
def self.scrub(text, types=[])
|
5
5
|
if types.include? :email
|
6
|
-
email_re = /\b[A-Z0-9._%+-]
|
7
|
-
text.gsub!(email_re,
|
6
|
+
email_re = /\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,4})\b/i
|
7
|
+
text.gsub!(email_re, 'xxx@\2')
|
8
8
|
end
|
9
9
|
|
10
10
|
if types.include? :phone
|
11
11
|
phone_re = /\b(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?\b/
|
12
|
-
text.
|
12
|
+
match = text.match phone_re
|
13
|
+
area_code = match[1] || match[2]
|
14
|
+
text.gsub!(phone_re, "#{area_code}-xxx-xxxx")
|
13
15
|
end
|
14
16
|
|
15
17
|
text
|
@@ -3,19 +3,22 @@ require_relative '../../lib/simple_scrubber'
|
|
3
3
|
describe SimpleScrubber do
|
4
4
|
it "scrubs emails" do
|
5
5
|
text = SimpleScrubber.scrub("foo bar adam.pash@gmail.com baz bat", [:email])
|
6
|
-
expect(text).to eq "foo bar xxx@
|
6
|
+
expect(text).to eq "foo bar xxx@gmail.com baz bat"
|
7
7
|
|
8
8
|
text = SimpleScrubber.scrub("adam.pash+foo@gmail.com.", [:email])
|
9
|
-
expect(text).to eq "xxx@
|
9
|
+
expect(text).to eq "xxx@gmail.com."
|
10
10
|
end
|
11
11
|
|
12
12
|
it "scrubs phone numbers" do
|
13
13
|
text = SimpleScrubber.scrub("foo bar 1(555)555-1234 baz bat", [:phone])
|
14
|
-
expect(text).to eq "foo bar
|
14
|
+
expect(text).to eq "foo bar 555-xxx-xxxx baz bat"
|
15
|
+
|
16
|
+
text = SimpleScrubber.scrub("foo bar 1-212-555-1234 baz bat", [:phone])
|
17
|
+
expect(text).to eq "foo bar 212-xxx-xxxx baz bat"
|
15
18
|
end
|
16
19
|
|
17
20
|
it "scrubs email and phone numbers" do
|
18
21
|
text = SimpleScrubber.scrub("contact bar at 1(555)555-1234 or pash@gawker.com", [:email, :phone])
|
19
|
-
expect(text).to eq "contact bar at
|
22
|
+
expect(text).to eq "contact bar at 555-xxx-xxxx or xxx@gawker.com"
|
20
23
|
end
|
21
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_scrubber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Pash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|