Class: Sinbotra::Bot::Conversation

Inherits:
Object
  • Object
show all
Defined in:
lib/sinbotra/bot/conversation.rb

Defined Under Namespace

Classes: Step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, store = {}) ⇒ Conversation

Returns a new instance of Conversation.



8
9
10
11
12
13
14
# File 'lib/sinbotra/bot/conversation.rb', line 8

def initialize(id, store={})
  @id           = id
  @steps        = []
  @store        = store
  update_current_step(0)
  store!(:is_active, false)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/sinbotra/bot/conversation.rb', line 5

def id
  @id
end

#stepsObject (readonly)

Returns the value of attribute steps.



6
7
8
# File 'lib/sinbotra/bot/conversation.rb', line 6

def steps
  @steps
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/sinbotra/bot/conversation.rb', line 20

def active?
  recall(:is_active)
end

#current_stepObject



24
25
26
# File 'lib/sinbotra/bot/conversation.rb', line 24

def current_step
  recall(:_current_step)
end

#done!Object



63
64
65
66
# File 'lib/sinbotra/bot/conversation.rb', line 63

def done!
  update_current_step(0)
  store!(:is_active, false)
end

#next_step!Object



48
49
50
51
52
# File 'lib/sinbotra/bot/conversation.rb', line 48

def next_step!
  new_step = current_step + 1
  update_current_step(new_step)
  done! if completed_last_step?
end

#next_step_now!(bot) ⇒ Object



54
55
56
57
# File 'lib/sinbotra/bot/conversation.rb', line 54

def next_step_now!(bot)
  next_step!
  perform_current_step(bot)
end

#perform_current_step(bot) ⇒ Object



68
69
70
# File 'lib/sinbotra/bot/conversation.rb', line 68

def perform_current_step(bot)
  current_action.(bot)
end

#recall(k) ⇒ Object



36
37
38
# File 'lib/sinbotra/bot/conversation.rb', line 36

def recall(k)
  @store[k]
end

#repeat_step!Object



59
60
61
# File 'lib/sinbotra/bot/conversation.rb', line 59

def repeat_step!
  puts "Repeating conversation step. Nothing to do here."
end

#say(text) ⇒ Object



40
41
42
# File 'lib/sinbotra/bot/conversation.rb', line 40

def say(text)
  puts text
end

#skip_to_next_step!Object



44
45
46
# File 'lib/sinbotra/bot/conversation.rb', line 44

def skip_to_next_step!
  puts "NOOP skip_to_next_step!"
end

#startObject



16
17
18
# File 'lib/sinbotra/bot/conversation.rb', line 16

def start
  store!(:is_active, true)
end

#step(id, &blk) ⇒ Object



28
29
30
# File 'lib/sinbotra/bot/conversation.rb', line 28

def step(id, &blk)
  @steps << Step.new(id, blk)
end

#store!(k, v) ⇒ Object



32
33
34
# File 'lib/sinbotra/bot/conversation.rb', line 32

def store!(k, v)
  @store[k] = v
end