Class: Dialogue::Conversation
- Inherits:
-
Object
- Object
- Dialogue::Conversation
- Includes:
- ConversationOptions, Storable
- Defined in:
- lib/dialogue/conversation.rb
Instance Attribute Summary collapse
-
#channel_id ⇒ Object
Returns the value of attribute channel_id.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#team_id ⇒ Object
Returns the value of attribute team_id.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Attributes included from ConversationOptions
Instance Method Summary collapse
- #ask(question, opts = {}, &block) ⇒ Object
- #diverge(template_name) ⇒ Object
- #end(statement = nil) ⇒ Object
-
#initialize(template = nil, message = nil, options = {}) ⇒ Conversation
constructor
A new instance of Conversation.
- #perform(*args) ⇒ Object (also: #continue)
- #say(statement, opts = {}) ⇒ Object (also: #reply)
Methods included from Storable
#data, #fetch, #has_data?, #store!
Methods included from ConversationOptions
Constructor Details
#initialize(template = nil, message = nil, options = {}) ⇒ Conversation
Returns a new instance of Conversation.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dialogue/conversation.rb', line 11 def initialize(template=nil, =nil, ={}) @templates = [] @steps = [] unless template.nil? @templates = [template] @steps << template.template end @message = unless @message.nil? @channel_id = .channel_id @team_id = .team_id @user_id = .user_id end @data = .delete(:data) @options = .freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dialogue::ConversationOptions
Instance Attribute Details
#channel_id ⇒ Object
Returns the value of attribute channel_id.
8 9 10 |
# File 'lib/dialogue/conversation.rb', line 8 def channel_id @channel_id end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/dialogue/conversation.rb', line 9 def @message end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
9 10 11 |
# File 'lib/dialogue/conversation.rb', line 9 def steps @steps end |
#team_id ⇒ Object
Returns the value of attribute team_id.
8 9 10 |
# File 'lib/dialogue/conversation.rb', line 8 def team_id @team_id end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
9 10 11 |
# File 'lib/dialogue/conversation.rb', line 9 def templates @templates end |
#user_id ⇒ Object
Returns the value of attribute user_id.
8 9 10 |
# File 'lib/dialogue/conversation.rb', line 8 def user_id @user_id end |
Instance Method Details
#ask(question, opts = {}, &block) ⇒ Object
33 34 35 36 |
# File 'lib/dialogue/conversation.rb', line 33 def ask(question, opts={}, &block) say question, opts steps << block end |
#diverge(template_name) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/dialogue/conversation.rb', line 38 def diverge(template_name) template = Dialogue.find_template template_name unless template.nil? templates << template steps << template.template perform end end |
#end(statement = nil) ⇒ Object
47 48 49 50 |
# File 'lib/dialogue/conversation.rb', line 47 def end(statement=nil) say statement unless statement.nil? Dialogue.unregister_conversation self end |
#perform(*args) ⇒ Object Also known as: continue
52 53 54 55 56 |
# File 'lib/dialogue/conversation.rb', line 52 def perform(*args) step = steps.pop step.call self, *args unless step.nil? Dialogue.unregister_conversation self if steps.empty? end |