title: Parse CSV Data with Ruby
body: <p>I am trying to return a specific cell value based on two criteria.</p>
  
  <p>The logic:</p>
  
  <p><code>If ClientID = 1 and BranchID = 1, puts SurveyID</code></p>
  
  <p>Using Ruby 1.9.3, I want to basically look through an excel file and for two specific values located within the <code>ClientID</code> and <code>BranchID</code> column, return the corresponding value in the <code>SurveyID</code> column.</p>
  
  <p>This is what I have so far, which I found during my online searches. It seemed promising, but no luck:</p>
  
  <pre><code>require 'csv'
  
  # Load file
  csv_fname = 'FS_Email_Test.csv'
  
  # Key is the column to check, value is what to match
  search_criteria = { 'ClientID' =&gt; '1', 
                     'BranchID' =&gt; '1' }
  
  options = { :headers      =&gt;  :first_row,
              :converters   =&gt;  [ :numeric ] }
  
  # Save `matches` and a copy of the `headers`
  matches = nil
  headers = nil
  
  # Iterate through the `csv` file and locate where
  # data matches the options.
  
  CSV.open( csv_fname, "r", options ) do |csv|
    matches = csv.find_all do |row|
      match = true
      search_criteria.keys.each do |key|
        match = match &amp;&amp; ( row[key] == search_criteria[key] )
      end
      match
    end
    headers = csv.headers
  end
  
  # Once matches are found, we print the results
  # for a specific row. The row `row[8]` is
  # tied specifically to a notes field.
  
  matches.each do |row|
    row = row[1]
    puts row
  end
  </code></pre>
  
  <p>I know the last bit of code following <code>matches.each do |row|</code> is invalid, but I left it in in hopes that it will make sense to someone else.</p>
  
  <p>How can I write <code>puts surveyID if ClientID == 1 &amp; BranchID == 1</code>?</p>