Method: Pio::Mac#initialize

Defined in:
lib/pio/mac.rb

#initialize(value) ⇒ Mac

Creates a Pio::Mac instance that encapsulates Ethernet addresses.

Examples:

address as a hexadecimal string

Mac.new("11:22:33:44:55:66")

address as a hexadecimal number

Mac.new(0xffffffffffff)

Parameters:

  • value (#to_str, #to_int)

    the value converted to an Ethernet address.


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pio/mac.rb', line 27

def initialize(value)
  if value.respond_to?(:to_str)
    @value = parse_mac_string(value.to_str)
  elsif value.respond_to?(:to_int)
    @value = value.to_int
    validate_value_range
  else
    fail TypeError
  end
rescue ArgumentError, TypeError
  raise InvalidValueError, "Invalid MAC address: #{ value.inspect }"
end