class Adhoq::Reporter::Json
Public Class Methods
Source
# File lib/adhoq/reporter/json.rb, line 7 def self.mime_type 'application/json' end
Source
# File lib/adhoq/reporter/json.rb, line 11 def initialize(result) @result = result end
Public Instance Methods
Source
# File lib/adhoq/reporter/json.rb, line 15 def build_report file = Tempfile.new(['adhoq-reporter', '.csv'], Dir.tmpdir, encoding: 'UTF-8') write_content!(file) file.tap(&:rewind) end
Private Instance Methods
Source
# File lib/adhoq/reporter/json.rb, line 24 def write_content!(file) json_objects = @result.rows.map {|row| Hash[*@result.header.zip(row).flatten] } file.write(JSON.dump(json_objects)) end