Class: Switch::PortName

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

Constant Summary collapse

MAX_ARGS =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ PortName

Returns a new instance of PortName.



18
19
20
21
22
23
24
25
26
# File 'lib/netutils/switch.rb', line 18

def initialize(name)
	if name =~ /^([^0-9]+)([0-9]?.*)/
		@type = $1.strip
		@numbers = $2.split('/')
	else
		@type = name.strip
		@numbers = Array.new
	end
end

Instance Attribute Details

#numbersObject (readonly)

Returns the value of attribute numbers.



16
17
18
# File 'lib/netutils/switch.rb', line 16

def numbers
  @numbers
end

Instance Method Details

#to_csvObject



32
33
34
35
36
37
38
# File 'lib/netutils/switch.rb', line 32

def to_csv
	n = @numbers.dup
	while n.length < MAX_ARGS do
		n.unshift('-')
	end
	[ @type, n ].join(',')
end

#to_sObject



28
29
30
# File 'lib/netutils/switch.rb', line 28

def to_s
	@type + ' ' + @numbers.join('/')
end