Sha256: adb1e3b614c06b87f1ff38205a62dfde4cc194ac11a209ff595a32a7b9a7b451
Contents?: true
Size: 915 Bytes
Versions: 1
Compression:
Stored size: 915 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' 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foreman_name_generator-0.0.2 | lib/foreman_name_generator/generator.rb |