Prev | Current Page 244 | Next

David Berube

"Practical Reporting with Ruby and Rails"

nil?
puts "Can't find symbol index on first row in file #{file}."
else
@symbols = @symbols + rows.map { |r| r[symbol_index]
}.delete_if { |s| s.nil? or s =='' }
end
end
end
This method loops through each of the CSV files and loads them. It does this by
assuming that the first row of each file is a header, and it loops through it looking for a
column named Symbol. This has the advantage of working with any CSV file whose first
line is a header row and that has a Symbol column. If your CSV files have symbol columns
labeled something else, you can add support for them by adding to the valid_symbol_
labels array.
The end result of this is a @symbols array full of symbols, which you use next. You
expose a single method, to_xml, which converts it into XML:
include Remarkably::Common
def to_xml
xml do
symbols do
@symbols.each do |s|
symbol s
end
CHAPTER 9 n INVESTMENT TRACKING WITH FIDELITY 177
end
end.to_s
end
The to_xml method uses Remarkably??™s xml method to create a simple XML document.
(You can use the xml method because you mixed in the Remarkably::Common framework
using include.


Pages:
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
online cash loans kredyt samochodowy lukas Gronkowiec miedzyzdroje wczasy naprawa komputerów Warszawa