Class: Ouidb::Importer
- Inherits:
-
Object
- Object
- Ouidb::Importer
- Defined in:
- lib/ouidb/importer.rb
Constant Summary collapse
- FIRST_LINE =
/\A (?<hex>([a-f\d]{2})(-([a-f\d]{2})){2}) \s+ \(hex\) \s+ (?<name>.+?)\s*\n\z/ix- SECOND_LINE =
/\A (?<start>[a-f\d]{6})(-(?<end>[a-f\d]{6}))? \s/ix
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io) ⇒ Importer
constructor
A new instance of Importer.
- #read ⇒ Object
- #read_block(lines) ⇒ Object
Constructor Details
#initialize(io) ⇒ Importer
Returns a new instance of Importer.
7 8 9 |
# File 'lib/ouidb/importer.rb', line 7 def initialize(io) @io = io end |
Class Method Details
.read(io) ⇒ Object
3 4 5 |
# File 'lib/ouidb/importer.rb', line 3 def self.read(io) new(io).read end |
Instance Method Details
#read ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ouidb/importer.rb', line 11 def read block = [] while (line = @io.gets) block << line if line.strip == '' read_block block block.clear end end end |
#read_block(lines) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ouidb/importer.rb', line 25 def read_block(lines) return unless (match = FIRST_LINE.match(lines.shift)) hex = match[:hex].delete('-') name = match[:name].gsub(/\s+/, ' ') return unless (match = SECOND_LINE.match(lines.shift)) hex << match[:start][0...3] if match[:end] # TODO addresses manufacturer = Manufacturer[name] manufacturer.ranges << (match[:end] ? MacRange::Range36 : MacRange::Range24).find_or_create(hex, manufacturer) end |