Class: BadWord
- Inherits:
-
Object
- Object
- BadWord
- Defined in:
- lib/bad_word_detector/bad_word.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#white_words ⇒ Object
readonly
Returns the value of attribute white_words.
-
#word ⇒ Object
readonly
Returns the value of attribute word.
Instance Method Summary collapse
-
#initialize(word, source, index, length, whitelist) ⇒ BadWord
constructor
Create new BadWord.
-
#white? ⇒ true, false
Check if word is in whitelist.
Constructor Details
#initialize(word, source, index, length, whitelist) ⇒ BadWord
Create new BadWord
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
#index ⇒ Object (readonly)
Returns the value of attribute index.
2 3 4 |
# File 'lib/bad_word_detector/bad_word.rb', line 2 def index @index end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
2 3 4 |
# File 'lib/bad_word_detector/bad_word.rb', line 2 def source @source end |
#text ⇒ Object (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_words ⇒ Object (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 |
#word ⇒ Object (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
26 27 28 |
# File 'lib/bad_word_detector/bad_word.rb', line 26 def white? !!@white_words end |