ruby on rails - SFTP Download CSV File to memory -


i have following code:

sftp = net::sftp.start('ftp.test.com','luigi', :password => 'pass_code')  data = sftp.download!("luigi/list.csv") 

this converts data string so:

2015,this is, 1 value, test, 9820\r\n4003, 1 value, test, 0393 

i want separate each row in csv file array value. attempt:

data.split(/\r\n/) data.each |record|     record.split(/,/) end 

this works cases, gets screwed first row in csv file since additional comma creates value in array:

2015,this is, 1 value, test, 9820 

because there additional comma not escaped, array looks this:

["2015","this is", "one value","test","9820"]

i want above this:

["2015","this is, 1 value","test","9820"]

or

["2015","this 1 value","test","9820"]

is possible, using sftp, download file memory (not locally, have store it) , loop through each row in file without additional commas throwing things off? seems root of issue can't like:

csv.foreach(...) |csv_row|

but instead have use sftp.download! returns 1 string, not array of "csv rows".


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -