Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.