hwaddr 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/hwaddr.gemspec +1 -1
  2. data/lib/hwaddr.rb +17 -2
  3. metadata +1 -1
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new {|s|
2
2
  s.name = 'hwaddr'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.author = 'meh.'
5
5
  s.email = 'meh@paranoici.org'
6
6
  s.homepage = 'http://github.com/meh/ruby-hwaddr'
@@ -16,9 +16,24 @@ class HWAddr
16
16
  end
17
17
 
18
18
  def initialize (value)
19
- @string = value.is_a?(Integer) ?
20
- [value].pack('q').bytes.map { |b| "%02x" % b }.join(':') :
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hwaddr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: