ramparts 0.3.0
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 +7 -0
- data/.github/stale.yml +24 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +54 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.md +21 -0
- data/README.md +226 -0
- data/ROADMAP.md +21 -0
- data/Rakefile +0 -0
- data/lib/ramparts.rb +3 -0
- data/lib/ramparts/base.rb +99 -0
- data/lib/ramparts/data/list_of_email_domains.rb +73 -0
- data/lib/ramparts/helpers.rb +46 -0
- data/lib/ramparts/parsers/email_parser.rb +88 -0
- data/lib/ramparts/parsers/phone_parser.rb +137 -0
- data/lib/ramparts/parsers/url_parser.rb +30 -0
- data/lib/ramparts/version.rb +5 -0
- data/ramparts.gemspec +24 -0
- data/spec/data/email_and_phone_data/falsy_email_and_phone_data.rb +6 -0
- data/spec/data/email_and_phone_data/truthy_email_and_phone_data.rb +33 -0
- data/spec/data/email_data/falsy_email_data.rb +6 -0
- data/spec/data/email_data/truthy_email_data.rb +87 -0
- data/spec/data/phone_data/falsy_phone_data.rb +6 -0
- data/spec/data/phone_data/truthy_phone_data.rb +109 -0
- data/spec/data/url_data/falsy_url_data.rb +6 -0
- data/spec/data/url_data/truthy_url_data.rb +12 -0
- data/spec/parsers/email_and_phone_parser_spec.rb +44 -0
- data/spec/parsers/email_parser_spec.rb +60 -0
- data/spec/parsers/phone_parser_spec.rb +56 -0
- data/spec/parsers/url_parser_spec.rb +15 -0
- data/spec/spec_constants.rb +3 -0
- data/spec/spec_helper.rb +87 -0
- metadata +147 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../data/phone_data/truthy_phone_data'
|
|
4
|
+
require_relative '../data/phone_data/falsy_phone_data'
|
|
5
|
+
|
|
6
|
+
describe '#count_phone_numbers' do
|
|
7
|
+
it 'parses a number of positive test blocks correctly' do
|
|
8
|
+
test_truthy_count(PHONE_TRUTHY_WITH_ANSWERS, :count_phone_numbers)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'parses a number of positive test blocks correctly with parse_leet option' do
|
|
12
|
+
test_truthy_count(PHONE_TRUTHY_WITH_ANSWERS, :count_phone_numbers, parse_leet: true)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'parses a number of spaced positive test blocks correctly with remove_spaces option' do
|
|
16
|
+
test_truthy_count(PHONE_TRUTHY_WITH_ANSWERS_AND_SPACES, :count_phone_numbers, remove_spaces: true)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'parses a number of positive test blocks correctly with remove_spaces and parse_leet option' do
|
|
20
|
+
test_truthy_count(PHONE_TRUTHY_WITH_ANSWERS, :count_phone_numbers, parse_leet: true, remove_spaces: true)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'parses a number of negative test blocks correctly' do
|
|
24
|
+
test_falsy_count(PHONE_FALSY_BLOCKS, :count_phone_numbers)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'parses a number of negative test blocks correctly with all the options' do
|
|
28
|
+
test_falsy_count(PHONE_FALSY_BLOCKS, :count_phone_numbers, parse_leet: true, remove_spaces: true)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#find_phone_numbers' do
|
|
33
|
+
it 'parses a number of positive test blocks correctly with glorified regex' do
|
|
34
|
+
test_truthy_finds(PHONE_TRUTHY_WITH_ANSWERS, :find_phone_numbers)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'parses a number of positive test blocks correctly' do
|
|
38
|
+
test_truthy_finds(PHONE_TRUTHY_WITH_ANSWERS_AND_SPACES, :find_phone_numbers)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'parses a number of negative test blocks correctly with glorified regex' do
|
|
42
|
+
test_falsy_finds(PHONE_FALSY_BLOCKS, :find_phone_numbers)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe '#replace_phone_numbers' do
|
|
47
|
+
it 'replaces a number of positive test blocks correctly with phone replacer' do
|
|
48
|
+
test_replacements(PHONE_TRUTHY_WITH_ANSWERS, :replace_phone_numbers)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe 'Map/Reduce to Regex Run Time' do
|
|
53
|
+
it 'times the two methods against each other' do
|
|
54
|
+
compare_run_times(PHONE_TRUTHY_WITH_ANSWERS, :count_phone_numbers, :find_phone_numbers)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require './lib/ramparts'
|
|
4
|
+
require_relative '../data/url_data/truthy_url_data'
|
|
5
|
+
require_relative '../data/url_data/falsy_url_data'
|
|
6
|
+
|
|
7
|
+
describe '#count_urls' do
|
|
8
|
+
it 'parses a number of positive test blocks correctly' do
|
|
9
|
+
test_truthy_count(URL_TRUTHY, :count_urls)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'parses a number of negative test blocks correctly' do
|
|
13
|
+
test_falsy_count(URL_FALSY, :count_urls)
|
|
14
|
+
end
|
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Load first so it can track the application code
|
|
4
|
+
require 'simplecov'
|
|
5
|
+
SimpleCov.start
|
|
6
|
+
|
|
7
|
+
require './lib/ramparts'
|
|
8
|
+
require 'spec_constants'
|
|
9
|
+
|
|
10
|
+
# Times a method run length in milliseconds
|
|
11
|
+
def time_method(method, *args)
|
|
12
|
+
beginning_time = Time.now
|
|
13
|
+
Ramparts.send(method, args[0])
|
|
14
|
+
end_time = Time.now
|
|
15
|
+
milliseconds = (end_time - beginning_time) * 1000
|
|
16
|
+
milliseconds
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Compares the run time of two methods
|
|
20
|
+
# In this case the MR and GR algos
|
|
21
|
+
def compare_run_times(tests, method1, method2)
|
|
22
|
+
total_time_map_reduce = 0
|
|
23
|
+
total_time_regex = 0
|
|
24
|
+
|
|
25
|
+
tests.each do |test|
|
|
26
|
+
map_reduce_time = time_method(method1, test[:text])
|
|
27
|
+
regex_time = time_method(method2, test[:text])
|
|
28
|
+
|
|
29
|
+
total_time_map_reduce += map_reduce_time
|
|
30
|
+
total_time_regex += regex_time
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
puts
|
|
34
|
+
puts "Map Reduce Total Time: #{total_time_map_reduce.round(2)} milliseconds"
|
|
35
|
+
puts "Regex Total Time: #{total_time_regex.round(2)} milliseconds"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Test helper for testing truthy values against count type methods
|
|
39
|
+
def test_truthy_count(tests, method, options = {})
|
|
40
|
+
tests.each do |test|
|
|
41
|
+
matches = Ramparts.send(method, test[:text], options)
|
|
42
|
+
expect(matches)
|
|
43
|
+
.to eq(test[:matches].length),
|
|
44
|
+
"Expected #{test[:matches].length}, got #{matches} for '#{test[:text]}'"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Test helper for testing truthy values against find type methods
|
|
49
|
+
def test_truthy_finds(tests, method, options = {})
|
|
50
|
+
tests.each do |test|
|
|
51
|
+
matches = Ramparts.send(method, test[:text], options)
|
|
52
|
+
test[:matches].each_with_index do |match_string, index|
|
|
53
|
+
if matches[index].nil? || matches[index][:value].casecmp(match_string) != 0
|
|
54
|
+
got_result = matches[index].nil? ? 'NIL' : matches[index][:value]
|
|
55
|
+
raise "Expected: #{match_string}\nGot: #{got_result}\nBlock '#{test[:text]}'\nResult: #{matches}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Test helper for testing truthy values against find type methods
|
|
62
|
+
def test_replacements(tests, method, options = {})
|
|
63
|
+
tests.each do |test|
|
|
64
|
+
text = Ramparts.send(method, test[:text], options) do
|
|
65
|
+
INSERTABLE
|
|
66
|
+
end
|
|
67
|
+
if text.casecmp(test[:filtered]) != 0
|
|
68
|
+
raise "Expected: #{test[:filtered]}\nGot: #{text}\nBlock '#{test[:filtered]}'"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Test helper for testing falsy values against count type methods
|
|
74
|
+
def test_falsy_count(tests, method, options = {})
|
|
75
|
+
tests.each do |test|
|
|
76
|
+
matches = Ramparts.send(method, test, options)
|
|
77
|
+
expect(matches).to eq(0), "Expected empty array, got #{matches} for '#{test}'"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Test helper for testing falsy values against find type methods
|
|
82
|
+
def test_falsy_finds(tests, method, options = {})
|
|
83
|
+
tests.each do |test|
|
|
84
|
+
matches = Ramparts.send(method, test, options)
|
|
85
|
+
expect(matches.length).to eq(0), "Expected empty array, got #{matches.length} for '#{test}'"
|
|
86
|
+
end
|
|
87
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ramparts
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.3.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brent Scheibelhut
|
|
8
|
+
- CareGuide
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - "~>"
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '2.5'
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 2.5.0
|
|
24
|
+
type: :development
|
|
25
|
+
prerelease: false
|
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
27
|
+
requirements:
|
|
28
|
+
- - "~>"
|
|
29
|
+
- !ruby/object:Gem::Version
|
|
30
|
+
version: '2.5'
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 2.5.0
|
|
34
|
+
- !ruby/object:Gem::Dependency
|
|
35
|
+
name: rubocop
|
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.51.0
|
|
41
|
+
type: :development
|
|
42
|
+
prerelease: false
|
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.51.0
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: simplecov
|
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.15.1
|
|
55
|
+
type: :development
|
|
56
|
+
prerelease: false
|
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 0.15.1
|
|
62
|
+
description: Parses blocks of text to find phone numbers (including phonetic numbers),
|
|
63
|
+
emails, and bad url. Useful for finding scammers who tend to try to post their phone
|
|
64
|
+
number in messages.
|
|
65
|
+
email:
|
|
66
|
+
- brent.scheibelhut@careguide.com
|
|
67
|
+
- info@careguide.com
|
|
68
|
+
executables: []
|
|
69
|
+
extensions: []
|
|
70
|
+
extra_rdoc_files: []
|
|
71
|
+
files:
|
|
72
|
+
- ".github/stale.yml"
|
|
73
|
+
- ".gitignore"
|
|
74
|
+
- ".rspec"
|
|
75
|
+
- ".rubocop.yml"
|
|
76
|
+
- ".travis.yml"
|
|
77
|
+
- CHANGELOG.md
|
|
78
|
+
- CONTRIBUTING.md
|
|
79
|
+
- Gemfile
|
|
80
|
+
- Gemfile.lock
|
|
81
|
+
- LICENSE.md
|
|
82
|
+
- README.md
|
|
83
|
+
- ROADMAP.md
|
|
84
|
+
- Rakefile
|
|
85
|
+
- lib/ramparts.rb
|
|
86
|
+
- lib/ramparts/base.rb
|
|
87
|
+
- lib/ramparts/data/list_of_email_domains.rb
|
|
88
|
+
- lib/ramparts/helpers.rb
|
|
89
|
+
- lib/ramparts/parsers/email_parser.rb
|
|
90
|
+
- lib/ramparts/parsers/phone_parser.rb
|
|
91
|
+
- lib/ramparts/parsers/url_parser.rb
|
|
92
|
+
- lib/ramparts/version.rb
|
|
93
|
+
- ramparts.gemspec
|
|
94
|
+
- spec/data/email_and_phone_data/falsy_email_and_phone_data.rb
|
|
95
|
+
- spec/data/email_and_phone_data/truthy_email_and_phone_data.rb
|
|
96
|
+
- spec/data/email_data/falsy_email_data.rb
|
|
97
|
+
- spec/data/email_data/truthy_email_data.rb
|
|
98
|
+
- spec/data/phone_data/falsy_phone_data.rb
|
|
99
|
+
- spec/data/phone_data/truthy_phone_data.rb
|
|
100
|
+
- spec/data/url_data/falsy_url_data.rb
|
|
101
|
+
- spec/data/url_data/truthy_url_data.rb
|
|
102
|
+
- spec/parsers/email_and_phone_parser_spec.rb
|
|
103
|
+
- spec/parsers/email_parser_spec.rb
|
|
104
|
+
- spec/parsers/phone_parser_spec.rb
|
|
105
|
+
- spec/parsers/url_parser_spec.rb
|
|
106
|
+
- spec/spec_constants.rb
|
|
107
|
+
- spec/spec_helper.rb
|
|
108
|
+
homepage: https://github.com/CareGuide/ramparts
|
|
109
|
+
licenses:
|
|
110
|
+
- MIT
|
|
111
|
+
metadata: {}
|
|
112
|
+
post_install_message:
|
|
113
|
+
rdoc_options: []
|
|
114
|
+
require_paths:
|
|
115
|
+
- lib
|
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
|
+
requirements:
|
|
118
|
+
- - ">="
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '0'
|
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
requirements: []
|
|
127
|
+
rubyforge_project:
|
|
128
|
+
rubygems_version: 2.6.13
|
|
129
|
+
signing_key:
|
|
130
|
+
specification_version: 4
|
|
131
|
+
summary: Parses blocks of text to find phone numbers (including phonetic numbers),
|
|
132
|
+
emails, and bad url
|
|
133
|
+
test_files:
|
|
134
|
+
- spec/data/email_and_phone_data/falsy_email_and_phone_data.rb
|
|
135
|
+
- spec/data/email_and_phone_data/truthy_email_and_phone_data.rb
|
|
136
|
+
- spec/data/email_data/falsy_email_data.rb
|
|
137
|
+
- spec/data/email_data/truthy_email_data.rb
|
|
138
|
+
- spec/data/phone_data/falsy_phone_data.rb
|
|
139
|
+
- spec/data/phone_data/truthy_phone_data.rb
|
|
140
|
+
- spec/data/url_data/falsy_url_data.rb
|
|
141
|
+
- spec/data/url_data/truthy_url_data.rb
|
|
142
|
+
- spec/parsers/email_and_phone_parser_spec.rb
|
|
143
|
+
- spec/parsers/email_parser_spec.rb
|
|
144
|
+
- spec/parsers/phone_parser_spec.rb
|
|
145
|
+
- spec/parsers/url_parser_spec.rb
|
|
146
|
+
- spec/spec_constants.rb
|
|
147
|
+
- spec/spec_helper.rb
|