Class: LittleWeasel::Preprocessors::PreprocessedWords

Inherits:
Object
  • Object
show all
Defined in:
lib/LittleWeasel/preprocessors/preprocessed_words.rb

Overview

This class provides a container for Preprocessors::PreprocessedWord objects.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_word:, preprocessed_words:) ⇒ PreprocessedWords

original_word:String the unsullied word before any preprocessing has been applied to it. preprocessed_words:Array, Preprocessors::PreprocessedWord, an Array of Preprocessors::PreprocessedWord objects that represents the original_word having passed through each successive Preprocessors::WordPreprocessor.



16
17
18
19
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 16

def initialize(original_word:, preprocessed_words:)
  self.original_word = original_word
  self.preprocessed_words = preprocessed_words
end

Instance Attribute Details

#original_wordObject

Returns the value of attribute original_word.



8
9
10
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 8

def original_word
  @original_word
end

#preprocessed_wordsObject

Returns the value of attribute preprocessed_words.



8
9
10
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 8

def preprocessed_words
  @preprocessed_words
end

Class Method Details

.preprocessed?(preprocessed_words:) ⇒ Boolean

Returns true if the word was passed through any preprocessing. If this is the case, #preprocessed_word may be different than #original_word.

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 25

def preprocessed?(preprocessed_words:)
  # TODO: Do we need to check for preprocessors where
  # #preprocessed? is true? or does preprocessed_words
  # contain only preprocessed word objects where
  # #preprocessed? is true?
  preprocessed_words.present?
end

.preprocessed_word(preprocessed_words:) ⇒ Object



33
34
35
36
37
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 33

def preprocessed_word(preprocessed_words:)
  return unless preprocessed? preprocessed_words: preprocessed_words

  preprocessed_words.max_by(&:preprocessor_order).preprocessed_word
end

Instance Method Details

#preprocessed?Boolean

Returns true if the word was preprocessed

Returns:

  • (Boolean)


50
51
52
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 50

def preprocessed?
  self.class.preprocessed? preprocessed_words: preprocessed_words
end

#preprocessed_wordObject



45
46
47
# File 'lib/LittleWeasel/preprocessors/preprocessed_words.rb', line 45

def preprocessed_word
  self.class.preprocessed_word preprocessed_words: preprocessed_words
end