Sha256: 4bd201314283fa1a578b05cb68a37e8e50156c139c1ed09cd94befbb6868b21f

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'json'

require_relative 'exporter'
require_relative 'id_generator'
require_relative 'serializers/test_record_serializer'

module Dragnet
  module Exporters
    # Exports the results for the Manual Test Record verification to a JSON
    # string.
    class JSONExporter < ::Dragnet::Exporters::Exporter
      # @return [String] A JSON string containing an array of objects, one for
      #   each Test Record.
      def export
        logger.info 'Exporting data to JSON'
        test_records.map do |test_record|
          ::Dragnet::Exporters::Serializers::TestRecordSerializer
            .new(test_record, repository).serialize
            .merge(id: id_generator.id_for(test_record))
        end.to_json
      end

      private

      # @return [Dragnet::Exporters::IDGenerator] An instance of the IDGenerator
      #   class that can be used to calculate the ID for the exported MTRs.
      def id_generator
        @id_generator ||= ::Dragnet::Exporters::IDGenerator.new(repository)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dragnet-5.3.1 lib/dragnet/exporters/json_exporter.rb
dragnet-5.3.0 lib/dragnet/exporters/json_exporter.rb
dragnet-5.2.1 lib/dragnet/exporters/json_exporter.rb