l2e_vocab_blacklist 1.0.1 → 1.1.0

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 +4 -4
  2. data/lib/l2e_vocab_blacklist.rb +25 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a89b0d6537e66cb74360ab8024cdbafaccfb2d9a
4
- data.tar.gz: 7ba3879756f5b9b1429904e488150c2c18d807f0
3
+ metadata.gz: 9ff5c746de5666a34afa6ca613e8d00b253ecb35
4
+ data.tar.gz: 013ce4b1478a34ba82b5664ac3c4f9c6e33309bb
5
5
  SHA512:
6
- metadata.gz: a05b911f2cbdc358f3c083d5c4e890b0d2280e086fb235d59381aff9925adc8d6b6aebcbdc4ddd28a5cacb950ff67e0d2b6dc5c8138f44e7638346bd8d80e731
7
- data.tar.gz: 48d946379208feb2f10ca1e508a437b18012d186a82fb510eb6c41d2eac2a05eadb74e25fd0e948ecc64e2a8ef4e03ce16d32b5fa004ff3fde1f626f6656cae7
6
+ metadata.gz: e2e1a7a39a4aee8e8b8da9e60fbc74ce3bc45dede898978b8722be2cc184fdc130ff15cced70591c54668172834172f25355e32df9769ba42e99e8e822ac64bc
7
+ data.tar.gz: dbb188bdb38cf44bf376345e48946ce085ed6cfae2e89b26a0afd7c37701b924e5295ca1fbabcbf29784a9f9a63ae6644230102a12eef0dfc5d6e22581ce0fd8
@@ -1,13 +1,15 @@
1
1
  require 'active_support/inflector'
2
2
 
3
3
  class VocabBlacklist
4
+
5
+ # Returns true or false, check to see if the
4
6
  def self.blacklisted?(str)
5
7
  # Sanitize string
6
8
  str = str.downcase.strip.gsub(CONSIDER_REGEX, '')
7
9
 
8
10
  # Blacklist if any of the words
9
11
  str.split(" ").each do |word|
10
- return true if FULL_WORDS.include?( word )
12
+ return true if FULL_WORDS.include?(word)
11
13
  end
12
14
 
13
15
  # For compound dirty words
@@ -15,7 +17,27 @@ class VocabBlacklist
15
17
  return true if str.include?(bad_phrase)
16
18
  end
17
19
 
18
- return GREEDY_DIRTY_WORDS.any?{ |s| str.include?( s ) }
20
+ return GREEDY_WORDS.any? { |s| str.include?(s) }
21
+ end
22
+
23
+ def self.censor(str, replace_with = "****")
24
+ PHRASES.each do |bad_phrase|
25
+ str.gsub!(/#{bad_phrase}/i, replace_with)
26
+ end
27
+
28
+ str.split(" ").map do |working_word|
29
+ word = working_word.downcase.strip.gsub(CONSIDER_REGEX, '')
30
+
31
+ if FULL_WORDS.include?(word)
32
+ working_word.gsub!(word, replace_with)
33
+ end
34
+
35
+ if GREEDY_WORDS.any? { |w| word.include?(w) }
36
+ working_word = replace_with
37
+ end
38
+
39
+ working_word
40
+ end.join(" ")
19
41
  end
20
42
 
21
43
  def self.file_to_nomalized_words(file)
@@ -31,6 +53,6 @@ class VocabBlacklist
31
53
 
32
54
  PHRASES = file_to_nomalized_words("#{BLACKLIST_DIR}/full_words.txt").select { |w| w.split(" ").length > 1 }
33
55
  FULL_WORDS = file_to_nomalized_words("#{BLACKLIST_DIR}/full_words.txt").reject { |w| w.split(" ").length > 1 }
34
- GREEDY_DIRTY_WORDS = words_with_expansions(file_to_nomalized_words("#{BLACKLIST_DIR}/greedy_words.txt")).uniq.freeze
56
+ GREEDY_WORDS = words_with_expansions(file_to_nomalized_words("#{BLACKLIST_DIR}/greedy_words.txt")).uniq.freeze
35
57
 
36
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l2e_vocab_blacklist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sherrid