Module: WordCensored

Defined in:
lib/word_censored.rb,
lib/word_censored/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

REGEX_FIRST_LETTER =

Your code goes here…

/[a-zàáãạảăắằẳẵặâấầẩẫậèéẹẻẽêềếểễệđìíĩỉịòóõọỏôốồổỗộơớờởỡợùúũụủưứừửữựỳỵỷỹý]/i
REGEX_PREPROCESS =
/([^0-9a-zàáãạảăắằẳẵặâấầẩẫậèéẹẻẽêềếểễệđìíĩỉịòóõọỏôốồổỗộơớờởỡợùúũụủưứừửữựỳỵỷỹý ])/i
VERSION =
"0.1.6"

Instance Method Summary collapse

Instance Method Details

#filter(str) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/word_censored.rb', line 11

def filter(str)
  blacklist  = combine_blacklist
  @str_array = str.split(' ')
  cindex     = -1

  @str_array.each_with_index do |word, index|
    next if index <= cindex
    next if preprocess(word).strip.empty?

    first_letter = preprocess(word)[0].match?(REGEX_FIRST_LETTER) ? preprocess(word)[0] : 'other'
    ibadword     = detect_badword(blacklist[first_letter], index, index)
    replace_asterisk(index, ibadword) && cindex = ibadword if ibadword >= index
  end

  @str_array.join(' ')
end