Prev | Current Page 256 | Next

David Berube

"Practical Reporting with Ruby and Rails"

addTimeout(1000*60*@quote_frequency,
method(:update_label_timer))
@fox_application.create
end
By default, the stock prices are loaded from Yahoo! Finance once a minute. The timer
calls class functions that implement the actual functionality. The first one loads the stock
symbols:
def load_symbols_from_server
xml_body = Net::HTTP.new(@hostname, @port_number).get('/').body
xml = XmlSimple.xml_in(xml_body)
@symbols = xml['symbols'][0]['symbol']
end
First, you request the XML using the Ruby built-in library Net::HTTP, and then you
parse it using XmlSimple. The XML document you are trying to parse looks like this:


GOOG
JAVA
RHT


The call xml['symbols'][0]['symbol'] returns an array of symbol nodes inside the first
symbols node. There is only one symbols node, but XmlSimple returns all elements of a
given name as arrays, even if there??™s just one. Because the symbol objects are nodes with
a text element (in other words, elements with text inside them) and no attributes or
child nodes, they are returned as strings in an array.


Pages:
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
ciekawe zdania czym jest nowomowa poker online słownik poker online