Class: Converse::Interaction
- Inherits:
-
Object
- Object
- Converse::Interaction
- Defined in:
- lib/converse/interaction.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#broker ⇒ Object
Returns the value of attribute broker.
-
#concern ⇒ Object
Returns the value of attribute concern.
-
#conversation ⇒ Object
Returns the value of attribute conversation.
-
#should_i_ask ⇒ Object
Returns the value of attribute should_i_ask.
-
#substance ⇒ Object
Returns the value of attribute substance.
Instance Method Summary collapse
- #about(action) ⇒ Object
- #ask ⇒ Object
- #ask_broker(broker) ⇒ Object
- #ask_broker_concerning(broker, concern) ⇒ Object
- #by_asking ⇒ Object
- #by_saying ⇒ Object
- #concerning(concern) ⇒ Object
- #detailed_by(substance) ⇒ Object
- #discuss ⇒ Object
- #discuss_with(broker) ⇒ Object
- #discuss_with_broker_concerning(broker, concern) ⇒ Object
- #does_not_include(keys) ⇒ Object
- #ensure_that(substance) ⇒ Object
- #handle_error!(response) ⇒ Object
- #includes(keys) ⇒ Object
- #interpret_conversation(response) ⇒ Object
- #say ⇒ Object
- #success?(response) ⇒ Boolean
- #tell_broker(broker) ⇒ Object
- #tell_broker_concerning(broker, concern) ⇒ Object
- #to(action) ⇒ Object
- #using(substance) ⇒ Object
- #with(substance) ⇒ Object
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
8 9 10 |
# File 'lib/converse/interaction.rb', line 8 def action @action end |
#broker ⇒ Object
Returns the value of attribute broker.
6 7 8 |
# File 'lib/converse/interaction.rb', line 6 def broker @broker end |
#concern ⇒ Object
Returns the value of attribute concern.
7 8 9 |
# File 'lib/converse/interaction.rb', line 7 def concern @concern end |
#conversation ⇒ Object
Returns the value of attribute conversation.
10 11 12 |
# File 'lib/converse/interaction.rb', line 10 def conversation @conversation end |
#should_i_ask ⇒ Object
Returns the value of attribute should_i_ask.
11 12 13 |
# File 'lib/converse/interaction.rb', line 11 def should_i_ask @should_i_ask end |
#substance ⇒ Object
Returns the value of attribute substance.
9 10 11 |
# File 'lib/converse/interaction.rb', line 9 def substance @substance end |
Instance Method Details
#about(action) ⇒ Object
59 60 61 62 |
# File 'lib/converse/interaction.rb', line 59 def about(action) @action = action.dup self end |
#ask ⇒ Object
91 92 93 |
# File 'lib/converse/interaction.rb', line 91 def ask @conversation.ask end |
#ask_broker(broker) ⇒ Object
37 38 39 40 41 |
# File 'lib/converse/interaction.rb', line 37 def ask_broker(broker) @broker = broker @should_i_ask = true self end |
#ask_broker_concerning(broker, concern) ⇒ Object
25 26 27 28 29 |
# File 'lib/converse/interaction.rb', line 25 def ask_broker_concerning(broker, concern) ask_broker(broker) concerning(concern) self end |
#by_asking ⇒ Object
81 82 83 84 |
# File 'lib/converse/interaction.rb', line 81 def by_asking @should_i_ask = true self end |
#by_saying ⇒ Object
86 87 88 89 |
# File 'lib/converse/interaction.rb', line 86 def @should_i_ask = false self end |
#concerning(concern) ⇒ Object
54 55 56 57 |
# File 'lib/converse/interaction.rb', line 54 def concerning(concern) @concern = concern.dup self end |
#detailed_by(substance) ⇒ Object
68 69 70 71 |
# File 'lib/converse/interaction.rb', line 68 def detailed_by(substance) @substance = substance self end |
#discuss ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/converse/interaction.rb', line 99 def discuss @conversation = broker.broker_conversation(@broker.open_topic(@concern, @action)) @conversation.subscribe(SimpleLogger.new) @should_i_ask ? response = ask : response = say if not success?(response) response = handle_error!(response) return nil if response.nil? end translated_response = broker.translate_response(response) interpret_conversation(translated_response) end |
#discuss_with(broker) ⇒ Object
49 50 51 52 |
# File 'lib/converse/interaction.rb', line 49 def discuss_with(broker) @broker = broker self end |
#discuss_with_broker_concerning(broker, concern) ⇒ Object
19 20 21 22 23 |
# File 'lib/converse/interaction.rb', line 19 def discuss_with_broker_concerning(broker, concern) discuss_with(broker) concerning(concern) self end |
#does_not_include(keys) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/converse/interaction.rb', line 138 def does_not_include(keys) if @validation.kind_of?(Hash) keys.each do |k| raise ArgumentError, "#{key} is invalid for this interaction" if @validation.has_key?(k) end end end |
#ensure_that(substance) ⇒ Object
123 124 125 126 |
# File 'lib/converse/interaction.rb', line 123 def ensure_that(substance) @validation = substance self end |
#handle_error!(response) ⇒ Object
119 120 121 |
# File 'lib/converse/interaction.rb', line 119 def handle_error!(response) response end |
#includes(keys) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/converse/interaction.rb', line 128 def includes(keys) raise ArgumentError, "No arguments provided for this interaction and it requires #{keys}" if @validation.nil? if @validation.kind_of?(Hash) keys.each do |k| raise ArgumentError, "#{k} must be provided for this interaction" if not @validation.has_key?(k) end end end |
#interpret_conversation(response) ⇒ Object
111 112 113 |
# File 'lib/converse/interaction.rb', line 111 def interpret_conversation(response) response end |
#say ⇒ Object
95 96 97 |
# File 'lib/converse/interaction.rb', line 95 def say @conversation.say end |
#success?(response) ⇒ Boolean
115 116 117 |
# File 'lib/converse/interaction.rb', line 115 def success?(response) true end |
#tell_broker(broker) ⇒ Object
43 44 45 46 47 |
# File 'lib/converse/interaction.rb', line 43 def tell_broker(broker) @broker = broker @should_i_ask = false self end |
#tell_broker_concerning(broker, concern) ⇒ Object
31 32 33 34 35 |
# File 'lib/converse/interaction.rb', line 31 def tell_broker_concerning(broker, concern) tell_broker(broker) concerning(concern) self end |
#to(action) ⇒ Object
64 65 66 |
# File 'lib/converse/interaction.rb', line 64 def to(action) about(action) end |
#using(substance) ⇒ Object
73 74 75 |
# File 'lib/converse/interaction.rb', line 73 def using(substance) detailed_by(substance) end |
#with(substance) ⇒ Object
77 78 79 |
# File 'lib/converse/interaction.rb', line 77 def with(substance) detailed_by(substance) end |