macker 0.1.1 → 0.1.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.
@@ -101,7 +101,7 @@ module Macker
101
101
  # @return [Address] MAC address with data
102
102
  def generate(opts = {})
103
103
  expire! if config.auto_expiration
104
- return generate_by_iso_code(opts.delete(:iso_code), opts) if opts[:iso_code]
104
+ return generate_by_iso_code(opts.delete(:iso_code).upcase, opts) if opts[:iso_code]
105
105
  vendor = opts.delete(:vendor)
106
106
  case vendor
107
107
  when nil, false
@@ -259,26 +259,10 @@ module Macker
259
259
  address = vendor.strip.delete("\t").split("\n")
260
260
  iso_code = address[-1].strip
261
261
  next unless @prefix_table[mac_prefix].nil?
262
- @prefix_table[mac_prefix] = { name: base16_fields[-1]
263
- .strip
264
- .gsub(/\s+/, ' ')
265
- .split(/ |\_|\-/)
266
- .map(&:capitalize)
267
- .join(' '),
268
- address: address[2..-1].map { |a| a
269
- .strip
270
- .gsub(/\s+/, ' ')
271
- .gsub(/,(?![\s])/, ', ')
272
- .gsub(/\,+$/, '')
273
- .split(/ |\_|\-/)
274
- .map(&:capitalize)
275
- .join(' ')
276
- },
277
- iso_code: iso_code.length == 2 ? iso_code.upcase : nil
278
- }
262
+ @prefix_table[mac_prefix] = add_vendor(base16_fields, address, iso_code)
279
263
  end
280
- @iso_code_table = @prefix_table.each_with_object({}) { |(key, value), out| (out[value[:iso_code]] ||= []) << value.merge(prefix: key) }
281
- @vendor_table = @prefix_table.each_with_object({}) { |(key, value), out| (out[value[:name]] ||= []) << value.merge(prefix: key) }
264
+ @iso_code_table = hash_invert(@prefix_table, :iso_code)
265
+ @vendor_table = hash_invert(@prefix_table, :name)
282
266
  @prefix_table
283
267
  end
284
268
 
@@ -392,4 +376,39 @@ module Macker
392
376
  File.join(File.dirname(file_path),
393
377
  File.basename(file_path).gsub(/_\d+\.txt/, "_#{Time.now.to_i}.txt")))
394
378
  end
379
+
380
+ private
381
+
382
+ # Invert hash with given key to use.
383
+ # @param hash [Hash] source hash
384
+ # @param new_key [Symbol] key for the inverted hash
385
+ # @return [Hash] inverted hash
386
+ def hash_invert(hash, new_key)
387
+ hash.each_with_object({}) { |(key, value), out| (out[value[new_key]] ||= []) << value.merge(prefix: key) }
388
+ end
389
+
390
+ # Perform vendor hash
391
+ # @param base16_fields [Array] preifx and name field line
392
+ # @param address [Array] address lines
393
+ # @param iso_code [String] last line, iso code
394
+ # @return [Hash] new vendor
395
+ def add_vendor(base16_fields, address, iso_code)
396
+ { name: base16_fields[-1]
397
+ .strip
398
+ .gsub(/\s+/, ' ')
399
+ .split(/ |\_|\-/)
400
+ .map(&:capitalize)
401
+ .join(' '),
402
+ address: address[2..-1].map { |a| a
403
+ .strip
404
+ .gsub(/\s+/, ' ')
405
+ .gsub(/,(?![\s])/, ', ')
406
+ .gsub(/\,+$/, '')
407
+ .split(/ |\_|\-/)
408
+ .map(&:capitalize)
409
+ .join(' ')
410
+ },
411
+ iso_code: iso_code.length == 2 ? iso_code.upcase : nil
412
+ }
413
+ end
395
414
  end
@@ -30,7 +30,7 @@ module Macker
30
30
  else
31
31
  raise(InvalidAddress, "Incompatible type for address initialization: #{mac.class}")
32
32
  end
33
- raise(InvalidAddress, "Invalid MAC address: #{self.to_s}") unless valid?
33
+ raise(InvalidAddress, "Invalid MAC address: #{self}") unless valid?
34
34
  @name ||= opts.fetch(:name, nil)
35
35
  @address ||= opts.fetch(:address, nil)
36
36
  @iso_code ||= opts.fetch(:iso_code, nil)
@@ -3,5 +3,5 @@
3
3
  # Macker namespace
4
4
  module Macker
5
5
  # Macker version
6
- VERSION = '0.1.1'.freeze
6
+ VERSION = '0.1.2'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Egon Zemmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -79,7 +79,7 @@ files:
79
79
  - LICENSE.txt
80
80
  - README.md
81
81
  - Rakefile
82
- - data/oui_1499079803.txt
82
+ - data/oui_1499162218.txt
83
83
  - lib/macker.rb
84
84
  - lib/macker/address.rb
85
85
  - lib/macker/config.rb