R
RichardOnRails
Hi,
I have a csv file suitable for an Excel display. The file has column-
names on certain row.
In order to process subsequent rows I want to refer to their columns
symbolically using the column-names. That requires the column-names to
be cleaned up in order to create valid Ruby symbols.
The following worked fine:
if col_name
col_name.gsub!(/[\s]/, "")
col_name.gsub!(/[&]/, "And")
col_name.gsub!(/[#]/, "Number")
end
Each of the following one-liners failed:
col_name.gsub!(/[\s]/, ""). gsub!(/[&]/, "And").gsub!(/[#]/,
"Number") if col_name
col_name.gsub(/[\s]/, ""). gsub(/[&]/, "And").gsub(/[#]/, "Number")
if col_name
Can either of the one-liners be made to work?
The code is show in a larger (easier to read) context at http://www.pastie.org/442456
Thanks in Advance,
Richard
..
I have a csv file suitable for an Excel display. The file has column-
names on certain row.
In order to process subsequent rows I want to refer to their columns
symbolically using the column-names. That requires the column-names to
be cleaned up in order to create valid Ruby symbols.
The following worked fine:
if col_name
col_name.gsub!(/[\s]/, "")
col_name.gsub!(/[&]/, "And")
col_name.gsub!(/[#]/, "Number")
end
Each of the following one-liners failed:
col_name.gsub!(/[\s]/, ""). gsub!(/[&]/, "And").gsub!(/[#]/,
"Number") if col_name
col_name.gsub(/[\s]/, ""). gsub(/[&]/, "And").gsub(/[#]/, "Number")
if col_name
Can either of the one-liners be made to work?
The code is show in a larger (easier to read) context at http://www.pastie.org/442456
Thanks in Advance,
Richard
..