Based on the current knowledge of Ruby and the help of Ruby Standard library, you should be able to build a real-world application.
In the beginning, I provided a sample application that used a lot of the Ruby features we had discussed. This program reads a simple text file to get a set of stock symbols and the number of shares owned by a person and retrieves the stock price on an ordinary financial site (finance.yahoo.com). After retrieving the stock price, it calculates the portfolio of the person (the stock number x the price of each share).
Rather than just showing a simple ruby syntax and class/object architecture, this simple application also uses Ruby's built-in array class and I/O features to get symbol and share information from a text file. It then uses the Ruby standard library class to connect to the financial site and retrieve an HTML page that contains the stock price corresponding to each symbol provided. Finally, it uses regular expressions and blocks of code to locate or get stock prices from the HTML returned via HTTP connections.
For the application to work, please download and extract the corresponding source files from this article to your file system. After decompression, a Examples2 folder is generated. There are 4 ruby code files (. rb files) and one text file Holdings.txt. The fetcher.rb file is used as the code to perform stock quotes retrieval. To run the sample application, open a command prompt and run the fetcher.rb file with Ruby.
This holding.txt file contains examples of stock symbols and the number of theories owning shares. The current contents of the holding.txt contain symbols corresponding to the 3m,wells Fargo and Pfizer, and appear as follows:
MMM 11
WFC 20
PFE 5
You can add your own symbols and imaginary shares to this file. When you execute this program, you will get similar results as shown in the following diagram.