Class: HWAddr
- Inherits:
-
Object
- Object
- HWAddr
- Defined in:
- lib/hwaddr.rb,
lib/hwaddr/database.rb
Overview
–
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
++
Direct Known Subclasses
Defined Under Namespace
Classes: Database
Class Method Summary collapse
Instance Method Summary collapse
- #=~(other) ⇒ Object
- #group? ⇒ Boolean
-
#initialize(value) ⇒ HWAddr
constructor
A new instance of HWAddr.
- #productor ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ HWAddr
Returns a new instance of HWAddr.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hwaddr.rb', line 18 def initialize (value) @string = value.is_a?(Integer) ? [value].pack('q').bytes.map { |b| "%02x" % b }.join(':') : value.to_s @string.tr! '-', ':' unless HWAddr.valid?(@string) raise ArgumentError, "#{value} isn't an usable MAC address" end end |
Class Method Details
.valid?(text) ⇒ Boolean
14 15 16 |
# File 'lib/hwaddr.rb', line 14 def self.valid? (text) text =~ /^\w\w:\w\w:\w\w(?::\w\w:\w\w:\w\w)?$/ end |
Instance Method Details
#=~(other) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/hwaddr.rb', line 30 def =~ (other) if group? to_s == other.to_s[0, 8] else to_s == other.to_s end end |
#group? ⇒ Boolean
38 39 40 |
# File 'lib/hwaddr.rb', line 38 def group? to_s.length == 8 end |
#productor ⇒ Object
42 43 44 |
# File 'lib/hwaddr.rb', line 42 def productor Database[to_s] end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/hwaddr.rb', line 46 def to_s @string end |