diff --git a/game.rb b/game.rb index 016edb1..1af3526 100644 --- a/game.rb +++ b/game.rb @@ -1,20 +1,22 @@ require 'yaml' -name = "Zack Siri" -# first_letter_first_name = name.split(' ').first[0] -# last_letter_last_name = name.split(' ').last[0] +def data_loader(file_name) + @data ||= YAML.load(File.open(File.join(File.dirname(__FILE__), file_name))) +end -first_initial, last_initial = name.split(' ').map { |n| n[0] } +def name_initials_for(name) + name.split(' ').map { |n| n[0] } +end -puts first_initial -puts last_initial +def data(file, set) + data_loader(file + '.yaml')[set] +end -got_data = YAML.load(File.open(File.join(File.dirname(__FILE__), 'got_names.yaml'))) - -mens_first_name = got_data[:mens_first_name] -house_name = got_data[:house_name] - -puts "#{mens_first_name[first_initial.downcase.to_sym]} of house #{house_name[last_initial.downcase.to_sym]}" +def name_and_house + first_initial, last_initial = name_initials_for("Zack Siri") + [data('got_names', :mens_first_name)[first_initial.downcase.to_sym], + data('got_names', :house_name)[last_initial.downcase.to_sym]].join(' of house ') +end