Class: Hooray::Node
- Inherits:
-
Object
- Object
- Hooray::Node
- Defined in:
- lib/hooray/node.rb
Overview
Node representing a device
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#mac ⇒ Object
Returns the value of attribute mac.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#ports ⇒ Object
Returns the value of attribute ports.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #find_name ⇒ Object
- #hash ⇒ Object
-
#initialize(params = {}) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(params = {}) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 |
# File 'lib/hooray/node.rb', line 6 def initialize(params = {}) self.ip = params[:ip] @mac = params[:mac] @mac ||= Mac.addr if @ip == Hooray::Local.lan_ip @name = params[:name] || find_name return unless params[:ports] @ports = params[:ports].reject(&:nil?).map { |n| Hooray::Port.new(n) } end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def host @host end |
#ip ⇒ Object
Returns the value of attribute ip.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def ip @ip end |
#mac ⇒ Object
Returns the value of attribute mac.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def mac @mac end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def name @name end |
#nick ⇒ Object
Returns the value of attribute nick.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def nick @nick end |
#ports ⇒ Object
Returns the value of attribute ports.
4 5 6 |
# File 'lib/hooray/node.rb', line 4 def ports @ports end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 |
# File 'lib/hooray/node.rb', line 33 def <=>(other) ip <=> other.ip end |
#eql?(other) ⇒ Boolean
37 38 39 |
# File 'lib/hooray/node.rb', line 37 def eql?(other) ip == other.ip || mac == other.mac end |
#find_name ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/hooray/node.rb', line 20 def find_name return unless mac if [Mac.addr].flatten.include?(mac) # Hack until macaddr get fix Socket.gethostname else Settings.device(mac) || Settings.manufacturer(mac) end end |
#hash ⇒ Object
41 42 43 |
# File 'lib/hooray/node.rb', line 41 def hash [ip, mac].hash end |