Class: Switch::Ports
- Inherits:
-
Object
- Object
- Switch::Ports
- Defined in:
- lib/netutils/switch.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(name, model, type, speed, duplex) ⇒ Object
- #each ⇒ Object
- #exists?(name) ⇒ Boolean
-
#initialize ⇒ Ports
constructor
A new instance of Ports.
- #key(name) ⇒ Object
- #length ⇒ Object
Constructor Details
#initialize ⇒ Ports
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 |
#each ⇒ Object
145 146 147 |
# File 'lib/netutils/switch.rb', line 145 def each @list.each { |p| yield p } end |
#exists?(name) ⇒ 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 |
#length ⇒ Object
141 142 143 |
# File 'lib/netutils/switch.rb', line 141 def length return @list.length end |