Class: Dot11::MACAddress
- Inherits:
-
Object
- Object
- Dot11::MACAddress
- Includes:
- Comparable
- Defined in:
- lib/dot11/macaddress.rb
Instance Attribute Summary collapse
-
#prefix_length ⇒ Object
Returns the value of attribute prefix_length.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](*index) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(address) ⇒ MACAddress
constructor
A new instance of MACAddress.
- #inspect ⇒ Object
- #to_arr ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(address) ⇒ MACAddress
Returns a new instance of MACAddress.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dot11/macaddress.rb', line 7 def initialize(address) if address.kind_of?(Integer) @address = [address].pack("Q").unpack("C8")[0, 6].reverse elsif address.kind_of?(String) && address =~ /^(.*?)(?:\/(.*))?$/ @prefix_length = $2.to_i @address = $1.split(":").map {|octet| octet.to_i(16)} elsif address.kind_of?(Array) @address = address end end |
Instance Attribute Details
#prefix_length ⇒ Object
Returns the value of attribute prefix_length.
5 6 7 |
# File 'lib/dot11/macaddress.rb', line 5 def prefix_length @prefix_length end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/dot11/macaddress.rb', line 43 def ==(other) eql?(other) end |
#[](*index) ⇒ Object
35 36 37 |
# File 'lib/dot11/macaddress.rb', line 35 def [](*index) @address[*index] end |
#eql?(other) ⇒ Boolean
39 40 41 |
# File 'lib/dot11/macaddress.rb', line 39 def eql?(other) to_i == other.to_i end |
#hash ⇒ Object
47 48 49 |
# File 'lib/dot11/macaddress.rb', line 47 def hash to_i.hash end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/dot11/macaddress.rb', line 27 def inspect to_s end |
#to_arr ⇒ Object
31 32 33 |
# File 'lib/dot11/macaddress.rb', line 31 def to_arr @address end |
#to_i ⇒ Object
19 20 21 |
# File 'lib/dot11/macaddress.rb', line 19 def to_i ("\x00\x00" + @address.pack("C6")).reverse.unpack("Q")[0] end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/dot11/macaddress.rb', line 23 def to_s @address.map{|byte| "%02x" % byte}.join(":") + (@prefix_length == 0 ? "" : "/#{@prefix_length}") end |