Class: EncodedId::Blocklist
- Inherits:
-
Object
- Object
- EncodedId::Blocklist
- Includes:
- Enumerable
- Defined in:
- lib/encoded_id/blocklist.rb
Overview
A blocklist of words that should not appear in encoded IDs.
Instance Attribute Summary collapse
-
#words ⇒ Object
readonly
: Set.
Class Method Summary collapse
Instance Method Summary collapse
- #blocks?(string) ⇒ Boolean
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#filter_for_alphabet(alphabet) ⇒ Object
Filters the blocklist to only include words that can be formed from the given alphabet.
- #include?(word) ⇒ Boolean
-
#initialize(words = []) ⇒ Blocklist
constructor
A new instance of Blocklist.
- #merge(other_blocklist) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(words = []) ⇒ Blocklist
Returns a new instance of Blocklist.
41 42 43 44 45 46 47 |
# File 'lib/encoded_id/blocklist.rb', line 41 def initialize(words = []) @words = if words.is_a?(Array) || words.is_a?(Set) Set.new(words.map(&:to_s).map(&:downcase)) else Set.new end end |
Instance Attribute Details
#words ⇒ Object (readonly)
: Set
38 39 40 |
# File 'lib/encoded_id/blocklist.rb', line 38 def words @words end |
Class Method Details
.empty ⇒ Object
21 22 23 |
# File 'lib/encoded_id/blocklist.rb', line 21 def empty @empty ||= new([]) end |
.minimal ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/encoded_id/blocklist.rb', line 26 def minimal @minimal ||= new([ "ass", "cum", "fag", "fap", "fck", "fuk", "jiz", "pis", "poo", "sex", "tit", "xxx", "anal", "anus", "ball", "blow", "butt", "clit", "cock", "coon", "cunt", "dick", "dyke", "fart", "fuck", "jerk", "jizz", "jugs", "kike", "kunt", "muff", "nigg", "nigr", "piss", "poon", "poop", "porn", "pube", "pusy", "quim", "rape", "scat", "scum", "shit", "slut", "suck", "turd", "twat", "vag", "wank", "whor" ]) end |
.sqids_blocklist ⇒ Object
16 17 18 |
# File 'lib/encoded_id/blocklist.rb', line 16 def sqids_blocklist new(::Sqids::DEFAULT_BLOCKLIST) end |
Instance Method Details
#blocks?(string) ⇒ Boolean
60 61 62 63 64 65 66 67 68 |
# File 'lib/encoded_id/blocklist.rb', line 60 def blocks?(string) return false if empty? downcased_string = string.to_s.downcase @words.each do |word| return word if downcased_string.include?(word) end false end |
#each(&block) ⇒ Object
50 51 52 |
# File 'lib/encoded_id/blocklist.rb', line 50 def each(&block) @words.each(&block) end |
#empty? ⇒ Boolean
76 77 78 |
# File 'lib/encoded_id/blocklist.rb', line 76 def empty? @words.empty? end |
#filter_for_alphabet(alphabet) ⇒ Object
Filters the blocklist to only include words that can be formed from the given alphabet. Only keeps words where ALL characters exist in the alphabet (case-insensitive). Maintains minimum 3-character length requirement.
90 91 92 93 94 95 96 97 98 |
# File 'lib/encoded_id/blocklist.rb', line 90 def filter_for_alphabet(alphabet) alphabet_chars = Set.new( alphabet.is_a?(Alphabet) ? alphabet.unique_characters : alphabet.to_s.chars ) self.class.new( @words.select { |word| word.length >= 3 && word.chars.to_set.subset?(alphabet_chars) } ) end |
#include?(word) ⇒ Boolean
55 56 57 |
# File 'lib/encoded_id/blocklist.rb', line 55 def include?(word) @words.include?(word.to_s.downcase) end |
#merge(other_blocklist) ⇒ Object
81 82 83 |
# File 'lib/encoded_id/blocklist.rb', line 81 def merge(other_blocklist) self.class.new(to_a + other_blocklist.to_a) end |
#size ⇒ Object
71 72 73 |
# File 'lib/encoded_id/blocklist.rb', line 71 def size @words.size end |