Class: LittleWeasel::WordResults

Inherits:
Object
  • Object
show all
Includes:
Modules::WordResultsValidatable, Preprocessors::PreprocessedWordsValidatable
Defined in:
lib/LittleWeasel/word_results.rb

Overview

This class represents the results of gathering information about a word.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Preprocessors::PreprocessedWordsValidatable

#validate_prepreprocessed_words, validate_prepreprocessed_words, #validation_error_message, validation_error_message

Methods included from Modules::WordResultsValidatable

#vaidate_word_valid, #validate_filters_matched, #validate_original_word, #validate_word_cached

Constructor Details

#initialize(original_word:, filters_matched: [], preprocessed_words: nil, word_cached: false, word_valid: false) ⇒ WordResults

Important: Regarding Boolean Methods

The return value of some of the boolean methods (i.e. methods ending with a ‘?’) of this class depend on whether or not #original_word has passed through any preprocessing. If #orginal_word has passed through preprocessing, the following boolean methods will reflect that of #preprocessed_word; if #original_word has NOT passed through any preprocessing, the following methods will reflect that of #original_word:

#success? #filter_match? #word_cached? #word_valid?

In other words, if #original_word has passed through preprocessing and has been altered by any of the preprocessing modules, it is the #preprocessed_word that is passed through any subsequent word filters, checked against the dictionary for validity, and cached, NOT #original_word. :reek:BooleanParameter - ignored, boolean params do not determine logic path, but only report status.



38
39
40
41
42
43
44
45
46
# File 'lib/LittleWeasel/word_results.rb', line 38

def initialize(original_word:, filters_matched: [],
  preprocessed_words: nil, word_cached: false, word_valid: false)

  self.original_word = original_word
  self.filters_matched = filters_matched
  self.word_cached = word_cached
  self.word_valid = word_valid
  self.preprocessed_words = preprocessed_words
end

Instance Attribute Details

#filters_matchedObject

Returns the value of attribute filters_matched.



13
14
15
# File 'lib/LittleWeasel/word_results.rb', line 13

def filters_matched
  @filters_matched
end

#original_wordObject

Returns the value of attribute original_word.



13
14
15
# File 'lib/LittleWeasel/word_results.rb', line 13

def original_word
  @original_word
end

#preprocessed_wordsObject

Returns the value of attribute preprocessed_words.



13
14
15
# File 'lib/LittleWeasel/word_results.rb', line 13

def preprocessed_words
  @preprocessed_words
end

#word_cachedObject

Returns the value of attribute word_cached.



13
14
15
# File 'lib/LittleWeasel/word_results.rb', line 13

def word_cached
  @word_cached
end

#word_validObject

Returns the value of attribute word_valid.



13
14
15
# File 'lib/LittleWeasel/word_results.rb', line 13

def word_valid
  @word_valid
end

Instance Method Details

#filter_match?Boolean

Returns true if the word was matched against at least one filter; false, otherwise.

See “Important: Regarding Boolean Methods” notes at the top of this class definition for more detail.

Returns:

  • (Boolean)


110
111
112
# File 'lib/LittleWeasel/word_results.rb', line 110

def filter_match?
  filters_matched.present?
end

#preprocessed_word?Boolean

Returns true if #original_word passed through any preprocessing. If this is the case, #preprocessed_word may be different than #original_word. Preprocessing should take place before any filtering takes place.

#word_cached, #word_valid and #filters_matched should all reflect that of the #preprocessed_word if #preprocessed_word is present?; otherwise, they should all reflect that of #original_word.

Returns:

  • (Boolean)


122
123
124
# File 'lib/LittleWeasel/word_results.rb', line 122

def preprocessed_word?
  preprocessed_word.present?
end

#preprocessed_word_or_original_wordObject

Returns #preprocessed_word (if available) or #original_word. #preprocessed_word will be present if #original_word has met the criteria for preprocessing and passed through at least one preprocessor.

See “Important: Regarding Boolean Methods” notes at the top of this class definition for more detail.



133
134
135
# File 'lib/LittleWeasel/word_results.rb', line 133

def preprocessed_word_or_original_word
  preprocessed_word || original_word
end

#success?Boolean

Returns true if the word is valid (found in the dictionary), or the word was matched against at least one filter; false, otherwise.

Use the results of this method if you want to consider a word’s validity as having been found in the dictionary as a valid word OR if the word has at least one word filter match. If the word has NOT passed through any word filters, or if word DID NOT match any filters, yet, it was found as a valid word in the dictionary, this method will return true and vice versa.

See “Important: Regarding Boolean Methods” notes at the top of this class definition for more detail.

Returns:

  • (Boolean)


89
90
91
# File 'lib/LittleWeasel/word_results.rb', line 89

def success?
  filter_match? || word_valid?
end

#word_cached?Boolean

Returns true if the word was found in the dictionary as a valid word OR if the word was found in the cache as an invalid word.

See “Important: Regarding Boolean Methods” notes at the top of this class definition for more detail.

Returns:

  • (Boolean)


142
143
144
# File 'lib/LittleWeasel/word_results.rb', line 142

def word_cached?
  word_cached
end

#word_valid?Boolean

Returns true if the word was found in the dictionary; false, otherwise.

Use the results of this method if you want to consider a word’s validity irrespective of whether or not the word has matched any word filters (if any).

See “Important: Regarding Boolean Methods” notes at the top of this class definition for more detail.

Returns:

  • (Boolean)


101
102
103
# File 'lib/LittleWeasel/word_results.rb', line 101

def word_valid?
  word_valid
end