Sha256: addf0e0b2bfa3ee3440d88079e1a50575a399020ed24661d6e66e2431bc77689

Contents?: true

Size: 576 Bytes

Versions: 15

Compression:

Stored size: 576 Bytes

Contents

require 'json'

module Adhoq
  module Reporter
    class Json

      def self.mime_type
        'application/json'
      end

      def initialize(result)
        @result = result
      end

      def build_report
        file = Tempfile.new(['adhoq-reporter', '.csv'], Dir.tmpdir, encoding: 'UTF-8')
        write_content!(file)

        file.tap(&:rewind)
      end

      private

      def write_content!(file)
        json_objects = @result.rows.map {|row| Hash[*@result.header.zip(row).flatten] }

        file.write(JSON.dump(json_objects))
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
adhoq-1.0.2 lib/adhoq/reporter/json.rb
adhoq-1.0.1 lib/adhoq/reporter/json.rb
adhoq-1.0.0 lib/adhoq/reporter/json.rb
adhoq-0.5.0 lib/adhoq/reporter/json.rb
adhoq-0.5.0.beta1 lib/adhoq/reporter/json.rb
adhoq-0.4.0 lib/adhoq/reporter/json.rb
adhoq-0.3.0 lib/adhoq/reporter/json.rb
adhoq-0.2.0 lib/adhoq/reporter/json.rb
adhoq-0.1.2 lib/adhoq/reporter/json.rb
adhoq-0.1.1 lib/adhoq/reporter/json.rb
adhoq-0.1.0 lib/adhoq/reporter/json.rb
adhoq-0.0.7 lib/adhoq/reporter/json.rb
adhoq-0.0.6 lib/adhoq/reporter/json.rb
adhoq-0.0.5 lib/adhoq/reporter/json.rb
adhoq-0.0.4 lib/adhoq/reporter/json.rb