Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 790745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:43:43+00:00 2026-05-14T21:43:43+00:00

I am dealing with a csv file that has some customer information (email, name,

  • 0

I am dealing with a csv file that has some customer information (email, name, address, amount, [shopping_list: item 1, item 2]).

I would like work with the data and produce some labels for printing… as well as to gather some extra information (total amounts, total items 1…)

My main concern is to find the appropriate structure to store the data in ruby for future manipulation. For now I have thought about the following possibilities:

  1. multidimensional arrays: pretty simple to build, but pretty hard to access the data in a beautiful ruby way.
  2. hashes: having the email as key, and storing the information in different hashes (one hash for name, another hash for address, another hash for shopping list…)
  3. (getting the cvs data in to a Database and working with the data from ruby??)

I would really appreciate your advice and guidance!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:43:44+00:00Added an answer on May 14, 2026 at 9:43 pm

    Once you have more than a couple pieces of information that you need to group together, it’s time to consider moving from a generic hash/array to something more specialized. A good candidate for what you’ve described is Ruby’s struct module:

    Customer = Struct.new(:email, :name, :address) # etc.
    
    bill = Customer.new('bill@asdf.com', 'Bill Foo', '123 Bar St.')
    
    puts "#{bill.name} lives at #{bill.address} and can be reached at #{bill.email}"
    

    Output:

    Bill Foo lives at 123 Bar St. and can be reached at bill@asdf.com

    Struct#new simply creates a class with an attr_accessor for each symbol you pass in. Well, it actually creates a bit more than that, but for starters, that’s all you need to worry about.

    Once you’ve got the data from each row packed into an object of some sort (whether it’s a struct or a class of your own), then you can worry about how to store those objects.

    • A hash will be ideal for random access by a given key (perhaps the customer’s name or other unique ID)
    • A one-dimensional array works fine for iterating over the entire set of customers in the same order they were inserted
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm dealing with a csv file that has missing values. What I want
I'm dealing with a program that reads in items from a .csv file, and
I'm dealing with a large amount of data that has both values and times
When dealing with a single file, I'm used to: /blah do some work n
I am reading in a csv file and dealing with each line as a
I have csv file with a line that looks something like this: ,,,,,,,,,, That's
Possible Duplicate: Dealing with commas in a CSV file We are exporting a bulk
I have a class that outputs a simple report file. It reads some record
I am dealing with a CSV file similar to this one foo; val1; position1
Dealing with some legacy code and in trying to get a poorly designed database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.