Class: Ouidb::MacRange
- Inherits:
-
Object
show all
- Defined in:
- lib/ouidb/mac_range.rb
Defined Under Namespace
Classes: Range24, Range36
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(addr, manufacturer) ⇒ MacRange
Returns a new instance of MacRange.
37
38
39
40
41
|
# File 'lib/ouidb/mac_range.rb', line 37
def initialize(addr, manufacturer)
raise NotImplementedError if self.class == MacRange
@addr = addr
@manufacturer = manufacturer
end
|
Instance Attribute Details
#manufacturer ⇒ Object
Returns the value of attribute manufacturer.
35
36
37
|
# File 'lib/ouidb/mac_range.rb', line 35
def manufacturer
@manufacturer
end
|
Class Method Details
.[](addr) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/ouidb/mac_range.rb', line 9
def [](addr)
if self == MacRange
Range36[addr] || Range24[addr]
else
all[str_to_int(addr)]
end
end
|
.all ⇒ Object
17
18
19
20
|
# File 'lib/ouidb/mac_range.rb', line 17
def all
raise NotImplementedError if self == MacRange
@all ||= {}
end
|
.find_or_create(addr, manufacturer = nil) ⇒ Object
22
23
24
25
26
|
# File 'lib/ouidb/mac_range.rb', line 22
def find_or_create(addr, manufacturer = nil)
raise NotImplementedError if self == MacRange
addr = str_to_int(addr)
all[addr] ||= new(addr, manufacturer)
end
|
.new_by_number(addr, manufacturer) ⇒ Object
28
29
30
31
32
|
# File 'lib/ouidb/mac_range.rb', line 28
def new_by_number(addr, manufacturer)
klass = addr < 0 ? Range36 : Range24
addr = addr.abs
klass.all[addr] = klass.new(addr, manufacturer)
end
|
.str_to_int(str) ⇒ Object
4
5
6
7
|
# File 'lib/ouidb/mac_range.rb', line 4
def str_to_int(str)
raise NotImplementedError if self == MacRange
str.gsub(/[^a-f\d]/i, '')[0...(self::SIZE / 4)].to_i(16)
end
|
Instance Method Details
#as_json ⇒ Object
48
49
50
|
# File 'lib/ouidb/mac_range.rb', line 48
def as_json
@addr
end
|
#inspect ⇒ Object
52
53
54
|
# File 'lib/ouidb/mac_range.rb', line 52
def inspect
"#<Range#{self.class::SIZE} #{to_s}>"
end
|
#to_s ⇒ Object
43
44
45
46
|
# File 'lib/ouidb/mac_range.rb', line 43
def to_s
size = self.class::SIZE
@addr.to_s(16).rjust(size / 4, '0').ljust(12, '0').chars.each_slice(2).map(&:join).join(':') << '/' << size.to_s << ' ' << manufacturer.to_s
end
|