Prev | Current Page 241 | Next

David Berube

"Practical Reporting with Ruby and Rails"

each do |file|
rows = FasterCSV.parse(open(file))
first_row= rows.shift
symbol_index = nil
first_row.each_with_index do |label, index|
if(valid_symbol_labels.include?(label))
symbol_index = index
break
end
end
if symbol_index.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
include Remarkably::Common
def to_xml # Output our stocks list as XML
xml do
symbols do
@symbols.each do |s|
symbol s
end
end
end.to_s
end
end
CHAPTER 9 n INVESTMENT TRACKING WITH FIDELITY 174
class StocksListHandler < Mongrel::HttpHandler
def initialize(stocks_list)
@stocks_list = stocks_list
super()
end
def process(request, response)
response.start(200) do |headers, output_stream|
headers["Content-Type"] = "text/xml"
output_stream.write(@stocks_list.to_xml)
end
end
end
stocks_list = StocksList.new
stocks_list.load_csv(ARGV)
interface = '127.0.0.1'
port = '3000'
mongrel_server = Mongrel::HttpServer.


Pages:
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253