Class: TestProf::TagProf::Result
- Inherits:
-
Object
- Object
- TestProf::TagProf::Result
- Defined in:
- lib/test_prof/tag_prof/result.rb
Overview
Object holding all the stats for tags
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
-
#initialize(tag, events = []) ⇒ Result
constructor
A new instance of Result.
- #to_json(*args) ⇒ Object
- #track(tag, time:, events: {}) ⇒ Object
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/test_prof/tag_prof/result.rb', line 7 def data @data end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
7 8 9 |
# File 'lib/test_prof/tag_prof/result.rb', line 7 def events @events end |
#tag ⇒ Object (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 |