Created
July 4, 2015 00:19
-
-
Save stevebooks/3a1d09c1c8bb5c0d07fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = File.new('input.txt','r') | |
@output = File.new('output.txt','w') | |
@last_names = [] | |
@first_names = [] | |
load_databases() | |
f.readlines.each do |line| | |
data = line.split(" ") #['HEADER', 'fkdasjdsk;jf'] | |
command = data[0] | |
extra = data[1] | |
if command == "HEADER" | |
handle_header(extra) | |
elsif command = "STRING" | |
handle_string(extra) | |
elsif command = "ENTER LAST NAME" | |
handle_last_name(extra) | |
end | |
end | |
def load_databases | |
load_first_names | |
load_last_names | |
end | |
def load_first_names | |
f = File.new('first_names.txt', 'r') | |
f.readlines.each do |line| | |
@first_names << line | |
end | |
end | |
def load_last_names | |
f = File.new('last_names.txt', 'r') | |
f.readlines.each do |line| | |
@last_names << line | |
end | |
end | |
def handle_header(extra) | |
write_to_file("Here is your header with data #{extra}") | |
end | |
def handle_last_name(extra) | |
#rand(1) #0 or 1 | |
total_size = @last_names.size | |
rand_index = rand(total_size) #this just gives a random number | |
random_last = @last_names[rand_index] | |
write_to_file(random_last) | |
end | |
def handle_string | |
end | |
def write_to_file(string) | |
@output.write(string) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment