Module: Pc::Campfire

Includes:
Interface
Defined in:
lib/pc/interfaces/campfire.rb

Instance Method Summary collapse

Methods included from Interface

included

Instance Method Details

#choose(choices = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pc/interfaces/campfire.rb', line 26

def choose(choices = {})
  if choices[:next]
    sleep 0.2
    choices[:next]
  else
    say %{Pick one: #{choices.keys.join ' - '} }
    @room.each_message do |message|
      choice = choices.select{|k,v| k.to_s == message}.values.first
      return choice if choice
    end
  end
end

#enqueue(message, choices = {}) ⇒ Object



18
19
20
# File 'lib/pc/interfaces/campfire.rb', line 18

def enqueue(message, choices = {})
  (@actions ||= []).push message: message, choices: choices
end

#run(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/pc/interfaces/campfire.rb', line 9

def run(options = {})
  @room ||= Nico::Room.new options
  while action = (@actions ||= []).shift
    say action[:message]
    choose(action[:choices]).call
    run
  end
end

#say(message) ⇒ Object



22
23
24
# File 'lib/pc/interfaces/campfire.rb', line 22

def say(message)
  @room.say message
end