Module: Pc::Campfire
- Includes:
- Interface
- Defined in:
- lib/pc/interfaces/campfire.rb
Instance Method Summary collapse
- #choose(choices = {}) ⇒ Object
- #enqueue(message, choices = {}) ⇒ Object
- #run(options = {}) ⇒ Object
- #say(message) ⇒ Object
Methods included from Interface
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. do || choice = choices.select{|k,v| k.to_s == }.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(, choices = {}) (@actions ||= []).push 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( = {}) @room ||= Nico::Room.new 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() @room.say end |