Class: Klue::Langcraft::DSL::KlueRunner

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

Overview

KlueRunner handles the processing of DSL input data It manages the execution of various processors and the output of processed data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKlueRunner

Returns a new instance of KlueRunner.



11
12
13
14
15
# File 'lib/klue/langcraft/dsl/klue_runner.rb', line 11

def initialize
  @interpreter = Klue::Langcraft::DSL::Interpreter.new
  @pipeline = Klue::Langcraft::DSL::ProcessDataPipeline.new(Klue::Langcraft::DSL::ProcessMatcher.new)
  @webhook = Klue::Langcraft::DSL::Webhook.new
end

Instance Attribute Details

#interpreterObject (readonly)

Returns the value of attribute interpreter.



9
10
11
# File 'lib/klue/langcraft/dsl/klue_runner.rb', line 9

def interpreter
  @interpreter
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



9
10
11
# File 'lib/klue/langcraft/dsl/klue_runner.rb', line 9

def pipeline
  @pipeline
end

#webhookObject (readonly)

Returns the value of attribute webhook.



9
10
11
# File 'lib/klue/langcraft/dsl/klue_runner.rb', line 9

def webhook
  @webhook
end

Instance Method Details

#run(input: nil, input_file: nil, basic_output_file: nil, enhanced_output_file: nil, webhook_url: nil, log_level: :none) ⇒ Object

Run the KlueRunner with the given input data

Parameters:

  • input (String) (defaults to: nil)

    The input data to process

  • input_file (String) (defaults to: nil)

    The input file to process (input data and file are mutually exclusive)

  • basic_output_file (String) (defaults to: nil)

    The output file to write the processed data, this file is before any processing

  • enhanced_output_file (String) (defaults to: nil)

    The output file to write the processed data, this file is after processing



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/klue/langcraft/dsl/klue_runner.rb', line 22

def run(
  input: nil,
  input_file: nil,
  basic_output_file: nil,
  enhanced_output_file: nil,
  webhook_url: nil,
  log_level: :none
)
  @log_level = log_level

  log_info('Processing input')
  data = interpreter.process(input: input, input_file: input_file, output_file: basic_output_file)
  log_detailed('Interpreter output:', data)

  log_info('Executing pipeline - enhance')
  enhanced_data = pipeline.execute(data)
  log_detailed('Enhanced output:', enhanced_data)

  if enhanced_output_file
    log_info("Writing enhanced output to file: #{enhanced_output_file}")
    @pipeline.write_output(enhanced_data, enhanced_output_file)
  end

  if webhook_url
    log_info("Delivering data to webhook: #{webhook_url}")
    @webhook.deliver(webhook_url, enhanced_data)
  end

  log_info('Processing complete')
end