Class: LittleWeasel::BlockResults

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

Overview

This class represents the results of gathering information about a word block (group of words).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_word_block:) ⇒ BlockResults

Returns a new instance of BlockResults.



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

def initialize(original_word_block:)
  self.original_word_block = original_word_block
  self.word_results = []
end

Instance Attribute Details

#original_word_blockObject

:reek:Attribute - Ignored, it doesn’t make sense to create a formal setter method.



11
12
13
# File 'lib/LittleWeasel/block_results.rb', line 11

def original_word_block
  @original_word_block
end

#word_resultsObject

:reek:Attribute - Ignored, it doesn’t make sense to create a formal setter method.



11
12
13
# File 'lib/LittleWeasel/block_results.rb', line 11

def word_results
  @word_results
end

Instance Method Details

#<<(word_result) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/LittleWeasel/block_results.rb', line 18

def <<(word_result)
  unless word_result.is_a? WordResults
    raise ArgumentError, "Argument word_result is not a WordResults object: #{word_result.class}"
  end

  word_results << word_result
end

#filters_match?Boolean

Returns true if all WordResults object words have filter matches (#filters_match?); false otherwise.

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/LittleWeasel/block_results.rb', line 44

def filters_match?
  return false unless word_results.present?

  word_results.all?(&:filter_match?)
end

#preprocessed_words?Boolean

Returns true if all WordResults object words have been preprocessed (#preprocessed_words?); false otherwise.

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/LittleWeasel/block_results.rb', line 52

def preprocessed_words?
  return false unless word_results.present?

  word_results.all?(&:preprocessed_word?)
end

#preprocessed_words_or_original_wordsObject

Calls #preprocessed_word_or_original_word on all WordResults objects. An Array of the results is returned.



63
64
65
66
67
# File 'lib/LittleWeasel/block_results.rb', line 63

def preprocessed_words_or_original_words
  return [] unless word_results.present?

  word_results.map(&:preprocessed_word_or_original_word)
end

#success?Boolean

Calls #success? on all WordResults objects. Returns true if all WordResults return true; false is returned otherwise.

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/LittleWeasel/block_results.rb', line 28

def success?
  return false unless word_results.present?

  word_results.all?(&:success?)
end

#words_cached?Boolean

Returns true if all WordResults object words have been cached (#words_cached?); false otherwise.

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/LittleWeasel/block_results.rb', line 71

def words_cached?
  return false unless word_results.present?

  word_results.all?(&:word_cached?)
end

#words_valid?Boolean

Returns true if all WordResults object words are valid (#word_valid?); false otherwise.

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/LittleWeasel/block_results.rb', line 36

def words_valid?
  return false unless word_results.present?

  word_results.all?(&:word_valid?)
end