It handles the loading of the symbols and then the list of symbols.
??? StocksListHandler: This class is a Mongrel handler. It processes requests from the
ticker, and then serves them as XML. The ticker then uses those symbols.
The code for the StocksList class has three methods. The first method, initialize,
sets up the array holding the list of symbols:
def initialize
@symbols = [] # Holds our list of symbols
end
initialize is the constructor??”a special method called by Ruby when a class is
instantiated into an object. The constructor has just a single line of code, which initializes
your @symbols array.
CHAPTER 9 n INVESTMENT TRACKING WITH FIDELITY 176
The next StocksList method is load_csv, which is used to load the CSV data into the
object:
def load_csv(files)
@symbols = []
valid_symbol_labels = ['Symbol']
files.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.
Pages:
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255