Class: Autoperf::Display::JSON
- Inherits:
-
Object
- Object
- Autoperf::Display::JSON
- Defined in:
- lib/autoperf/display/json.rb
Instance Method Summary collapse
-
#initialize(results, fields = nil) ⇒ JSON
constructor
A new instance of JSON.
- #print ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
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
#print ⇒ Object
22 23 24 |
# File 'lib/autoperf/display/json.rb', line 22 def print puts ::JSON.pretty_generate(@results) end |
#to_json ⇒ Object
18 19 20 |
# File 'lib/autoperf/display/json.rb', line 18 def to_json @results.to_json end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/autoperf/display/json.rb', line 14 def to_s to_json end |