Ruby CSV Generator Tutorial

This coding exercise will walk through how you can build a CSV file generator that will allow you to export data that can be viewed in applications such as Microsoft Excel.

Sign Up to Start Your Own Code Camp

large

View Screencast

Summary

Build a CSV File generator in Ruby.

Exercise File

Code File

Exercise Description

This coding exercise examines how to build a method that takes in a collection of data and generates a CSV file that can be viewed in applications such as Microsoft Excel.

Example Data Input

headers = %w{Name Title Email}

crm_data = [
  ["Darth Vader", "CEO", "betterthan@theforce.com"],
  ["Luke Skywalker", "Dev", "daddy@issues.com"],
  ["Kylo Ren", "COO", "daddy2@issues.com"],
]

Generated File

large

Real World Usage

Being able to generate CSV files is a common feature I'm asked to build in a wide variety of applications. Many users need the ability to export data and CSV is one of the most popular methods for reports because they can be opened in Excel.

Solution

Can be found on the solutions branch on github.

Jordan Hudgens

Jordan Hudgens

I've been a software engineer for the past decade and have traveled the world building applications and training individuals on a wide variety of topics.


View All Posts