Is this what you are looking for?
students.each do |s|
puts s[1]['first_name'].first + "," + "Earliest Start Date:" + s[1]['start_dates'].sort_by(&:to_date).first
end
Above code will output
Mista,Earliest Start Date: Mon, 19 Aug 2013
Question
I am processing a CSV, and the resulting hash I am creating looks like this...
["709267", {"first_name"=>["Mista", "Mista", "Mista", "Mista"],
"last_name"=>["Ainsley", "Ainsley", "Ainsley", "Ainsley"],
"start_dates"=>[Mon, 19 Aug 2013, Mon, 19 Aug 2013, Mon, 19 Aug 2013, Mon, 19 Aug 2013],
"end_dates"=>["12/14/2013", "12/14/2013", "12/14/2013", "12/14/2013"],
"last_attend_dates"=>[nil, "8/29/2013", nil, nil],
"final_grades"=>["B", "W", "A", "D"]}]
So now I want to display the results of this. Right now I'm just doing it in the console. With...
students.each do |s|
puts s.inspect
end
I trying to make this look a little more orderly by calling each peice of information by its hash name. So would like to do something like...
students.each do |s|
puts s['first_name'].inspect + "," + "Earliest Start Date:" + s[start_date].min.inspectt
end
But I'm not having any luck. What is the correct syntax I should be using?
Solution
Is this what you are looking for?
students.each do |s|
puts s[1]['first_name'].first + "," + "Earliest Start Date:" + s[1]['start_dates'].sort_by(&:to_date).first
end
Above code will output
Mista,Earliest Start Date: Mon, 19 Aug 2013