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.2"

Instance Method Summary collapse

Instance Method Details

#filter(str) ⇒ Object



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

def filter(str)
  blacklist     = JSON.parse(File.read(File.join(File.dirname(__FILE__), './lib/files/blacklist.json')))
  @str_array    = str.split(' ')
  current_index = -1

  @str_array.each_with_index do |word, index|
    next if index <= current_index

    first_letter  =  preprocess_word(word)[0].match?(REGEX_FIRST_LETTER) ? preprocess_word(word)[0] : 'other'
    index_badword =  detect_badword(blacklist[first_letter], index, index)
    replace_asterisk(index, index_badword) && current_index = index_badword unless index <= current_index
  end

  @str_array.join(' ')
end