Last active
August 29, 2015 14:05
-
-
Save pumpkincouture/b171bb448095da80a13b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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