Class: Autoperf::Display::JSON

Inherits:
Object
  • Object
show all
Defined in:
lib/autoperf/display/json.rb

Instance Method Summary collapse

Constructor Details

#initialize(results, fields = nil) ⇒ JSON

Returns a new instance of JSON.



4
5
6
7
8
9
10
11
12
# File 'lib/autoperf/display/json.rb', line 4

def initialize(results, fields=nil)
  @results = []
  fields ||= ::Autoperf::Display::DEFAULT_FIELDS
  results.each do |rate, result|
    result.keep_if { |k,v| fields.include?(k) }
    result.merge!(:rate => rate) if fields.include?(:rate)
    @results.push(result)
  end
end

Instance Method Details



22
23
24
# File 'lib/autoperf/display/json.rb', line 22

def print
  puts ::JSON.pretty_generate(@results)
end

#to_jsonObject



18
19
20
# File 'lib/autoperf/display/json.rb', line 18

def to_json
  @results.to_json
end

#to_sObject



14
15
16
# File 'lib/autoperf/display/json.rb', line 14

def to_s
  to_json
end