Class: MacAddressEui48::MacAddress
- Inherits:
-
Object
- Object
- MacAddressEui48::MacAddress
- Includes:
- Comparable
- Defined in:
- lib/mac_address_eui48/mac_address.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(arg) ⇒ MacAddress
constructor
A new instance of MacAddress.
- #is_broadcast ⇒ Object
- #is_glob_uniq ⇒ Object
- #is_loc_admin ⇒ Object
- #is_multicast ⇒ Object
- #is_unicast ⇒ Object
- #next ⇒ Object (also: #succ)
- #to_i ⇒ Object
- #to_s(sep = ':') ⇒ Object
Constructor Details
#initialize(arg) ⇒ MacAddress
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mac_address_eui48/mac_address.rb', line 9 def initialize(arg) case arg when MacAddress @val = arg.to_i when Integer @val = arg when String # String value must be provided as hex char separated by ':' if (MacAddressEui48::is_valid_mac(arg)) then @mac_str=arg @val=MacAddressEui48::str_mac_to_int(arg) else raise "Wrong format for string mac address #{arg}" end else raise "Incompatible type for MacAddress Initialization: #{arg.class}" end end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 |
# File 'lib/mac_address_eui48/mac_address.rb', line 32 def <=>(other) self.to_i <=> other.to_i end |
#is_broadcast ⇒ Object
40 41 42 43 |
# File 'lib/mac_address_eui48/mac_address.rb', line 40 def is_broadcast #self.to_s == "FF:FF:FF:FF:FF:FF" @val == 2**48-1 end |
#is_glob_uniq ⇒ Object
54 55 56 |
# File 'lib/mac_address_eui48/mac_address.rb', line 54 def is_glob_uniq !is_loc_admin end |
#is_loc_admin ⇒ Object
58 59 60 61 |
# File 'lib/mac_address_eui48/mac_address.rb', line 58 def is_loc_admin mask = 2 << (5*8) (mask & @val) !=0 end |
#is_multicast ⇒ Object
49 50 51 52 |
# File 'lib/mac_address_eui48/mac_address.rb', line 49 def is_multicast mask = 1 << (5*8) (mask & @val) !=0 end |
#is_unicast ⇒ Object
45 46 47 |
# File 'lib/mac_address_eui48/mac_address.rb', line 45 def is_unicast !is_multicast end |
#next ⇒ Object Also known as: succ
63 64 65 |
# File 'lib/mac_address_eui48/mac_address.rb', line 63 def next return MacAddress.new(((self.to_i) +1)%2**48) end |
#to_i ⇒ Object
28 29 30 |
# File 'lib/mac_address_eui48/mac_address.rb', line 28 def to_i @val end |
#to_s(sep = ':') ⇒ Object
36 37 38 |
# File 'lib/mac_address_eui48/mac_address.rb', line 36 def to_s(sep=':') MacAddressEui48::int_to_str_mac(@val,sep).upcase end |