Class: FlowChat::Ussd::App

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_chat/ussd/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/flow_chat/ussd/app.rb', line 4

def context
  @context
end

#inputObject (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/flow_chat/ussd/app.rb', line 4

def input
  @input
end

Returns the value of attribute navigation_stack.



4
5
6
# File 'lib/flow_chat/ussd/app.rb', line 4

def navigation_stack
  @navigation_stack
end

#sessionObject (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

Raises:

  • (ArgumentError)


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 navigation_stack.include?(key)

  navigation_stack << 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