Class: Kanal::Interfaces::SimpleCli::SimpleCliInterface

Inherits:
Core::Interfaces::Interface show all
Defined in:
lib/kanal/interfaces/simple_cli/simple_cli_interface.rb

Overview

This interface provides input/output with the cli

Instance Attribute Summary

Attributes inherited from Core::Interfaces::Interface

#core

Instance Method Summary collapse

Methods inherited from Core::Interfaces::Interface

#consume_input, #consume_output, #modify_core, #router

Constructor Details

#initialize(core) ⇒ SimpleCliInterface

<Description>

Parameters:



16
17
18
19
20
21
22
23
# File 'lib/kanal/interfaces/simple_cli/simple_cli_interface.rb', line 16

def initialize(core)
  super

  # For simple cli we need body
  @core.register_plugin Kanal::Plugins::Batteries::BatteriesPlugin.new

  @core.register_output_parameter :quit
end

Instance Method Details

#startObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kanal/interfaces/simple_cli/simple_cli_interface.rb', line 25

def start
  loop do
    puts ">>>"
    input = @core.create_input
    input.body = gets

    output = router.create_output_for_input input

    if output.quit
      puts "Undestood! Quitting"
      break
    end

    puts "[bot]: #{output.body}"
  rescue Interrupt
    puts "Got it! Hard stop. Bye bye!"
    break
  end

  puts "End of conversation!"
end

#stopObject



47
# File 'lib/kanal/interfaces/simple_cli/simple_cli_interface.rb', line 47

def stop; end