ego 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/.yardopts +1 -0
- data/README.md +40 -35
- data/ego.gemspec +1 -0
- data/lib/ego.rb +40 -3
- data/lib/ego/capability.rb +30 -0
- data/lib/ego/filesystem.rb +58 -29
- data/lib/ego/handler.rb +62 -59
- data/lib/ego/options.rb +14 -2
- data/lib/ego/plugin.rb +58 -0
- data/lib/ego/plugins/capabilities.rb +17 -0
- data/lib/ego/plugins/fallback.rb +36 -0
- data/lib/ego/plugins/robot_io.rb +16 -0
- data/lib/ego/plugins/social.rb +19 -0
- data/lib/ego/plugins/system.rb +21 -0
- data/lib/ego/printer.rb +95 -0
- data/lib/ego/robot.rb +157 -10
- data/lib/ego/robot_error.rb +8 -0
- data/lib/ego/runner.rb +51 -20
- data/lib/ego/version.rb +2 -1
- data/spec/ego/capability_spec.rb +23 -0
- data/spec/ego/handler_spec.rb +63 -0
- data/spec/ego/options_spec.rb +23 -13
- data/spec/ego/plugin_spec.rb +68 -0
- data/spec/ego/printer_spec.rb +120 -0
- data/spec/ego/robot_error_spec.rb +12 -0
- data/spec/ego/robot_spec.rb +283 -26
- metadata +36 -10
- data/lib/ego/formatter.rb +0 -36
- data/lib/ego/handler/default.rb +0 -31
- data/lib/ego/handler/echo.rb +0 -9
- data/lib/ego/handler/greet.rb +0 -17
- data/lib/ego/handler/handlers.rb +0 -15
- data/lib/ego/handler/self.rb +0 -9
- data/lib/ego/listener.rb +0 -25
- data/spec/ego/formatter_spec.rb +0 -53
data/lib/ego/handler/default.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
Ego::Handler.register do |handler|
|
2
|
-
handler.description = 'let you know when I don\'t understand something'
|
3
|
-
|
4
|
-
handler.listen /(.*)/, priority: 0
|
5
|
-
|
6
|
-
handler.run do |robot, params|
|
7
|
-
robot.respond %Q{I don't understand "#{params[0]}".}
|
8
|
-
|
9
|
-
handler_slug = params[0]
|
10
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
11
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
-
.tr('\'', '')
|
13
|
-
.gsub(/\W+/, '_')
|
14
|
-
.gsub(/__+/, '_')
|
15
|
-
.downcase
|
16
|
-
|
17
|
-
STDERR.puts <<-EOF
|
18
|
-
Perhaps add a handler to #{Ego::Filesystem.config "handler/#{handler_slug}.rb"}:
|
19
|
-
|
20
|
-
Ego::Handler.register do |handler|
|
21
|
-
handler.description = 'do something'
|
22
|
-
|
23
|
-
handler.listen /^#{params[0]}$/
|
24
|
-
|
25
|
-
handler.run do |robot, params|
|
26
|
-
# ...
|
27
|
-
end
|
28
|
-
end
|
29
|
-
EOF
|
30
|
-
end
|
31
|
-
end
|
data/lib/ego/handler/echo.rb
DELETED
data/lib/ego/handler/greet.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
Ego::Handler.register do |handler|
|
2
|
-
handler.description = 'greet you'
|
3
|
-
|
4
|
-
handler.listen /^(hello|salve|ave|hi|hey|ciao|hej)/i, priority: 3
|
5
|
-
|
6
|
-
handler.run do |robot|
|
7
|
-
robot.respond [
|
8
|
-
'Hello.',
|
9
|
-
'Salve tu.',
|
10
|
-
'Ave.',
|
11
|
-
'Hi.',
|
12
|
-
'Hey.',
|
13
|
-
'Ciao.',
|
14
|
-
'Hej.',
|
15
|
-
].sample
|
16
|
-
end
|
17
|
-
end
|
data/lib/ego/handler/handlers.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative '../handler'
|
2
|
-
|
3
|
-
Ego::Handler.register do |handler|
|
4
|
-
handler.description = 'tell you what I can do'
|
5
|
-
|
6
|
-
handler.listen /^(show me|show|tell me|list)\s+(handlers|what you can do|what (?:you are|you're) able to do|what you do|what (?:queries )?you (?:can )?understand)$/i
|
7
|
-
handler.listen /^what (?:can you|are you able to|do you) (?:do|handle|understand)\??$/i
|
8
|
-
handler.listen /^help/i, priority: 2
|
9
|
-
|
10
|
-
handler.run do |robot|
|
11
|
-
robot.respond 'I know how to...'
|
12
|
-
|
13
|
-
Ego::Formatter.print_handlers Ego::Handler.handlers
|
14
|
-
end
|
15
|
-
end
|
data/lib/ego/handler/self.rb
DELETED
data/lib/ego/listener.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Ego
|
2
|
-
# Listeners map user queries to handlers.
|
3
|
-
class Listener
|
4
|
-
include Comparable
|
5
|
-
|
6
|
-
attr_accessor :pattern, :priority, :parser, :handler
|
7
|
-
|
8
|
-
def initialize(pattern, priority, parser, handler)
|
9
|
-
@pattern = pattern
|
10
|
-
@priority = priority
|
11
|
-
@parser = parser
|
12
|
-
@handler = handler
|
13
|
-
end
|
14
|
-
|
15
|
-
def <=> other
|
16
|
-
@priority <=> other.priority
|
17
|
-
end
|
18
|
-
|
19
|
-
def match(query)
|
20
|
-
return false unless (matches = @pattern.match(query))
|
21
|
-
|
22
|
-
@parser.call matches
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/ego/formatter_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'ego/formatter'
|
2
|
-
|
3
|
-
module Ego
|
4
|
-
RSpec.describe Formatter do
|
5
|
-
before(:example) do
|
6
|
-
@formatter = Formatter.new
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#puts' do
|
10
|
-
it 'prints the message to STDOUT with newline' do
|
11
|
-
expect { @formatter.puts('X') }.to output("X\n").to_stdout
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#robot_respond' do
|
16
|
-
it 'prints the message to STDOUT with color and newline' do
|
17
|
-
expect { @formatter.robot_respond('X') }.to output("\e[0;33;49mX\e[0m\n").to_stdout
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'accepts placeholders and replacement strings' do
|
21
|
-
expect { @formatter.robot_respond('Hello, %s.', 'world') }.to output("\e[0;33;49mHello, world.\e[0m\n").to_stdout
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'capitalizes the first letter of the message' do
|
25
|
-
expect { @formatter.robot_respond('foo') }.to output("\e[0;33;49mFoo\e[0m\n").to_stdout
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'capitalizes the first letter of the message when it is a replacement' do
|
29
|
-
expect { @formatter.robot_respond('%s', 'foo') }.to output("\e[0;33;49mFoo\e[0m\n").to_stdout
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'does not lowercase subsequent letters' do
|
33
|
-
expect { @formatter.robot_respond('foO') }.to output("\e[0;33;49mFoO\e[0m\n").to_stdout
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '#robot_action' do
|
38
|
-
it 'prints the message to STDOUT with color and formatting' do
|
39
|
-
expect { @formatter.robot_action('FOO') }.to output("\e[0;35;49m*FOO*\e[0m\n").to_stdout
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#debug' do
|
44
|
-
it 'prints the message to STDERR with newline' do
|
45
|
-
expect { @formatter.debug('FOO') }.to output("FOO\n").to_stderr
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'accepts placeholders and replacement strings' do
|
49
|
-
expect { @formatter.debug('Hello, %s.', 'world') }.to output("Hello, world.\n").to_stderr
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|