Class: Dragnet::Exporter

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

Overview

The base exporter class, receives an array of test records, an array of errors and an array of file names and exports the results to the given files. (For each file the format is deduced from its file name).

Constant Summary collapse

KNOWN_FORMATS =
{
  'HTML' => { extensions: %w[.html .htm], exporter: Dragnet::Exporters::HTMLExporter },
  'JSON' => { extensions: %w[.json], exporter: Dragnet::Exporters::JSONExporter }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_records:, errors:, repository:, targets:, logger:) ⇒ Exporter

Creates a new instance of the class.



30
31
32
33
34
35
36
# File 'lib/dragnet/exporter.rb', line 30

def initialize(test_records:, errors:, repository:, targets:, logger:)
  @test_records = test_records
  @errors = errors
  @repository = repository
  @targets = targets
  @logger = logger
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



18
19
20
# File 'lib/dragnet/exporter.rb', line 18

def errors
  @errors
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/dragnet/exporter.rb', line 18

def logger
  @logger
end

#repositoryObject (readonly)

Returns the value of attribute repository.



18
19
20
# File 'lib/dragnet/exporter.rb', line 18

def repository
  @repository
end

#targetsObject (readonly)

Returns the value of attribute targets.



18
19
20
# File 'lib/dragnet/exporter.rb', line 18

def targets
  @targets
end

#test_recordsObject (readonly)

Returns the value of attribute test_records.



18
19
20
# File 'lib/dragnet/exporter.rb', line 18

def test_records
  @test_records
end

Instance Method Details

#exportObject

Starts the export process.

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dragnet/exporter.rb', line 42

def export
  logger.info 'Starting export process...'
  log_target_files

  formats.each do |format, targets|
    exporter = KNOWN_FORMATS.dig(format, :exporter).new(
      test_records: test_records, errors: errors, repository: repository, logger: logger
    )

    text = exporter.export
    write_output(text, format, targets)
  end
end