That worked great!  Thanks for clearing up the idiomatic usage.  I have 
not quite wrapped my head around it yet, but look forward to learning 
more.

For the record, here's the working code:

#TODO move require and plant class to helper
#DONE do not use eval if possible -- Possible thanks to Matt Jones on 
ruby-forum.com
require 'FasterCSV'

class Plant

  def self.grow (model, filename, headers = true)
      Kernel.const_get(model).delete_all
      table = FasterCSV.table(filename, {
         :headers => headers,
         :header_converters => :symbol,
         :col_sep => "\t" # need the double quotes
         })
      table.each do |row|
        yield(row)
      end
  end

end

Plant.grow("Business", File.join(File.dirname(__FILE__), 'vendor.db')) 
do |row|
  Business.create(
    :address         => row[:vendoraddress],
    :city            => row[:vendorcity],
    :domain_name     => row[:vendordomainname].to_s.gsub(/^(www.)+([^ 
]*).*/, '\2'),
    :email_general   => row[:vendoremail],
    :fax             => row[:faxnumber],
    :iadm_member     => row[:iadm],
    :name            => row[:vendorname],
    :old_vendorid    => row[:vendorid],
    :phone           => row[:vendorphone],
    :sales_tax_rate  => row[:vendorsalestax],
    :zip_code        => row[:vendorzipcode]
  )
end
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to