title: Changing header names in a ruby hash
body: <p>I have some code which imports a CSV file into a database, but having some trouble with in place changes because of attribute names not matching up.</p>
  
  <p>The headers in the CSV file look like this:</p>
  
  <pre><code>Date,Visitors
  02/01/2014,3483
  01/01/2014,13636
  </code></pre>
  
  <p>My database has the same fields but they don't use capital letters at the beginning:</p>
  
  <pre><code>date
  visitors
  </code></pre>
  
  <p>When I import the file it works great but I have to manually edit the values in the file and change the headers to lowercase so they match on the import. Here is my import method in my model:</p>
  
  <pre><code>def self.import(file)
      CSV.foreach(file.path, headers: true) do |row|
        entry = find_by(date: Date.parse(row["Date"])) || new
        entry.update row.to_hash
        entry.save!
      end
  end
  </code></pre>
  
  <p>I'm wondering if there is an easier way to make my method change the header names in the hash before it gets into the database and fails, so I can remove some of the manual intervention of editing the file myself.</p>
  
  <p>I've tried looking into the .slice method but they look as though it's only for selecting specific attributes, I've found some pure ruby using the .map to replace these but wondering if rails includes something more suited to this task?</p>
  
  <p>Thanks for reading!</p>