Skip to content

Instantly share code, notes, and snippets.

@jmmarco
Created October 18, 2016 02:56
Show Gist options
  • Save jmmarco/3f200d0da167f05f64174755cd256cb5 to your computer and use it in GitHub Desktop.
Save jmmarco/3f200d0da167f05f64174755cd256cb5 to your computer and use it in GitHub Desktop.
require 'csv'
module CarLoader
def self.get_cars_from_csv(filename)
# The result is being passed to the new dealership.
# I need to return some useful data from this method...
hashed_data = CSV.read(filename, {:headers => true, :header_converters => :symbol})
mapped_data = hashed_data.map {|row| row.to_hash}
cars = mapped_data.map! do |car|
Car.new(car)
end
cars
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment