Class: Nmunch::Node

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options)
  @ip_address  = options[:ip_address]
  @mac_address = options[:mac_address]
end

Instance Attribute Details

#ip_addressObject (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_addressObject (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

Returns:

  • (Boolean)


26
27
28
# File 'lib/nmunch/node.rb', line 26

def meta_address?
  ip_address == '0.0.0.0'
end

#to_sObject

Public: Convert node to string

Returns IP address



33
34
35
# File 'lib/nmunch/node.rb', line 33

def to_s
  ip_address
end