Class: Switch::Ports

Inherits:
Object
  • Object
show all
Defined in:
lib/netutils/switch.rb

Instance Method Summary collapse

Constructor Details

#initializePorts

Returns a new instance of Ports.



119
120
121
122
# File 'lib/netutils/switch.rb', line 119

def initialize
	@hash = Hash.new
	@list = Array.new
end

Instance Method Details

#[](name) ⇒ Object



133
134
135
# File 'lib/netutils/switch.rb', line 133

def [](name)
	return @hash[key(name)]
end

#add(name, model, type, speed, duplex) ⇒ Object



124
125
126
127
# File 'lib/netutils/switch.rb', line 124

def add(name, model, type, speed, duplex)
	port = Port.new(name, model, type, speed, duplex)
	@list << @hash[port.name.to_s] = port
end

#eachObject



145
146
147
# File 'lib/netutils/switch.rb', line 145

def each
	@list.each { |p| yield p }
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/netutils/switch.rb', line 137

def exists?(name)
	return @hash.key?(key(name))
end

#key(name) ⇒ Object



129
130
131
# File 'lib/netutils/switch.rb', line 129

def key(name)
	PortName.new(name).to_s
end

#lengthObject



141
142
143
# File 'lib/netutils/switch.rb', line 141

def length
	return @list.length
end