Prev | Current Page 253 | Next

David Berube

"Practical Reporting with Ruby and Rails"

run
end
end
hostname = ARGV.shift
port_number = ARGV.shift
my_app = FXTickerApp.new(hostname, port_number, 240)
my_app.go
Save this script as xml_ticker.rb.
You can run the script using a command like the following:
ruby xml_ticker.rb localhost 3000
Note that under Mac OS X and Linux, you??™ll need to launch the X11 server in order to
see anything. X11 is available from the Mac OS X installation media. X11 comes standard
with most Linux distributions. To launch X11 under Linux, use the startx command. On
an OS X system, click the X11 icon.
You should see a screen similar to Figure 9-2.
Figure 9-2. XML stock ticker
Let??™s examine the code line by line.
Dissecting the Code
The code in Listing 9-2 has a single class, FXTickerApp, which has a number of methods.
The first is the initialize method, which creates the user interface elements you need.
However, before you start creating user interface elements, you need to initialize the settings
and load the stock symbols from the server:
class FXTickerApp
include Fox
def initialize(hostname, port_number,
font_size = 100, quote_frequency=1,
reload_csv_frequency=60)
# Quote_frequency and reload_csv_frequency are in minutes
CHAPTER 9 n INVESTMENT TRACKING WITH FIDELITY 183
@hostname = hostname
@port_number = port_number
@quote_frequency = quote_frequency
@reload_csv_frequency = reload_csv_frequency
load_symbols_from_server
The first few lines set appropriate instance variables.


Pages:
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
pomiary wiatru 200 dollar payday loan Łeba domki impregnacja posadzek kamiennych siłacz strongman