Ruby has a standard library for parsing CSV files. All we need to do is open a csv file, read it and parse the file using CSV parser. So, here is my CSV file.
repository_name,repository_language,repository_url,total_number_of_forks
bootstrap,JavaScript,https://github.com/twitter/bootstrap,14037
bootstrap,JavaScript,https://github.com//bootstrap,13700
Spoon-Knife,null,https://github.com/octocat/Spoon-Knife,13316
Spoon-Knife,null,https://github.com//Spoon-Knife,12831
homebrew,Ruby,https://github.com/mxcl/homebrew,5758
I will use CSV library. So, we need to add this
require 'csv'
Now, we need to read and parse the file and by specify the headers exist, the parse will use the first row as names for each value.
require 'csv'
csv_text = File.read("info.csv")
csv = CSV.parse(csv_text, :headers => true)
And now we just need to loop through each record for printing output in terminal.
require 'csv'
csv_text = File.read("info.csv")
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
puts
"Name: #{row['repository_name']} -
Language: #{row['epository_language']} -
URL: #{row['repository_url']} -
Total Number of Forks: #{row['total_number_of_forks']}"
end