Class: Klue::Langcraft::DSL::Processors::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/klue/langcraft/dsl/processors/processor.rb

Overview

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.

Direct Known Subclasses

FileCollectorProcessor, FullNameProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, key) ⇒ Processor

Every processor subclass must accept data and key



16
17
18
19
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 16

def initialize(data, key)
  @data = Marshal.load(Marshal.dump(data)) # Deep clone of the data
  @key = key
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 13

def data
  @data
end

#keyObject (readonly)

Returns the value of attribute key.



13
14
15
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 13

def key
  @key
end

Class Method Details

.keysObject

This will be overridden by subclasses to define keys (or aliases)

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 36

def self.keys
  raise NotImplementedError, 'Subclasses must define the `keys` method'
end

Instance Method Details

#build_resultObject

Build an envelope result with type, name, and data



22
23
24
25
26
27
28
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 22

def build_result
  {
    name: data.is_a?(Hash) ? data['as'] : nil,
    type: key.to_s,
    data: build_result_data
  }
end

#build_result_dataObject

Subclasses should override this method to build the actual data.

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 31

def build_result_data
  raise NotImplementedError, 'Subclasses must implement `build_data` to generate their specific data'
end