Class: TestProf::TagProf::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/tag_prof/result.rb

Overview

Object holding all the stats for tags

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, events = []) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/test_prof/tag_prof/result.rb', line 9

def initialize(tag, events = [])
  @tag = tag
  @events = events

  @data = Hash.new do |h, k|
    h[k] = {value: k, count: 0, time: 0.0}
    h[k].merge!(events.map { |event| [event, 0.0] }.to_h) unless
      events.empty?
    h[k]
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#eventsObject (readonly)

Returns the value of attribute events.



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

def events
  @events
end

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

Instance Method Details

#to_json(*args) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/test_prof/tag_prof/result.rb', line 29

def to_json(*args)
  {
    tag: tag,
    data: data.values,
    events: events
  }.to_json(*args)
end

#track(tag, time:, events: {}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/test_prof/tag_prof/result.rb', line 21

def track(tag, time:, events: {})
  data[tag][:count] += 1
  data[tag][:time] += time
  events.each do |event, time|
    data[tag][event] += time
  end
end