Module: Baseh::Profanity
- Defined in:
- lib/baseh/profanity.rb
Overview
Profanity safety, spec section 18. Profiles gain an optional profanity: { mode:, words:, extra_words: } object. It never changes decode behavior for issued codes and never changes capacity accounting.
Constant Summary collapse
- DEFAULT_BLOCKLIST =
Spec 18.2 default list. Deliberately small; applications extend it.
%w[ CRAP TWAT SHAG DAMN FCK FUC SHT CNT TWT DCK AZZ BCH ].freeze
- MODES =
%w[none no-vowels blocklist].freeze
- WORD =
/\A[A-Za-z]{2,32}\z/.freeze
- VOWELS =
"AEIOU"
Class Method Summary collapse
-
.effective_blocklist(profanity) ⇒ Object
Spec 18.2: replacement semantics, then augmentation, uppercased and deduplicated.
-
.strip_vowels(alphabet_norm) ⇒ Object
Spec 18.1: vowels removed for no-vowels mode, applied after case normalization.
Class Method Details
.effective_blocklist(profanity) ⇒ Object
Spec 18.2: replacement semantics, then augmentation, uppercased and deduplicated. Raises BasehError INVALID_PROFILE for malformed entries.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/baseh/profanity.rb', line 27 def effective_blocklist(profanity) base = profanity[:words] || DEFAULT_BLOCKLIST list = Array(base) + Array(profanity[:extra_words] || []) out = [] list.each do |word| unless word.is_a?(String) && WORD.match?(word) raise BasehError.new( "INVALID_PROFILE", "Invalid baseH profile: blocklist entries must be 2 through 32 ASCII letters", safe_for_customer: false ) end upper = word.upcase out << upper unless out.include?(upper) end out end |
.strip_vowels(alphabet_norm) ⇒ Object
Spec 18.1: vowels removed for no-vowels mode, applied after case normalization.
21 22 23 |
# File 'lib/baseh/profanity.rb', line 21 def strip_vowels(alphabet_norm) alphabet_norm.delete(VOWELS) end |