Sha256: 3795d3dd5f6121bf39c96f1150b88a67bdcc823ca068a5adcceb63d529c6cfae

Contents?: true

Size: 959 Bytes

Versions: 2

Compression:

Stored size: 959 Bytes

Contents

# frozen_string_literal: true

class DSLProcessData
  PROCESSORS = [{ file_collector: ProcessFileCollector }].freeze

  # Method to process the JSON file after initial evaluation
  def process(base_path, input_file, output_file)
    json_file_path = File.join(base_path, input_file)
    data = JSON.parse(File.read(json_file_path))

    # Loop through the processors and execute matching ones
    PROCESSORS.each do |processor_entry|
      key, processor_class = processor_entry.first
      processor = processor_class.new(key)

      next unless processor.match?(data)

      result = processor.execute(data)

      data['process-data'] ||= {}

      result.each do |key, result|
        data['process-data'][key.to_s] = result unless result.empty?
      end
    end

    # Write the updated JSON data to an extended file
    extended_output_file = File.join(base_path, output_file)
    File.write(extended_output_file, JSON.pretty_generate(data))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
klue-langcraft-0.3.0 lib/dsl_process_data.rb
klue-langcraft-0.2.0 lib/dsl_process_data.rb