Sha256: 890c74a2554bfcccf458df440d588c67d5f7c21c995c350c462bc5df590713d7

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

module Deacon
  class Generator
    DEFAULT_DATA_DIR = File.expand_path('../../../data', __FILE__)
    GIVEN_MALE_NAMES_FILE = 'gmnames.txt'
    GIVEN_FEMALE_NAMES_FILE = 'gfnames.txt'
    SURNAMES_FILE = 'srnames.txt'
    RECORD_LENGTH_GIVEN = 6
    RECORD_LENGTH_SURNAME = 9

    def initialize(data_dir = DEFAULT_DATA_DIR)
      @data_dir = data_dir
    end

    private

    def data_file(filename)
      File.join(@data_dir, filename)
    end

    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

    def mac_to_bytes(mac)
      mac.split(/[:-]/).collect{|x| x.to_i(16)}
    end

    def mac_to_shorts(mac)
      mac_to_bytes(mac).each_slice(2).collect { |a, b| (a << 8) + b }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deacon-1.0.0 lib/deacon/generator.rb
deacon-0.0.3 lib/deacon/generator.rb