Sha256: 8ed72151e249d0cd85ada1eb69b80409010b968622c1250605bdb2b9572dadf5

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

module ForemanNameGenerator
  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'

    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)
      File.open(filename, 'r') do |f|
        f.seek(index * 15)
        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

1 entries across 1 versions & 1 rubygems

Version Path
foreman_name_generator-0.0.1 lib/foreman_name_generator/generator.rb