Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2008, 08:34 PM   PM User | #1
ibanez270dx
New Coder

 
Join Date: Aug 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ibanez270dx is an unknown quantity at this point
Ruby CSV Parsing

Hello,
I have a Ruby controller that parses a POSTed CSV file and it works great... the problem is that I want to discard the first line. I am not sure how to do this... My code looks like this:

Code:
require 'csv'

class ImportController < ApplicationController

   def import 
     currenttime = DateTime.now
     @parsed_file=CSV::Reader.parse(params[:dump][:file])
     n=0
     @parsed_file.each  do |row| 
     c=Import.new
	c.prov_info_fac=row[0]
	c.prov_info_bac=row[4]
	c.prov_info_datatype=row[2]

	c.prov_service_name=row[1]
	c.prov_service_number=row[3]
	c.prov_service_provider=row[5]

	c.prov_charges_tot_access=row[7]
	c.prov_charges_tot_airtime=row[8]
	c.prov_charges_tot_kb=row[9]
	c.prov_charges_tot_messaging=row[10]
	c.prov_charges_tot_features=row[13]
	c.prov_charges_tot_equipment=row[26]
	c.prov_charges_tot_longdistance=row[27]
	c.prov_charges_tot_roaming=row[31]
	c.prov_charges_tot_misc=row[39]
	c.prov_charges_tot_other=row[42]
	c.prov_charges_tot_taxesfees=row[43]

	c.prov_charges_messaging_sms=row[11]
	c.prov_charges_messaging_mms=row[12]
	c.prov_charges_feat_basicvoice=row[14]
	c.prov_charges_feat_voicemail=row[15]
	c.prov_charges_feat_wos=row[16]
	c.prov_charges_feat_aod=row[17]
	c.prov_charges_feat_intnl=row[18]
	c.prov_charges_feat_mou=row[19]
	c.prov_charges_feat_data=row[20]
	c.prov_charges_feat_vidshare=row[21]
	c.prov_charges_feat_wifi=row[22]
	c.prov_charges_feat_messaging=row[23]
	c.prov_charges_feat_otherfees=row[24]
	c.prov_charges_feat_otherfeat=row[25]
	c.prov_charges_ld_local=row[28]
	c.prov_charges_ld_intnl=row[29]
	c.prov_charges_ld_directory=row[30]
	c.prov_charges_roam_airtime=row[32]
	c.prov_charges_roam_kb=row[33]
	c.prov_charges_roam_surcharges=row[34]
	c.prov_charges_roam_ld=row[35]
	c.prov_charges_roam_intnl=row[36]
	c.prov_charges_roam_intnl_ld=row[37]
	c.prov_charges_roam_taxes=row[38]
	c.prov_charges_misc_voice=row[40]
	c.prov_charges_misc_data=row[41]
	c.prov_updated_date=currenttime

     if c.save
        n=n+1
        GC.start if n%50==0
     end
     flash.now[:message] = 'CSV Import Successful'
   end
   
end
Thanks for you help, it is appreciated!

- Jeff
ibanez270dx is offline   Reply With Quote
Old 01-17-2008, 01:54 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
Code:
require 'csv'

class ImportController < ApplicationController

   def import 
     currenttime = DateTime.now
     @parsed_file=CSV::Reader.parse(params[:dump][:file])
     @parsed_file.shift
     n=0
     @parsed_file.each  do |row| 
     c=Import.new
	c.prov_info_fac=row[0]
	c.prov_info_bac=row[4]
	c.prov_info_datatype=row[2]

	c.prov_service_name=row[1]
	c.prov_service_number=row[3]
	c.prov_service_provider=row[5]

	c.prov_charges_tot_access=row[7]
	c.prov_charges_tot_airtime=row[8]
	c.prov_charges_tot_kb=row[9]
	c.prov_charges_tot_messaging=row[10]
	c.prov_charges_tot_features=row[13]
	c.prov_charges_tot_equipment=row[26]
	c.prov_charges_tot_longdistance=row[27]
	c.prov_charges_tot_roaming=row[31]
	c.prov_charges_tot_misc=row[39]
	c.prov_charges_tot_other=row[42]
	c.prov_charges_tot_taxesfees=row[43]

	c.prov_charges_messaging_sms=row[11]
	c.prov_charges_messaging_mms=row[12]
	c.prov_charges_feat_basicvoice=row[14]
	c.prov_charges_feat_voicemail=row[15]
	c.prov_charges_feat_wos=row[16]
	c.prov_charges_feat_aod=row[17]
	c.prov_charges_feat_intnl=row[18]
	c.prov_charges_feat_mou=row[19]
	c.prov_charges_feat_data=row[20]
	c.prov_charges_feat_vidshare=row[21]
	c.prov_charges_feat_wifi=row[22]
	c.prov_charges_feat_messaging=row[23]
	c.prov_charges_feat_otherfees=row[24]
	c.prov_charges_feat_otherfeat=row[25]
	c.prov_charges_ld_local=row[28]
	c.prov_charges_ld_intnl=row[29]
	c.prov_charges_ld_directory=row[30]
	c.prov_charges_roam_airtime=row[32]
	c.prov_charges_roam_kb=row[33]
	c.prov_charges_roam_surcharges=row[34]
	c.prov_charges_roam_ld=row[35]
	c.prov_charges_roam_intnl=row[36]
	c.prov_charges_roam_intnl_ld=row[37]
	c.prov_charges_roam_taxes=row[38]
	c.prov_charges_misc_voice=row[40]
	c.prov_charges_misc_data=row[41]
	c.prov_updated_date=currenttime

     if c.save
        n=n+1
        GC.start if n%50==0
     end
     flash.now[:message] = 'CSV Import Successful'
   end
   
end
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
shyam is offline   Reply With Quote
Old 01-18-2008, 06:21 PM   PM User | #3
ibanez270dx
New Coder

 
Join Date: Aug 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ibanez270dx is an unknown quantity at this point
thank you, it works perfectly now!
ibanez270dx is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:40 AM.


Advertisement
Log in to turn off these ads.