Class: FlowChat::Ussd::App
- Inherits:
-
Object
- Object
- FlowChat::Ussd::App
- Defined in:
- lib/flow_chat/ussd/app.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#navigation_stack ⇒ Object
readonly
Returns the value of attribute navigation_stack.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(context) ⇒ App
constructor
A new instance of App.
- #say(msg) ⇒ Object
- #screen(key) ⇒ Object
Constructor Details
#initialize(context) ⇒ App
Returns a new instance of App.
6 7 8 9 10 11 |
# File 'lib/flow_chat/ussd/app.rb', line 6 def initialize(context) @context = context @session = context.session @input = context.input @navigation_stack = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/flow_chat/ussd/app.rb', line 4 def context @context end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
4 5 6 |
# File 'lib/flow_chat/ussd/app.rb', line 4 def input @input end |
#navigation_stack ⇒ Object (readonly)
Returns the value of attribute navigation_stack.
4 5 6 |
# File 'lib/flow_chat/ussd/app.rb', line 4 def @navigation_stack end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
4 5 6 |
# File 'lib/flow_chat/ussd/app.rb', line 4 def session @session end |
Instance Method Details
#say(msg) ⇒ Object
28 29 30 |
# File 'lib/flow_chat/ussd/app.rb', line 28 def say(msg) raise FlowChat::Interrupt::Terminate.new(msg) end |
#screen(key) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flow_chat/ussd/app.rb', line 13 def screen(key) raise ArgumentError, "a block is expected" unless block_given? raise ArgumentError, "screen has been presented" if .include?(key) << key return session.get(key) if session.get(key).present? prompt = FlowChat::Ussd::Prompt.new input @input = nil # input is being submitted to prompt so we clear it value = yield prompt session.set(key, value) value end |