Class: Klue::Langcraft::DSL::Processors::Processor
- Inherits:
-
Object
- Object
- Klue::Langcraft::DSL::Processors::Processor
- 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
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
-
.keys ⇒ Object
This will be overridden by subclasses to define keys (or aliases).
Instance Method Summary collapse
-
#build_result ⇒ Object
Build an envelope result with type, name, and data.
-
#build_result_data ⇒ Object
Subclasses should override this method to build the actual data.
-
#initialize(data, key) ⇒ Processor
constructor
Every processor subclass must accept data and key.
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
13 14 15 |
# File 'lib/klue/langcraft/dsl/processors/processor.rb', line 13 def data @data end |
#key ⇒ Object (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
.keys ⇒ Object
This will be overridden by subclasses to define keys (or aliases)
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_result ⇒ Object
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_data ⇒ Object
Subclasses should override this method to build the actual data.
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 |