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 32 |
# File 'lib/james/controller.rb', line 28 def initialize dialog = nil @initial = dialog || CoreDialog.new @conversation = Conversation.new @initial.current @preferences = James::Preferences.new 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.
39 40 41 |
# File 'lib/james/controller.rb', line 39 def << dialog @initial << dialog end |
#applicationDidFinishLaunching(notification) ⇒ Object
MacRuby callback functions.
68 69 70 71 |
# File 'lib/james/controller.rb', line 68 def applicationDidFinishLaunching notification start_output start_input end |
#expects ⇒ Object
98 99 100 |
# File 'lib/james/controller.rb', line 98 def expects conversation.expects end |
#hear(text) ⇒ Object
93 94 95 96 97 |
# File 'lib/james/controller.rb', line 93 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).
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/james/controller.rb', line 49 def listen = {} return if listening @listening = true @input_class = [:input] || Inputs::Audio @output_class = [:output] || Outputs::Audio app = NSApplication.sharedApplication app.delegate = self app.run end |
#say(text) ⇒ Object
Callback method from dialog.
90 91 92 |
# File 'lib/james/controller.rb', line 90 def say text @output.say text end |
#start_input ⇒ Object
Start recognizing words.
78 79 80 81 |
# File 'lib/james/controller.rb', line 78 def start_input @input = @input_class.new self @input.listen end |
#start_output ⇒ Object
Start speaking.
84 85 86 |
# File 'lib/james/controller.rb', line 84 def start_output @output = @output_class.new @preferences end |
#windowWillClose(notification) ⇒ Object
72 73 74 |
# File 'lib/james/controller.rb', line 72 def windowWillClose notification exit end |