Class: HWAddr

Inherits:
Object
  • Object
show all
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

Database::Company::Range

Defined Under Namespace

Classes: Database

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (Boolean)


38
39
40
# File 'lib/hwaddr.rb', line 38

def group?
	to_s.length == 8
end

#productorObject



42
43
44
# File 'lib/hwaddr.rb', line 42

def productor
	Database[to_s]
end

#to_sObject



46
47
48
# File 'lib/hwaddr.rb', line 46

def to_s
	@string
end