Sha256: 84f3b7c383d14487ddf6d83d2141a4ed930829e2521f0c3be4654729fce1445d

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Klue
  module Langcraft
    module DSL
      module Processors
        # Base Processor class for defining common processor behavior
        #
        # This abstract class serves as the foundation for all specific processors.
        # It defines the basic structure and common methods that all processors
        # should implement or inherit.
        class Processor
          attr_reader :data, :key

          # Every processor subclass must accept data and key
          def initialize(data, key)
            @data = Marshal.load(Marshal.dump(data)) # Deep clone of the data
            @key = key
          end

          # Build an envelope result with type, name, and data
          def build_result
            {
              name: data.is_a?(Hash) ? data['as'] : nil,
              type: key.to_s,
              data: build_result_data
            }
          end

          # Subclasses should override this method to build the actual data.
          def build_result_data
            raise NotImplementedError, 'Subclasses must implement `build_data` to generate their specific data'
          end

          # This will be overridden by subclasses to define keys (or aliases)
          def self.keys
            raise NotImplementedError, 'Subclasses must define the `keys` method'
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
klue-langcraft-0.4.0 lib/klue/langcraft/dsl/processors/processor.rb
klue-langcraft-0.3.0 lib/klue/langcraft/dsl/processors/processor.rb
klue-langcraft-0.2.0 lib/klue/langcraft/dsl/processors/processor.rb