Class: MacAddr
- Inherits:
-
Ruckus::Str
- Object
- Ruckus::Parsel
- Ruckus::Str
- MacAddr
- Defined in:
- lib/ruckus/mac_addr.rb
Overview
instead of dealing with .value directly, this class exposes ‘set’ and ‘display’ methods for handling @value as a mac address string.
Constant Summary
Constants inherited from Ruckus::Parsel
Instance Attribute Summary
Attributes inherited from Ruckus::Parsel
#name, #parent, #rendered_offset, #rendering, #tag, #value
Instance Method Summary collapse
- #display ⇒ Object
-
#initialize(opts = {}) ⇒ MacAddr
constructor
A new instance of MacAddr.
-
#set(val) ⇒ Object
mac address may be specified as either aa-bb-cc-dd-ee-ff or aa:bb:cc:dd:ee:ff.
- #to_human(indent = nil) ⇒ Object
Methods inherited from Ruckus::Str
Methods inherited from Ruckus::Parsel
bytes_for_bits, coerce, #each_matching_selector, endian?, factory?, #find_containing, #find_tag, #find_tag_struct, #fixup, #in, #incomplete!, #index_for_selectors, #inspect, #matches_selector?, #method_missing, #native?, native?, #next, #out, #parent_structure, #permute, #prev, #resolve, #respond_to?, #root, #size, #visit, #where_am_i?
Constructor Details
#initialize(opts = {}) ⇒ MacAddr
Returns a new instance of MacAddr.
4 5 6 7 8 |
# File 'lib/ruckus/mac_addr.rb', line 4 def initialize(opts={}) opts[:size] = 6 super(opts) @width = 48 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruckus::Parsel
Instance Method Details
#display ⇒ Object
22 23 24 |
# File 'lib/ruckus/mac_addr.rb', line 22 def display self.value.split('').map {|x| x.hexify}.join(':') end |
#set(val) ⇒ Object
mac address may be specified as either
aa-bb-cc-dd-ee-ff
or
aa:bb:cc:dd:ee:ff
14 15 16 17 18 19 |
# File 'lib/ruckus/mac_addr.rb', line 14 def set(val) unless m=/^([0-9a-f]{2})([:-]?)([0-9a-f]{2})\2([0-9a-f]{2})\2([0-9a-f]{2})\2([0-9a-f]{2})\2([0-9a-f]{2})$/i.match(val) raise "argument must be a mac_addr string as in aa:bb:cc:dd:ee:ff" end self.value = [$1,$3,$4,$5,$6,$7].join('').dehexify end |
#to_human(indent = nil) ⇒ Object
26 27 28 29 |
# File 'lib/ruckus/mac_addr.rb', line 26 def to_human(indent=nil) indent ||= "" "#{indent}#{name} = #{self.display}" end |