ruboty-brain_dictionary 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b780ed6cc5de570a8f45b428f9b35fc35cb6876
4
+ data.tar.gz: 94c2f8868fcd424c777067bf9ac43d87ef6527d9
5
+ SHA512:
6
+ metadata.gz: aca7fc41970bb9f329c15008224856e800f552a63af103abf236559d5ae6f746c2ed6af40701d62e19b4b5135cf423597429921c07f8c1e271c31e5c7e88331e
7
+ data.tar.gz: ff8aa73dd4bb20411785d8740e59daffd0ed3d95b51478388e9cc03bdca52f3c9bb8705c08d737f96ee54d066f381f4b029bf0c2a291dae5f965f74e6ce10501
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-brain_dictionary.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 tbpgr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Ruboty::BrainDictionary
2
+
3
+ An Ruboty Handler + Actions to learn your key-value into brain.
4
+
5
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
6
+
7
+ ## :arrow_down: Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-brain_dictionary'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## :cl: Commands
20
+
21
+ |Command|Pattern|Description|
22
+ |:--|:--|:--|
23
+ |[learn](#learn)|/learn\s\{1\}?(?<key>.+)?\s\{1\}(?<value>.+)?\z/|learn key-value|
24
+ |[remember](#remember)|/remember\s\{0,1\}?(?<key>.+)?\z/|remember your ruboty brain_dictionary that match your keys.|
25
+ |[dict](#dict)|/dict\s\{1\}?(?<key>.+)?\z/|show your value from brain.|
26
+ |[forget](#forget)|/forget\s\{0,1\}?(?<key>.+)?\z/|forget your ruboty brain_dictionary that match your key.|
27
+
28
+ ## :scroll: Usage
29
+ ### learn
30
+ * learn key-value
31
+
32
+ ~~~
33
+ >ruboty learn tu ka
34
+ >ruboty remember tu
35
+ tu,ka
36
+ ~~~
37
+
38
+ ### remember
39
+ * remember your ruboty brain_dictionary that match with your keys.
40
+
41
+ ~~~
42
+ >ruboty learn hoge hoge-value
43
+ >ruboty learn hige hige-value
44
+ >ruboty learn hage hage-value
45
+ >ruboty learn hoo bar
46
+
47
+ # remember all
48
+ >ruboty remember
49
+ hage,hage-value
50
+ hige,hige-value
51
+ hoge,hoge-value
52
+ hoo,bar
53
+
54
+ # remember match keys
55
+ >ruboty remember ge
56
+ hage,hage-value
57
+ hige,hige-value
58
+ hoge,hoge-value
59
+
60
+ # remember match key
61
+ >ruboty remember hoo
62
+ hoo,bar
63
+ ~~~
64
+
65
+ ### dict
66
+
67
+ ~~~
68
+ >ruboty learn hoge hoge-value
69
+ >ruboty learn hige hige-value
70
+ >ruboty learn hage hage-value
71
+ >ruboty learn hoo bar
72
+ >dict hoge
73
+ hoge-value
74
+ >dict hoo
75
+ hoo-value
76
+ >dict hogea
77
+ >
78
+ ~~~
79
+
80
+ ### forget
81
+ * forget your ruboty brain_dictionary that match with your key.
82
+
83
+ ~~~
84
+ >ruboty learn hoge hoge-value
85
+ >ruboty learn hige hige-value
86
+ >ruboty learn hage hage-value
87
+ >ruboty learn hoo bar
88
+
89
+ # remember all
90
+ >ruboty remember
91
+ hage,hage-value
92
+ hige,hige-value
93
+ hoge,hoge-value
94
+ hoo,bar
95
+
96
+ # forget hoo & confirm
97
+ >ruboty forget hoo
98
+ success delete key 'hoo'
99
+
100
+ >ruboty remember
101
+ hage,hage-value
102
+ hige,hige-value
103
+ hoge,hoge-value
104
+
105
+ # forget hoo ( not exist )
106
+ >ruboty forget hoo
107
+ no key 'hoo'
108
+ ~~~
109
+
110
+ ## :earth_asia: ENV
111
+
112
+ |Name|Description|
113
+ |:--|:--|
114
+ |--|--|
115
+
116
+ ## :couple: Dependency
117
+
118
+ |Name|Description|
119
+ |:--|:--|
120
+ |--|--|
121
+
122
+ ## :two_men_holding_hands: Contributing :two_women_holding_hands:
123
+
124
+ 1. Fork it ( https://github.com/tbpgr/ruboty-brain_dictionary/fork )
125
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
126
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
127
+ 4. Push to the branch (`git push origin my-new-feature`)
128
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,8 @@
1
+ require 'ruboty/brain_dictionary/version'
2
+ require 'ruboty/handlers/brain_dictionary'
3
+
4
+ module Ruboty
5
+ module BrainDictionary
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module BrainDictionaryHelper
2
+ module_function
3
+ NAMESPACE = 'dictionary'
4
+
5
+ def dictionary(robot)
6
+ robot.brain.data[NAMESPACE] ||= {}
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ require 'ruboty/brain_dictionary/actions/brain_dictionary_helper'
2
+
3
+ module Ruboty
4
+ module BrainDictionary
5
+ module Actions
6
+ class Dict < Ruboty::Actions::Base
7
+ def call
8
+ dict_message = dict
9
+ return if dict_message.empty?
10
+ message.reply(dict_message)
11
+ end
12
+
13
+ private
14
+
15
+ def dict
16
+ d = BrainDictionaryHelper.dictionary(message.robot)
17
+ key = message[:key]
18
+ return if (key.nil? || key.empty?)
19
+ d.key?(key) ? d[key] : ''
20
+ rescue => e
21
+ e.message
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruboty/brain_dictionary/actions/brain_dictionary_helper'
2
+
3
+ module Ruboty
4
+ module BrainDictionary
5
+ module Actions
6
+ class Forget < Ruboty::Actions::Base
7
+ def call
8
+ message.reply(forget)
9
+ end
10
+
11
+ private
12
+
13
+ def forget
14
+ dict = BrainDictionaryHelper.dictionary(message.robot)
15
+ key = message[:key]
16
+ ret = dict.delete(key)
17
+ ret.nil? ? "no key '#{key}'" : "success delete key '#{key}'"
18
+ rescue => e
19
+ e.message
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruboty/brain_dictionary/actions/brain_dictionary_helper'
2
+
3
+ module Ruboty
4
+ module BrainDictionary
5
+ module Actions
6
+ class Learn < Ruboty::Actions::Base
7
+ def call
8
+ message.reply(learn)
9
+ end
10
+
11
+ private
12
+
13
+ def learn
14
+ dict = BrainDictionaryHelper.dictionary(message.robot)
15
+ key = message[:key]
16
+ dict[key] = message[:value]
17
+ "I learn #{key}:#{message[:value]}"
18
+ rescue => e
19
+ e.message
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruboty/brain_dictionary/actions/brain_dictionary_helper'
2
+
3
+ module Ruboty
4
+ module BrainDictionary
5
+ module Actions
6
+ class Remember < Ruboty::Actions::Base
7
+ def call
8
+ message.reply(remember)
9
+ end
10
+
11
+ private
12
+
13
+ def remember
14
+ dict = BrainDictionaryHelper.dictionary(message.robot)
15
+ key = message[:key]
16
+ ret = (key.nil? || key.empty?) ? dict : dict.select { |k, v|k.include?(key) }
17
+ ret.sort.map { |k, v| "#{k},#{v}" }.join("\n")
18
+ rescue => e
19
+ e.message
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module BrainDictionary
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'ruboty/brain_dictionary/actions/learn'
2
+ require 'ruboty/brain_dictionary/actions/remember'
3
+ require 'ruboty/brain_dictionary/actions/dict'
4
+ require 'ruboty/brain_dictionary/actions/forget'
5
+
6
+ module Ruboty
7
+ module Handlers
8
+ class BrainDictionary < Base
9
+ on(/learn\s{1}(?<key>.+)?\s{1}(?<value>.+)?\z/,
10
+ name: 'learn',
11
+ description: 'learn key-value'
12
+ )
13
+ on(/remember\s{0,1}(?<key>.+)?\z/,
14
+ name: 'remember',
15
+ description: 'remember your ruboty brain_dictionary that match with your keys.'
16
+ )
17
+ on(/dict\s{1}(?<key>.+)?\z/,
18
+ name: 'dict',
19
+ description: 'show your value from brain.',
20
+ all: true
21
+ )
22
+ on(/forget\s{0,1}(?<key>.+)?\z/,
23
+ name: 'forget',
24
+ description: 'forget your ruboty brain_dictionary that match with your key.'
25
+ )
26
+
27
+ def learn(message)
28
+ Ruboty::BrainDictionary::Actions::Learn.new(message).call
29
+ end
30
+
31
+ def remember(message)
32
+ Ruboty::BrainDictionary::Actions::Remember.new(message).call
33
+ end
34
+
35
+ def dict(message)
36
+ Ruboty::BrainDictionary::Actions::Dict.new(message).call
37
+ end
38
+
39
+ def forget(message)
40
+ Ruboty::BrainDictionary::Actions::Forget.new(message).call
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/brain_dictionary/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-brain_dictionary'
8
+ spec.version = Ruboty::BrainDictionary::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.summary = 'An Ruboty Handler + Actions to learn your key-value into brain.'
12
+ spec.description = 'An Ruboty Handler + Actions to learn your key-value into brain.'
13
+ spec.homepage = 'https://github.com/tbpgr/ruboty-ruboty-brain'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'ruboty'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-brain_dictionary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: An Ruboty Handler + Actions to learn your key-value into brain.
56
+ email:
57
+ - tbpgr@tbpgr.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/ruboty/brain_dictionary.rb
68
+ - lib/ruboty/brain_dictionary/actions/brain_dictionary_helper.rb
69
+ - lib/ruboty/brain_dictionary/actions/dict.rb
70
+ - lib/ruboty/brain_dictionary/actions/forget.rb
71
+ - lib/ruboty/brain_dictionary/actions/learn.rb
72
+ - lib/ruboty/brain_dictionary/actions/remember.rb
73
+ - lib/ruboty/brain_dictionary/version.rb
74
+ - lib/ruboty/handlers/brain_dictionary.rb
75
+ - ruboty-brain_dictionary.gemspec
76
+ homepage: https://github.com/tbpgr/ruboty-ruboty-brain
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.3.0
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: An Ruboty Handler + Actions to learn your key-value into brain.
100
+ test_files: []
101
+ has_rdoc: