Class: Whitelist

Inherits:
Object
  • Object
show all
Defined in:
lib/bad_word_detector/whitelist.rb

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ Whitelist

Returns a new instance of Whitelist.



3
4
5
# File 'lib/bad_word_detector/whitelist.rb', line 3

def initialize(list)
  @words_set = Set.new list
end

Instance Method Details

#check(words) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/bad_word_detector/whitelist.rb', line 11

def check(words)
  all_white = words.all? do |word|
    @words_set.include? word
  end
  if all_white 
    words
  end
end

#check_bad_word(word) ⇒ Object



20
21
22
# File 'lib/bad_word_detector/whitelist.rb', line 20

def check_bad_word(word)
  self.check_substring(word.source, word.index, word.word.length)
end

#check_substring(text, index, length) ⇒ Object



6
7
8
9
# File 'lib/bad_word_detector/whitelist.rb', line 6

def check_substring(text, index, length)
  words = text.get_substring_words(index, length)
  self.check(words)
end

#inspectObject



24
25
26
# File 'lib/bad_word_detector/whitelist.rb', line 24

def inspect
  "#<#{self.class.name}:#{self.object_id}>"
end