How to Build a CSV File Generator in Pure Ruby

2
1173

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.

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", "[email protected]"],
  ["Luke Skywalker", "Dev", "[email protected]"],
  ["Kylo Ren", "COO", "[email protected]"],
]

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.

2 COMMENTS

  1. I added a new line to the test file. I didn’t see that original file so I just copied in what was generated then deleted the generated file.

LEAVE A REPLY

Please enter your comment!
Please enter your name here