How do i strip CSV's "Cell" designation when migrating to YAML

L

lfast1234

In some magical way ruby is maintaining the 'Cell' designation from my .csv data as I transform it into a yaml file. I don't want that. Any idea how i get rid of it?

Source:
location,server_env (heading line)
van,cpci (content line)
....

Desired output
fleetmanifest:
location: van
server_env: cpci

Actual Output
fleetmanifest:

? !str:CSV::Cell location
: !str:CSV::Cell van

? !str:CSV::Cell server_env
: !str:CSV::Cell cpci1

Current Transformation code
fleetH = {}
myCSV.each { |row|
# Find the header row based on 0th column
if headerrow
hd_row = row
end
if datarow
hd_row.zip(row).each { |k,v|
fleetH[k] = v
}
break
end
}
puts fleetH.class => Hash
puts fleetH.to_yaml => produces the ? !str:CSV::Cell gibberish!
 
L

lfast1234

RESOLVED (as I was drifting off to sleep last night)
The magic is in each element of the CSV record.

puts row[0].class => CSV::Cell

so, replacing this line fixes the problem
bad: fleetH[k] = v
good: fleetH[k.to_s] = v.to_s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top