Class: Hooray::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/hooray/node.rb

Overview

Node representing a device

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject

Returns the value of attribute host.



4
5
6
# File 'lib/hooray/node.rb', line 4

def host
  @host
end

#ipObject

Returns the value of attribute ip.



4
5
6
# File 'lib/hooray/node.rb', line 4

def ip
  @ip
end

#macObject

Returns the value of attribute mac.



4
5
6
# File 'lib/hooray/node.rb', line 4

def mac
  @mac
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/hooray/node.rb', line 4

def name
  @name
end

#nickObject

Returns the value of attribute nick.



4
5
6
# File 'lib/hooray/node.rb', line 4

def nick
  @nick
end

#portsObject

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/hooray/node.rb', line 37

def eql?(other)
  ip == other.ip || mac == other.mac
end

#find_nameObject



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

#hashObject



41
42
43
# File 'lib/hooray/node.rb', line 41

def hash
  [ip, mac].hash
end