Class: Switch::PortName
- Inherits:
-
Object
- Object
- Switch::PortName
- Defined in:
- lib/netutils/switch.rb
Constant Summary collapse
- MAX_ARGS =
3
Instance Attribute Summary collapse
-
#numbers ⇒ Object
readonly
Returns the value of attribute numbers.
Instance Method Summary collapse
-
#initialize(name) ⇒ PortName
constructor
A new instance of PortName.
- #to_csv ⇒ Object
- #to_s ⇒ Object
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
#numbers ⇒ Object (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_csv ⇒ Object
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_s ⇒ Object
28 29 30 |
# File 'lib/netutils/switch.rb', line 28 def to_s @type + ' ' + @numbers.join('/') end |