Class: James::Controller
- Inherits:
-
Object
- Object
- James::Controller
- Defined in:
- lib/james/controller.rb
Instance Attribute Summary collapse
-
#conversation ⇒ Object
readonly
Returns the value of attribute conversation.
-
#initial ⇒ Object
readonly
Returns the value of attribute initial.
-
#listening ⇒ Object
readonly
Returns the value of attribute listening.
Class Method Summary collapse
-
.instance ⇒ Object
Singleton reader.
Instance Method Summary collapse
-
#<<(dialog) ⇒ Object
Convenience method to add a dialog to the current system.
-
#applicationDidFinishLaunching(notification) ⇒ Object
MacRuby callback functions.
- #expects ⇒ Object
- #hear(text) ⇒ Object
-
#initialize(dialog = nil) ⇒ Controller
constructor
This puts together the initial dialog and the user ones that are hooked into it.
-
#listen(options = {}) ⇒ Object
Start listening using the provided options.
-
#say(text) ⇒ Object
Callback method from dialog.
-
#start_input ⇒ Object
Start recognizing words.
-
#start_output ⇒ Object
Start speaking.
- #windowWillClose(notification) ⇒ Object
Constructor Details
#initialize(dialog = nil) ⇒ Controller
This puts together the initial dialog and the user ones that are hooked into it.
The initial dialog needs an state defined as initially. This is where it will start.
Example:
initially :awake
state :awake do
# ...
end
If you don’t give it an initial dialog, James will simply use the built-in CoreDialog.
28 29 30 31 |
# File 'lib/james/controller.rb', line 28 def initialize dialog = nil @initial = dialog || CoreDialog.new @conversation = Conversation.new @initial.current end |
Instance Attribute Details
#conversation ⇒ Object (readonly)
Returns the value of attribute conversation.
5 6 7 |
# File 'lib/james/controller.rb', line 5 def conversation @conversation end |
#initial ⇒ Object (readonly)
Returns the value of attribute initial.
5 6 7 |
# File 'lib/james/controller.rb', line 5 def initial @initial end |
#listening ⇒ Object (readonly)
Returns the value of attribute listening.
5 6 7 |
# File 'lib/james/controller.rb', line 5 def listening @listening end |
Class Method Details
.instance ⇒ Object
Singleton reader.
9 10 11 |
# File 'lib/james/controller.rb', line 9 def self.instance @controller ||= new end |
Instance Method Details
#<<(dialog) ⇒ Object
Convenience method to add a dialog to the current system.
Will add the dialog to the initial dialog passed into the controller.
38 39 40 |
# File 'lib/james/controller.rb', line 38 def << dialog @initial << dialog end |
#applicationDidFinishLaunching(notification) ⇒ Object
MacRuby callback functions.
70 71 72 73 |
# File 'lib/james/controller.rb', line 70 def applicationDidFinishLaunching notification start_output start_input end |
#expects ⇒ Object
100 101 102 |
# File 'lib/james/controller.rb', line 100 def expects conversation.expects end |
#hear(text) ⇒ Object
95 96 97 98 99 |
# File 'lib/james/controller.rb', line 95 def hear text conversation.hear text do |response| say response end end |
#listen(options = {}) ⇒ Object
Start listening using the provided options.
Options:
* input # Inputs::Terminal or Inputs::Audio (default).
* output # Outputs::Terminal or Outputs::Audio (default).
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/james/controller.rb', line 48 def listen = {} return if listening @listening = true @input_class = [:input] || Inputs::Audio @output_class = [:output] || Outputs::Audio @output_options ||= {} @output_options[:voice] = [:voice] || 'com.apple.speech.synthesis.voice.Alex' app = NSApplication.sharedApplication app.delegate = self app.run end |
#say(text) ⇒ Object
Callback method from dialog.
92 93 94 |
# File 'lib/james/controller.rb', line 92 def say text @output.say text end |
#start_input ⇒ Object
Start recognizing words.
80 81 82 83 |
# File 'lib/james/controller.rb', line 80 def start_input @input = @input_class.new self @input.listen end |
#start_output ⇒ Object
Start speaking.
86 87 88 |
# File 'lib/james/controller.rb', line 86 def start_output @output = @output_class.new @output_options end |
#windowWillClose(notification) ⇒ Object
74 75 76 |
# File 'lib/james/controller.rb', line 74 def windowWillClose notification exit end |