Class: Blinkman::Adapter::Shell

Inherits:
Base
  • Object
show all
Defined in:
lib/blinkman/adapter/shell.rb

Constant Summary collapse

PROMPT =
'> '

Instance Attribute Summary collapse

Attributes inherited from Base

#bot

Instance Method Summary collapse

Methods inherited from Base

inherited

Constructor Details

#initialize(bot) ⇒ Shell

Returns a new instance of Shell.



10
11
12
13
# File 'lib/blinkman/adapter/shell.rb', line 10

def initialize(bot)
  @stopped = false
  super
end

Instance Attribute Details

#stoppedObject (readonly)

Returns the value of attribute stopped.



6
7
8
# File 'lib/blinkman/adapter/shell.rb', line 6

def stopped
  @stopped
end

Instance Method Details

#listenObject



15
16
17
18
19
# File 'lib/blinkman/adapter/shell.rb', line 15

def listen
  while ! stopped
    bot.on_receive(read)
  end
end

#readObject



21
22
23
24
25
26
27
# File 'lib/blinkman/adapter/shell.rb', line 21

def read
  Message::Shell.new(
    Readline.readline(PROMPT, true).tap do |line|
      @stopped = (line == 'exit')
    end
  )
end