lib/hooray/node.rb in hooray-0.0.9 vs lib/hooray/node.rb in hooray-0.1.5
- old
+ new
@@ -2,26 +2,33 @@
# Node representing a device
class Node
attr_accessor :host, :name, :nick, :mac, :ip, :ports
def initialize(params = {})
- @ip = params[:ip]
+ self.ip = params[:ip]
@mac = params[:mac]
- @mac ||= Mac.addr if @ip == Seek.my_lan_ip
+ @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
+ def ip=(param)
+ return unless param
+ @ip = param.is_a?(IPAddr) ? param : IPAddr.new(param)
+ end
+
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
- def to_ip
- IPAddr.new(ip)
+ def ports
+ @ports.sort.map(&:number).join(', ')
end
def <=>(other)
ip <=> other.ip
end