Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 41 lines (32 sloc) 0.739 kb
254e652 Florian R. Hanke + stocks example – James tells you if your stocks went up or down
authored
1 require 'rubygems'
2 require 'yahoofinance'
3
4 # If using the gem, replace with:
5 #
6 # require 'rubygems'
7 # require 'james'
8 require File.expand_path '../../lib/james', __FILE__
9
10 # Stocks dialog by Florian Hanke.
11 #
12 # This is a very simple James example.
13 #
14 class StocksDialog
15
16 include James::Dialog
17
18 attr_reader :quotes, :stocks
19
20 def initialize *stocks
21 @quotes = YahooFinance::ExtendedQuote.new
22 @stocks = stocks
23 end
24
25 hear 'How are my stocks?' => :stocks
26
27 state :stocks do
28 hear 'Again'
29 into do
30 say = []
31 stocks.each do |stock|
32 result = quotes.load_quote stock
33 say << "#{stock} has moved #{result[28]}."
34 end
35 say.join ' '
36 end
37 end
38
39 end
40
f7c6cb7 Florian R. Hanke + preferences and updated examples
authored
41 James.use StocksDialog.new('IBM', 'AAPL')
Something went wrong with that request. Please try again.