hwaddr 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/hwaddr.gemspec +1 -1
- data/lib/hwaddr.rb +17 -2
- metadata +1 -1
data/hwaddr.gemspec
CHANGED
data/lib/hwaddr.rb
CHANGED
@@ -16,9 +16,24 @@ class HWAddr
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize (value)
|
19
|
-
@string = value.is_a?(
|
20
|
-
|
19
|
+
@string = if value.is_a?(Array)
|
20
|
+
if value.length > 6
|
21
|
+
raise ArgumentError, "#{value.inspect} is too big for a MAC address"
|
22
|
+
end
|
23
|
+
|
24
|
+
value.map { |b| "%02x" % b }.join(':')
|
25
|
+
elsif value.is_a?(Integer)
|
26
|
+
array = []
|
27
|
+
|
28
|
+
6.times {
|
29
|
+
array << value & 0xff
|
30
|
+
value >>= 8
|
31
|
+
}
|
32
|
+
|
33
|
+
array.map { |b| "%02x" % b }.join(':')
|
34
|
+
else
|
21
35
|
value.to_s
|
36
|
+
end
|
22
37
|
|
23
38
|
@string.tr! '-', ':'
|
24
39
|
|