Sha256: 5c4212d9ae71717fc1fb1a7ddf4971669c1475d803752e623441cac504948f1e
Contents?: true
Size: 1000 Bytes
Versions: 3
Compression:
Stored size: 1000 Bytes
Contents
module Hooray # Node representing a device class Node attr_accessor :host, :name, :nick, :mac, :ip, :ports 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 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 ports @ports.sort.map(&:number).join(', ') end def <=>(other) ip <=> other.ip end def eql?(other) ip == other.ip || mac == other.mac end def hash [ip, mac].hash end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hooray-0.1.9 | lib/hooray/node.rb |
hooray-0.1.8 | lib/hooray/node.rb |
hooray-0.1.5 | lib/hooray/node.rb |