Class: Nosey::Report
- Inherits:
-
Object
- Object
- Nosey::Report
- Defined in:
- lib/nosey/report.rb
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Report
constructor
A new instance of Report.
-
#probe_sets ⇒ Object
Grab some probe_sets or an array.
-
#probe_sets=(probe_sets) ⇒ Object
Make sure we end up with a flat array of probe_sets.
-
#reset ⇒ Object
Reset all the counters in each probe.
-
#to_hash ⇒ Object
Hash representation of all the probe_sets.
-
#to_s ⇒ Object
String representation of all the probe_sets that’s suitable for flushing out over a socket.
Constructor Details
#initialize {|_self| ... } ⇒ Report
Returns a new instance of Report.
5 6 7 8 |
# File 'lib/nosey/report.rb', line 5 def initialize yield self if block_given? self end |
Instance Method Details
#probe_sets ⇒ Object
Grab some probe_sets or an array
16 17 18 |
# File 'lib/nosey/report.rb', line 16 def probe_sets @probe_sets ||= Array.new end |
#probe_sets=(probe_sets) ⇒ Object
Make sure we end up with a flat array of probe_sets
11 12 13 |
# File 'lib/nosey/report.rb', line 11 def probe_sets=(probe_sets) @probe_sets = Array(probe_sets).flatten end |
#reset ⇒ Object
Reset all the counters in each probe.
36 37 38 |
# File 'lib/nosey/report.rb', line 36 def reset probe_sets.each(&:reset) end |
#to_hash ⇒ Object
Hash representation of all the probe_sets. This gives is an intermediate format that we can parse from other systems or code that needs reporting data for formatting, or whatever.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nosey/report.rb', line 23 def to_hash # Drop the probes into the report probe_sets.inject({}) { |report, set| report[set.name.to_s] = set.probes.inject({}) { |memo, (_, probe)| # round the values to 2 decimal places memo[probe.name] = (probe.value.to_f * 100).round().to_f/100 memo } report } end |
#to_s ⇒ Object
String representation of all the probe_sets that’s suitable for flushing out over a socket.
42 43 44 |
# File 'lib/nosey/report.rb', line 42 def to_s Psych.dump to_hash end |