Class: DSLProcessData

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl_process_data.rb

Constant Summary collapse

PROCESSORS =
[{ file_collector: ProcessFileCollector }].freeze

Instance Method Summary collapse

Instance Method Details

#process(base_path, input_file, output_file) ⇒ Object

Method to process the JSON file after initial evaluation



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dsl_process_data.rb', line 7

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