Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Last active August 29, 2015 14:05
Show Gist options
  • Save pumpkincouture/b171bb448095da80a13b to your computer and use it in GitHub Desktop.
Save pumpkincouture/b171bb448095da80a13b to your computer and use it in GitHub Desktop.
#code in txt file
FIRST_NAME,LAST_NAME,EMAIL
Albus,Dumbledore,<[email protected]>
Harry,Potter,<[email protected]>
Ron,Weasley,<[email protected]>
Hermione,Granger,<[email protected]>
Draco,Malfoy,<[email protected]>
#code in Secret Santa class
require 'csv'
class SecretSanta
attr_reader :santa_list
def open
f = File.open("/Users/administrator/Desktop/Personal/8th_Light/Apprenticeship/secret_santa/lib/example.csv")
csv_data = CSV.read '/Users/administrator/Desktop/Personal/8th_Light/Apprenticeship/secret_santa/lib/example.csv'
headers = csv_data.shift.map {|i| i.to_s }
string_data = csv_data.map {|row| row.map {|cell| cell.to_s} }
hash_names = string_data.map {|row| Hash[*headers.zip(row).flatten] }
hash_names
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment