Class: Deacon::MacGenerator

Inherits:
Generator show all
Defined in:
lib/deacon/mac_generator.rb

Constant Summary

Constants inherited from Generator

Generator::DEFAULT_DATA_DIR, Generator::GIVEN_FEMALE_NAMES_FILE, Generator::GIVEN_MALE_NAMES_FILE, Generator::RECORD_LENGTH_GIVEN, Generator::RECORD_LENGTH_SURNAME, Generator::SURNAMES_FILE

Instance Method Summary collapse

Methods inherited from Generator

#initialize

Constructor Details

This class inherits a constructor from Deacon::Generator

Instance Method Details

#generate(mac, female = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/deacon/mac_generator.rb', line 3

def generate(mac, female = false)
  return [] if mac.nil? || mac.empty?
  # B0 B1 B2 B3 B4 B5
  # SHRT0 SHRT1 SHRT2
  bytes = mac_to_bytes(mac)
  shorts = mac_to_shorts(mac)
  filename = (shorts[0] & 0x1) == 0 ? GIVEN_MALE_NAMES_FILE : GIVEN_FEMALE_NAMES_FILE
  firstname1 = find_name(bytes[2], data_file(filename), RECORD_LENGTH_GIVEN)
  firstname2 = find_name(bytes[3], data_file(filename), RECORD_LENGTH_GIVEN)
  surname1 = find_name(shorts[0], data_file(SURNAMES_FILE), RECORD_LENGTH_SURNAME)
  surname2 = find_name(shorts[2], data_file(SURNAMES_FILE), RECORD_LENGTH_SURNAME)
  [firstname2, firstname1, surname1, surname2]
end