Class: Perfer::Result

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/perfer/result.rb

Overview

A result for a particular job run

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata, data = []) ⇒ Result

Returns a new instance of Result.



8
9
10
11
# File 'lib/perfer/result.rb', line 8

def initialize(, data = [])
  @metadata = .dup
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/perfer/result.rb', line 7

def data
  @data
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/perfer/result.rb', line 6

def 
  @metadata
end

Class Method Details

.json_create(json) ⇒ Object



38
39
40
# File 'lib/perfer/result.rb', line 38

def self.json_create json
  new(json['metadata'], json['data'])
end

Instance Method Details

#on(field) ⇒ Object



22
23
24
# File 'lib/perfer/result.rb', line 22

def on(field)
  @data.map { |result| result[field] }
end

#statsObject



18
19
20
# File 'lib/perfer/result.rb', line 18

def stats
  Statistics.new(on(:real))
end

#to_hashObject



26
27
28
# File 'lib/perfer/result.rb', line 26

def to_hash
  { :metadata => @metadata, :data => @data }
end

#to_json(*args) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/perfer/result.rb', line 30

def to_json(*args)
  {
    'json_class' => self.class.name,
    'data'       => @data,
    'metadata'   => @metadata
  }.to_json(*args)
end