title: Ruby CSV parsing string with quotes
body: <p>I'm having an issue when trying to import CSV data into Active Record.  My CSV was created in google sheets, then downloaded as a CSV.  Some entries in the CSV have quotes around certain words (ie. "Logic").  Here is the script that I am writing to import this data:</p>
  
  <pre><code>    require 'csv'
  
  homeDir = Dir.home
  file = File.join(homeDir, "trdata-1.csv")
  header = []
  
   CSV.foreach(file, headers: true, :quote_char =&gt; '"', encoding: "UTF-8") do |row|
  
    #possible cause
    possible_cause = PossibleCause.find_by_description(row["Possible Cause"]) || PossibleCause.new.tap do |possible_cause|
      # find the possible cause by its description, else make a new one.
           possible_cause.description = row.to_s.slice(row["Possible Cause"])
      #
      puts possible_cause.description
    end
  
    #troubleshooting paths
    troubleshooting_path = TroubleshootingPath.find_by_description(row["Troubelshooting Path"]) || TroubleshootingPath.new.tap do |troubleshooting_path|
      # Find the troubleshooting path by its description, or else make a new one.
      troubleshooting_path.description = row.to_s.slice(row["Troubleshooting Path"])
  
      puts possible_cause.description
    end
    possible_cause.troubleshooting_paths &lt;&lt; troubleshooting_path
  
    #action steps
    action_step = ActionStep.find_by_description(row["Action Step"]) || ActionStep.new.tap do |action_step|
      action_step.description = row.to_s.slice(row["Action Step"])
      puts possible_cause.description
    end
    troubleshooting_path.action_steps &lt;&lt; action_step
  
    possible_cause.save!
  end
  </code></pre>
  
  <p>I execute the script in the rails console:</p>
  
  <pre><code>load 'lib/scripts/troubleshooting.rb'
  </code></pre>
  
  <p>Most of the data loads just fine, and is properly saving into the DB the way I want it to.</p>
  
  <p>Here is a sample of the data I'm trying to import with the header:</p>
  
  <pre><code>Frequency metric,Problem Symptom Title,Problem Symptom Desciption,Icon,Possible Cause,Troubleshooting Path,Action Step
  2,Spindle issues,"When its time to run the job, the spindle doesn't run smoothly or doesn't work at all.",spindle_issue.png,Toggle switch on power supply is in the wrong position,Check toggle switch,"If using PWM, make sure it's set to ""Logic"""
  </code></pre>
  
  <p>This line will blow up the script. The word "Logic" is enclosed in quotes.  I've tried taking the quotes out, and it will run just fine, so its definitely the quotes that are causing the problem.  I'm at a loss for why this would be happening and googling around hasn't pulled up many results.</p>