Permalink
Browse files

+ 0.1.0

  • Loading branch information...
1 parent 7d025b8 commit 39b4078ee0edad48261c5750a1bf9aceed501b2c @floere committed May 20, 2011
View
@@ -23,11 +23,10 @@ All examples can be found in "/examples":http://github.com/floere/james/tree/mas
Create a file called @time_dialog.rb@:
-<pre><code>class TimeDialog
-
- include James::Dialog
+<pre><code>James.use_dialog do
hear 'what time is it?' => :time
+
state :time do
hear ['What time is it?', 'And now?'] => :time
into { time = Time.now; "It is currently #{time.hour} #{time.min}." }
@@ -53,6 +52,8 @@ require 'james'
# Your dialog goes here.
+# This is needed to start James.
+#
James.listen</code></pre>
in your script, and call it by using
@@ -65,21 +66,26 @@ Or else, in the terminal, just call
and it will include all dialogs (files called @_dialog{ue,}.rb@, the @ue@ is for the brits and aussies :) ) in this directory and subdirectories. E.g. @joke_dialog.rb@, @newsfeed_dialog.rb@, or @social_media/tweets_dialog.rb@.
-You can select dialogs using their first file name part
+You can select dialogs using their file names
-<pre><code>$ james time joke twitter</code></pre>
+<pre><code>$ james time_dialog.rb twitter_dialog.rb</code></pre>
-and it will include the time dialog, the joke dialog, and the twitter dialog.
+and it will include the time dialog and the twitter dialog.
-Note: The @james@ executable looks for files called and includes them.
+Or a bit more exciting
+
+<pre><code>$ james {time,twitter}*.rb</code></pre>
+
+to do the same as above.
h3. Short Version
-There is a short, anonymous dialog version, using @James.dialog@.
+There is a short, anonymous dialog version, using @James.use_dialog@.
-<pre><code>James.dialog do
+<pre><code>James.use_dialog do
hear 'what time is it?' => :time
+
state :time do
hear ['What time is it?', 'And now?'] => :time
into { time = Time.now; "It is currently #{time.hour} #{time.min}." }
@@ -89,19 +95,20 @@ end</code></pre>
h3. Extended Version
-Or there is an extended version, using initialize to set up some important stuff that needs other stuff for doing stuff, you know?
+Or there is an extended version, using initialize with parameters to set up some important stuff that needs other stuff for doing stuff, you know?
<pre><code>require 'james'
class TwitterDialog
include James::Dialog
- def initialize
- @client = Twitter.new 'user', 'password'
+ def initialize user, password
+ @client = Twitter.new user, password
end
hear 'What are the birds tweeting?' => :newsfeed
+
state :newsfeed do
hear 'Who mentions me?' => :mentions
into do
@@ -118,7 +125,11 @@ class TwitterDialog
end
end
-end</code></pre>
+end
+
+James.use TwitterDialog.new('user', 'password')
+
+James.listen</code></pre>
h2. Contributions
@@ -127,7 +138,7 @@ Sending dialog gists is appreciated. Thanks!
h2. Running the specs
-@rspec spec@
+Currently need to be run separately.
h2. Roadmap
View
@@ -2,60 +2,72 @@ This is the directory for contributed examples.
They should always be of the form:
-<pre><code> # If using the gem, replace with:
- #
- # require 'rubygems'
- # require 'james'
- require File.expand_path '../../lib/james', __FILE__
+<pre><code># If using the gem, replace with:
+#
+# require 'rubygems'
+# require 'james'
+require File.expand_path '../../lib/james', __FILE__
- class ItunesDialog
+James.use_dialog do
- include James::Dialog
+ # You dialog definitions go here.
- # You dialog definitions go here.
+end
+# Or with initializer.
+#
+class CoffeeDialog
+
+ include James::Dialog
+
+ def initialize coffee_type
+ @coffee_type = coffee_type
end
- # This line is for running it standalone.
- #
- James.listen</code></pre>
+ # Your dialog definitions go here.
+
+end
+
+James.use CoffeeDialog.new('bolivian')</code></pre>
One example is the following simple one:
-<pre><code> # If using the gem, replace with:
- #
- # require 'rubygems'
- # require 'james'
- require File.expand_path '../../lib/james', __FILE__
+<pre><code># If using the gem, replace with:
+#
+# require 'rubygems'
+# require 'james'
+require File.expand_path '../../lib/james', __FILE__
+
+class ItunesDialog
+
+ include James::Dialog
+
+ def initialize
+ # Usually though it's a good idea to set it up lazily in the actions:
+ # @setup_thing ||= Thing.new
+ # @setup_thing.do_something
+ #
+ @setup_thing = Thing.new
+ end
+
+ hear 'My useful initial phrase' => :my_initial_state
- class ItunesDialog
+ state :my_initial_state do
- include James::Dialog
+ hear 'something' => :next_state
+ hear 'something and stay in state' => ->(){ "I am saying this but staying in this state" }
+ hear 'something and stay in state, silently'
- def initialize
- # Usually though it's a good idea to set it up in the actions:
- # @setup_thing ||= Thing.new
- # @setup_thing.do_something
- #
- @setup_thing = Thing.new
+ into do
+ "Say something on entering"
end
- hear 'My useful initial phrase' => :my_initial_state
- state :my_initial_state do
- hear 'something' => :next_state
- hear 'something and stay in state' => ->(){ "I am saying this but staying in this state" }
- into do
- "Say something on entering"
- end
- exit do
- "Say something on exiting"
- end
+ exit do
+ "Say something on exiting"
end
end
- # This line is for running it standalone.
- #
- James.listen</code></pre>
+end</code></pre>
Please see the many examples in this folder.
@@ -33,5 +33,3 @@
end
end
-
-James.listen
@@ -32,6 +32,4 @@
end
end
-end
-
-James.listen
+end
@@ -52,6 +52,4 @@ def initialize
end
end
-end
-
-James.listen
+end
View
@@ -25,6 +25,4 @@
end
end
-end
-
-James.listen
+end
@@ -37,5 +37,3 @@ def initialize from
end
James.use TwitterDialog.new('hanke')
-
-James.listen
@@ -33,6 +33,4 @@ def initialize location
end
-James.use WeatherDialog.new('Melbourne')
-
-James.listen
+James.use WeatherDialog.new('Melbourne')
View
@@ -1,3 +1,10 @@
+h2. Version 0.1.0
+
+* hanke: API breakage, @James.dialog@ -> @James.use_dialog@.
+* hanke: Command line @james@ now takes file names (or patterns, like @james time_dialog.rb@ or @james {time,twitter}*.rb@)
+* hanke: @James.listen@ can only be called once. So if you use @ruby@ to run a dialog, it needs to be called once at the end of the script.
+* hanke: Added @James.use@. It takes any number of @James::Dialog@ instances to use when listening.
+
h2. Version 0.0.12
* hanke: @hear 'Stay in same state' => ->(){ "This block will now be instance eval'd in the context of the Dialog" }@
View
@@ -1,5 +0,0 @@
-class Object
- def framework(*)
-
- end
-end

0 comments on commit 39b4078

Please sign in to comment.