Class: Nmunch::Node
- Inherits:
-
Object
- Object
- Nmunch::Node
- Defined in:
- lib/nmunch/node.rb
Overview
Public: A class to represent a network node
For now it is a simple wrapper around IP and MAC address information but might contain more information in the future.
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#mac_address ⇒ Object
readonly
Returns the value of attribute mac_address.
Class Method Summary collapse
-
.create_from_dissector(dissector) ⇒ Object
Public: Convenience method to create a node from an Nmunch::Dissector instance.
Instance Method Summary collapse
-
#==(obj) ⇒ Object
Public: Compare string version of node.
-
#initialize(options) ⇒ Node
constructor
Public: Initialize a new node.
-
#meta_address? ⇒ Boolean
Public: Determine if node has a meta address.
-
#to_s ⇒ Object
Public: Convert node to string.
Constructor Details
#initialize(options) ⇒ Node
Public: Initialize a new node
options - A hash that must contain the keys :ip_address and :mac_address
Returns nothing
15 16 17 18 |
# File 'lib/nmunch/node.rb', line 15 def initialize() @ip_address = [:ip_address] @mac_address = [:mac_address] end |
Instance Attribute Details
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
8 9 10 |
# File 'lib/nmunch/node.rb', line 8 def ip_address @ip_address end |
#mac_address ⇒ Object (readonly)
Returns the value of attribute mac_address.
8 9 10 |
# File 'lib/nmunch/node.rb', line 8 def mac_address @mac_address end |
Class Method Details
.create_from_dissector(dissector) ⇒ Object
Public: Convenience method to create a node from an Nmunch::Dissector instance
dissector - An instance of Nmunch::Dissector
Returns instance of Nmunch::Node with details from dissector
49 50 51 |
# File 'lib/nmunch/node.rb', line 49 def self.create_from_dissector(dissector) self.new(ip_address: dissector.ip_address, mac_address: dissector.mac_address) end |
Instance Method Details
#==(obj) ⇒ Object
Public: Compare string version of node
Returns TRUE if same and FALSE if not
40 41 42 |
# File 'lib/nmunch/node.rb', line 40 def ==(obj) self.to_s == obj.to_s end |
#meta_address? ⇒ Boolean
Public: Determine if node has a meta address
A node will have a meta address (0.0.0.0) if it has not yet been given a DHCP lease
Returns TRUE if meta address and FALSE if not
26 27 28 |
# File 'lib/nmunch/node.rb', line 26 def ip_address == '0.0.0.0' end |
#to_s ⇒ Object
Public: Convert node to string
Returns IP address
33 34 35 |
# File 'lib/nmunch/node.rb', line 33 def to_s ip_address end |