Gregory and James
Thank you so much for your precise and speedy replies, I am thankful both
for your suggestions and for your effort in building these libraries.
With FasterCSV I espescially like the ability to set
:headers => "my;custom;header"
and with ruport it seems very covenient to add some simple logic within
the Ruport::Data::Record class.
James - your code example is very neat, but since I'm blessed with a
simple mind I traded space for readability:
-------------------------------------------------
FROM
-------------------------------------------------
people = FCSV(data, :col_sep => ";",
:headers => true,
:header_converters => :symbol ) do |csv|
csv.inject(Array.new) { |all, person| all + [OpenStruct.new(person.to_hash)] }
end
# example usage
puts people.map { |person| person.first_name }
-------------------------------------------------
TO
-------------------------------------------------
people = Array.new
FCSV(data, :col_sep => ";",
:headers => true,
:header_converters => :symbol ) do |csv|
csv.each do |csvrow|
people.push OpenStruct.new(csvrow.to_hash)
end
end
people.each do |person|
puts person.first_name
end
-------------------------------------------------
Not meaning to bash your suggestion, just sharing my initial reaction. Any
comments or caveats?
Anyway, both your suggestions surpass my needs though, so from here on in
it's a breeze. Thank you.
JE