Class: BadWord

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(word, source, index, length, whitelist) ⇒ BadWord

Create new BadWord

Parameters:

  • word (String)

    found word

  • source (String)

    Source text where word was found

  • index (Integer)

    index of word in source

  • length (Integer)

    word length

  • whitelist (Array<String>)

    Whitelist words



12
13
14
15
16
17
18
19
20
21
# File 'lib/bad_word_detector/bad_word.rb', line 12

def initialize(word, source, index, length, whitelist)
  @index = index
  @length = length
  @word = word
  @source = source
  word_end = @index+@length-1
  space_location = @source.index(' ', word_end) || 0
  @text = @source[@index..space_location-1]
  @white_words = whitelist.check_bad_word(self)
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



2
3
4
# File 'lib/bad_word_detector/bad_word.rb', line 2

def index
  @index
end

#sourceObject (readonly)

Returns the value of attribute source.



2
3
4
# File 'lib/bad_word_detector/bad_word.rb', line 2

def source
  @source
end

#textObject (readonly)

Returns the value of attribute text.



2
3
4
# File 'lib/bad_word_detector/bad_word.rb', line 2

def text
  @text
end

#white_wordsObject (readonly)

Returns the value of attribute white_words.



2
3
4
# File 'lib/bad_word_detector/bad_word.rb', line 2

def white_words
  @white_words
end

#wordObject (readonly)

Returns the value of attribute word.



2
3
4
# File 'lib/bad_word_detector/bad_word.rb', line 2

def word
  @word
end

Instance Method Details

#white?true, false

Check if word is in whitelist

Returns:

  • (true, false)


26
27
28
# File 'lib/bad_word_detector/bad_word.rb', line 26

def white?
  !!@white_words
end