Join Kevin Skoglund for an in-depth discussion in this video CSV to hashes, part of Ruby: Files, Formats, Templates.
- [Instructor] In this movie, I want to touch…on something that frequently comes up…when working with CSV files, and that is…how to take CSV values and turn them into hashes.…The problem is because the header row…of a CSV file contains all of the labels,…and it's not repeated again for each row after that,…it's just contained at the very top.…After that, we only have values.…But hashes are structured differently,…hashes use labels as keys for each value,…every time we have another hash, that is,…it's repeated in each hash.…
So what we need is a way to efficiently match up the labels…with the values in each row.…And Ruby gives us a handy way to do that.…The first thing I would suggest is…to take the header row that you've got,…and make it into suitable labels.…There's a number of different ways you could do that,…here's a simple one that just downcases everything…that's in the header item,…and replaces all the spaces with underscores.…You could also do more substitutions,…or you could turn it into a symbol if you wanted,…
- File system basics
- Writing to and reading from files
- Renaming, deleting, and copying files
- Creating and editing directories
- Working with common data formats
- ERB templating
Skill Level Beginner
Ruby on Rails 5 Essential Trainingwith Kevin Skoglund10h 21m Beginner
1. The File System
2. Work with Files
3. Work with Directories
4. Common Data Formats
5. ERB Templating
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.