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.
3 4 5 6 |
# File 'lib/nosey/report.rb', line 3 def initialize yield self if block_given? self end |
Instance Method Details
#probe_sets ⇒ Object
Grab some probe_sets or an array
14 15 16 |
# File 'lib/nosey/report.rb', line 14 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
9 10 11 |
# File 'lib/nosey/report.rb', line 9 def probe_sets=(probe_sets) @probe_sets = Array(probe_sets).flatten end |
#reset ⇒ Object
Reset all the counters in each probe.
34 35 36 |
# File 'lib/nosey/report.rb', line 34 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.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nosey/report.rb', line 21 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.
40 41 42 |
# File 'lib/nosey/report.rb', line 40 def to_s Psych.dump to_hash end |