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

  • SEARCH
  • Home
  • 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 8858513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:50:47+00:00 2026-06-14T14:50:47+00:00

I have a csv which I would like to process instances of a row[report]

  • 0

I have a csv which I would like to process instances of a row[report] based on the input of another row[number].

Report,Number,Name,Date
INC AMT %,12345678,ACME INC,10/30/2012
INC AMT %,12345678,ACME INC,10/31/2012
OUT AMT %,12345678,ACME INC,10/31/2012
# shortened for brevity

My code block looks like this:

require 'CSV'

module AlertHash
  @alert_hash = {}
  CSV.foreach("alerts.csv") do |row|
    report, number = row
    next if number == "Number"
    @alert_hash[number] = report
  end

  def self.report(number)
  @alert_hash[number]
  end

end

puts "Alert: " + AlertHash.report("12345678")
# OUTPUT => Alert: OUT AMT %
# DESIRED OUTPUT => Alert: INC AMT %, OUT AMT % 

I’ve been able to process the last [report]stack of each number. However, my desired output would be to capture ALL reports for a given row[number]. Can someone give me some pointers on how this could be done? Maybe I’m approaching this problem the wrong way.

  • 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-06-14T14:50:49+00:00Added an answer on June 14, 2026 at 2:50 pm

    This statement:

    @alert_hash[number] = report
    

    will overwrite any previous value for any given number index, so you only retain the last one. That’s why you get the OUT value only. If you want to collect all lines for a given number, use an array:

    @alert_hash[number] ||= [] # initialize array if required
    @alert_hash[number] << report # add value
    

    and then concatenate them in your report method:

    @alert_hash[number].join(", ")
    

    This will give you:

    Alert: INC AMT %, INC AMT %, OUT AMT %
    

    Not sure what you’re actually trying to achieve, but this explains your code’s current behaviour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. So I have a collection of csv files which I would like
I have a csv file encoded in UCS-2 Little Endian which I would like
Little Background: I have csv file which has lots of rows and each row
I have an app/tool which reads from a CSV file and writes to another,
I have big .csv file. I would like to filter that file into a
I have a CSV file which uses a highly customized format. Here, each number
I have a csv data set containing a date field which my may or
I have a csv file which may have empty or blank rows. I want
I have some .csv files which I'm using as part of a test bench.
I have a CSV file which has the following format: id,case1,case2,case3 Here is a

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.