Class: QemuToolkit::Network::MacAddress
- Inherits:
-
Object
- Object
- QemuToolkit::Network::MacAddress
- Defined in:
- lib/qemu-toolkit/network/mac_address.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(address) ⇒ MacAddress
constructor
A new instance of MacAddress.
- #normalize(str) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(address) ⇒ MacAddress
Returns a new instance of MacAddress.
3 4 5 |
# File 'lib/qemu-toolkit/network/mac_address.rb', line 3 def initialize address @address = normalize(address) end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/qemu-toolkit/network/mac_address.rb', line 26 def == other self.to_s == other.to_s end |
#normalize(str) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/qemu-toolkit/network/mac_address.rb', line 7 def normalize str elements = str.split(':') fail "Malformed MAC address: not enough or too many elements (should == 6, was #{elements.size})." \ unless elements.size == 6 elements.map { |n| n.downcase! case n.size when 1 '0' + n when 2 n else fail "Malformed MAC address: #{str}; should have 6 elements with max. 2 digits." end }.join(':') end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/qemu-toolkit/network/mac_address.rb', line 30 def to_s @address end |