Sha256: d7fb2e00a24ab185dc3be0afd32832167f7ab4f68e26408472f58045514f189a

Contents?: true

Size: 1.9 KB

Versions: 14

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module LittleWeasel
  module Preprocessors
    # This class provides a container for Preprocessors::PreprocessedWord
    # objects.
    class PreprocessedWords
      attr_reader :original_word, :preprocessed_words

      # 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.
      def initialize(original_word:, preprocessed_words:)
        self.original_word = original_word
        self.preprocessed_words = preprocessed_words
      end

      class << self
        # Returns true if the word was passed through any preprocessing. If
        # this is the case, #preprocessed_word may be different than
        # #original_word.
        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

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

          preprocessed_words.max_by(&:preprocessor_order).preprocessed_word
        end
      end

      def preprocessed_words=(value)
        value ||= []
        @preprocessed_words = value
      end

      def preprocessed_word
        self.class.preprocessed_word preprocessed_words: preprocessed_words
      end

      # Returns true if the word was preprocessed
      def preprocessed?
        self.class.preprocessed? preprocessed_words: preprocessed_words
      end

      private

      attr_writer :original_word
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
LittleWeasel-5.0.13 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.12 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.11 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.10 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.9 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.8 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.7 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.6 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.5 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.4 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.3 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.2 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.1 lib/LittleWeasel/preprocessors/preprocessed_words.rb
LittleWeasel-5.0.0 lib/LittleWeasel/preprocessors/preprocessed_words.rb