Class: Nmunch::Report
- Inherits:
-
Object
- Object
- Nmunch::Report
- Defined in:
- lib/nmunch/report.rb
Overview
Public: Nmunch report class
Keeps track of discovered nodes and publishes nodes to registered subscribers
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options) ⇒ Report
constructor
Public: Initialize a new report.
-
#publish_node(node) ⇒ Object
Public: Publish a new node to all registered subscribers.
-
#register_subscriber(subscriber) ⇒ Object
Public: Register a new subscriber.
-
#summary ⇒ Object
Public: Get a summary.
Constructor Details
#initialize(options) ⇒ Report
Public: Initialize a new report
options - Hash of command line options
12 13 14 15 16 |
# File 'lib/nmunch/report.rb', line 12 def initialize() @options = @subscribers = [] @discovered_nodes = [] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/nmunch/report.rb', line 7 def @options end |
Instance Method Details
#publish_node(node) ⇒ Object
Public: Publish a new node to all registered subscribers
node - An instance of Nmunch::Node
Already discovered nodes or nodes with meta addresses (e.g. DHCP requests) will be ignored.
Returns nothing
38 39 40 41 42 43 |
# File 'lib/nmunch/report.rb', line 38 def publish_node(node) if !node. && !@discovered_nodes.include?(node) @subscribers.each { |s| s.process(node) } @discovered_nodes << node end end |
#register_subscriber(subscriber) ⇒ Object
Public: Register a new subscriber
subscriber - An object that responds to #process(node)
All subscribers will be notified of new nodes and it is up to each subscriber to do something meaningful with the node.
Returns nothing
26 27 28 |
# File 'lib/nmunch/report.rb', line 26 def register_subscriber(subscriber) @subscribers << subscriber end |
#summary ⇒ Object
Public: Get a summary
Returns a simple summary telling how many live nodes were discovered TODO: Make the summary more detailed
49 50 51 |
# File 'lib/nmunch/report.rb', line 49 def summary " Discovered #{@discovered_nodes.count} live node(s)" end |