Class: Portfolio::StockPrices
- Inherits:
-
Object
- Object
- Portfolio::StockPrices
- Includes:
- Singleton
- Defined in:
- lib/portfolio/stockprices.rb
Instance Method Summary collapse
Instance Method Details
#get_price_formatted(symbol) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/portfolio/stockprices.rb', line 12 def get_price_formatted(symbol) # Lookup stock price: stock = get_stock(symbol) # If the response code isn't 200, something went wrong: if stock.response_code != 200 "ERROR".red else # Get the current stock price: price = stock.ask.to_s # If it's up, show it in green: if stock.change > 0.0 price.green # If it's down, show it in red: elsif stock.change < 0.0 return price.red # Otherwise, show it normally: else price end end end |
#get_stock(symbol) ⇒ Object
8 9 10 |
# File 'lib/portfolio/stockprices.rb', line 8 def get_stock(symbol) StockQuote::Stock.quote(symbol) end |