class Deacon::Generator

Constants

DEFAULT_DATA_DIR
GIVEN_FEMALE_NAMES_FILE
GIVEN_MALE_NAMES_FILE
RECORD_LENGTH_GIVEN
RECORD_LENGTH_SURNAME
SURNAMES_FILE

Public Class Methods

new(data_dir = DEFAULT_DATA_DIR) click to toggle source
# File lib/deacon/generator.rb, line 10
def initialize(data_dir = DEFAULT_DATA_DIR)
  @data_dir = data_dir
end

Private Instance Methods

data_file(filename) click to toggle source
# File lib/deacon/generator.rb, line 16
def data_file(filename)
  File.join(@data_dir, filename)
end
find_name(index, filename, length) click to toggle source
# File lib/deacon/generator.rb, line 20
def find_name(index, filename, length)
  File.open(filename, 'r') do |f|
    f.seek(index * length)
    f.readline.chomp.strip
  end
rescue Exception => e
  raise "Error when seeking to #{index} in #{filename}: #{e}"
end
mac_to_bytes(mac) click to toggle source
# File lib/deacon/generator.rb, line 29
def mac_to_bytes(mac)
  mac.split(/[:-]/).collect{|x| x.to_i(16)}
end
mac_to_shorts(mac) click to toggle source
# File lib/deacon/generator.rb, line 33
def mac_to_shorts(mac)
  mac_to_bytes(mac).each_slice(2).collect { |a, b| (a << 8) + b }
end