ruboty-ume 1.0.0

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: 37fe750f47988a06a682a9615da8fd1719bc0eca
4
+ data.tar.gz: a139e292047002e78dc49b790cdf0a6ba3849b53
5
+ SHA512:
6
+ metadata.gz: 275f5c1e016ffada637fc9c7ebd2f5fce4abc428775f27a6489b2f7df6e34f7274da49b7e02cb27ea04fe44d28a97d0135331c777b9ab27465edcb047e79c7eb
7
+ data.tar.gz: 6b5289288b3f7f4f969f26d04cc9959801ce16652f61ab0358038f88ae1011814dd1fd7702c122c47d70cd7d53ea21ece49fbae4d99d6c444ae02352c8628a7a
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'simplecov', '~> 0.8.2'
5
+ group :test do
6
+ gem 'coveralls', require: false
7
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 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,57 @@
1
+ # Ruboty::Ume
2
+
3
+ An Ruboty Handler + Actions to output N line messages.
4
+
5
+ [![Build Status](https://travis-ci.org/tbpgr/ruboty-ume.png?branch=master)](https://travis-ci.org/tbpgr/ruboty-ume)
6
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/ruboty-ume/badge.png)](https://coveralls.io/r/tbpgr/ruboty-ume)
7
+
8
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ruboty-ume'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ruboty-ume
25
+
26
+ ## Usage
27
+ ### Ume empty messages
28
+
29
+ ~~~
30
+ now editing...
31
+ ~~~
32
+
33
+ ### Umec specific text messages
34
+
35
+ ~~~
36
+ now editing...
37
+ ~~~
38
+
39
+ ## ENV
40
+ nothing
41
+
42
+ ## Screenshot
43
+ nothing
44
+
45
+ ## Dependency
46
+ nothing
47
+
48
+ ## Reference
49
+ nothing
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/tbpgr/ruboty-ume/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
@@ -0,0 +1,29 @@
1
+ require 'ruboty/ume/actions/ume'
2
+ require 'ruboty/ume/actions/umec'
3
+
4
+ module Ruboty
5
+ module Handlers
6
+ # Ume
7
+ class Ume < Base
8
+ on(
9
+ /ume (?<count>.*?)\z/,
10
+ name: 'ume',
11
+ description: 'output empty message N lines (<count> times)'
12
+ )
13
+
14
+ on(
15
+ /umec (?<text>.+?) (?<count>.*?)\z/,
16
+ name: 'umec',
17
+ description: 'output <text> message N lines (<count> times)'
18
+ )
19
+
20
+ def ume(message)
21
+ Ruboty::Ume::Actions::Ume.new(message).call
22
+ end
23
+
24
+ def umec(message)
25
+ Ruboty::Ume::Actions::Umec.new(message).call
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/ruboty/ume.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'ruboty'
2
+ require 'ruboty/ume/version'
3
+ require 'ruboty/handlers/ume'
4
+
5
+ module Ruboty
6
+ # Ume
7
+ module Ume
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Ruboty
2
+ module Ume
3
+ # Actions
4
+ module Actions
5
+ DEFAULT_COUNT = 15
6
+
7
+ def normalize_count(repeat_count)
8
+ return DEFAULT_COUNT if repeat_count.nil?
9
+ Integer(repeat_count)
10
+ end
11
+
12
+ module_function :normalize_count
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require 'ruboty/ume/actions'
2
+
3
+ module Ruboty
4
+ module Ume
5
+ module Actions
6
+ # Ume
7
+ class Ume < Ruboty::Actions::Base
8
+ def call
9
+ message.reply(ume)
10
+ end
11
+
12
+ private
13
+
14
+ def ume
15
+ repeat_count = Ruboty::Ume::Actions.normalize_count(message[:count])
16
+ "\n" * repeat_count
17
+ rescue => e
18
+ e.message
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ require 'ruboty/ume/actions'
2
+
3
+ module Ruboty
4
+ module Ume
5
+ # Actions
6
+ module Actions
7
+ DEFAULT_TEXT = '--'
8
+
9
+ # Umec
10
+ class Umec < Ruboty::Actions::Base
11
+ def call
12
+ message.reply(umec)
13
+ end
14
+
15
+ private
16
+
17
+ def umec
18
+ repeat_count = Ruboty::Ume::Actions.normalize_count(message[:count])
19
+ text = normalize_text(message[:text])
20
+ "#{text}\n" * repeat_count
21
+ rescue => e
22
+ e.message
23
+ end
24
+
25
+ def normalize_text(text)
26
+ return DEFAULT_TEXT if text.nil?
27
+ return DEFAULT_TEXT if text.empty?
28
+ return DEFAULT_TEXT unless text.is_a?(String)
29
+ text
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ module Ruboty
2
+ # Ume
3
+ module Ume
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/ume/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-ume'
8
+ spec.version = Ruboty::Ume::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.summary = 'An Ruboty Handler + Actions to output N line messages.'
12
+ spec.description = 'An Ruboty Handler + Actions to output N line messages.'
13
+ spec.homepage = 'https://github.com/tbpgr/ruboty-ume'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'ruboty'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'simplecov'
27
+ end
@@ -0,0 +1,121 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty/handlers/ume'
4
+ require 'ruboty/ume/actions/ume'
5
+ require 'ruboty/ume/actions/umec'
6
+
7
+ describe Ruboty::Handlers::Ume do
8
+ context :ume do
9
+ let(:robot) do
10
+ Ruboty::Robot.new
11
+ end
12
+
13
+ let(:ume) do
14
+ Ruboty::Ume::Actions::Ume
15
+ end
16
+
17
+ cases = [
18
+ {
19
+ case_no: 1,
20
+ case_title: 'hit message case',
21
+ body: 'ruboty ume 10',
22
+ expected: 'expected message',
23
+ hit: true
24
+ },
25
+ {
26
+ case_no: 2,
27
+ case_title: 'not hit message case',
28
+ body: 'ruboty umeume 10',
29
+ hit: false
30
+ }
31
+ ]
32
+
33
+ cases.each do |c|
34
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
35
+ begin
36
+ case_before c
37
+
38
+ # -- given --
39
+ allow_any_instance_of(ume).to receive(:ume).and_return(c[:expected])
40
+
41
+ # -- then --
42
+ if c[:hit]
43
+ Ruboty.logger.should_receive(:info).with(c[:expected])
44
+ else
45
+ Ruboty.logger.should_not_receive(:info)
46
+ end
47
+
48
+ # -- when --
49
+ robot.receive(body: c[:body], from: 'sender', to: 'channel')
50
+ ensure
51
+ case_after c
52
+ end
53
+ end
54
+
55
+ def case_before(_c)
56
+ # implement each case before
57
+ end
58
+
59
+ def case_after(_c)
60
+ # implement each case after
61
+ end
62
+ end
63
+ end
64
+
65
+ context :umec do
66
+ let(:robot) do
67
+ Ruboty::Robot.new
68
+ end
69
+
70
+ let(:umec) do
71
+ Ruboty::Ume::Actions::Umec
72
+ end
73
+
74
+ cases = [
75
+ {
76
+ case_no: 1,
77
+ case_title: 'hit message case',
78
+ body: 'ruboty umec hoge 10',
79
+ expected: 'expected message',
80
+ hit: true
81
+ },
82
+ {
83
+ case_no: 2,
84
+ case_title: 'not hit message case',
85
+ body: 'ruboty umecumec hoge 10',
86
+ hit: false
87
+ }
88
+ ]
89
+
90
+ cases.each do |c|
91
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
92
+ begin
93
+ case_before c
94
+
95
+ # -- given --
96
+ allow_any_instance_of(umec).to receive(:umec).and_return(c[:expected])
97
+
98
+ # -- then --
99
+ if c[:hit]
100
+ Ruboty.logger.should_receive(:info).with(c[:expected])
101
+ else
102
+ Ruboty.logger.should_not_receive(:info)
103
+ end
104
+
105
+ # -- when --
106
+ robot.receive(body: c[:body], from: 'sender', to: 'channel')
107
+ ensure
108
+ case_after c
109
+ end
110
+ end
111
+
112
+ def case_before(_c)
113
+ # implement each case before
114
+ end
115
+
116
+ def case_after(_c)
117
+ # implement each case after
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty/ume/actions/ume'
4
+
5
+ describe Ruboty::Ume::Actions::Ume do
6
+ context :ume do
7
+ let(:message) do
8
+ # Dummy Message
9
+ class Message < Hash
10
+ def reply(message)
11
+ message
12
+ end
13
+ end
14
+ Message.new
15
+ end
16
+
17
+ cases = [
18
+ {
19
+ case_no: 1,
20
+ case_title: '10 count case',
21
+ count: '10',
22
+ expected: "\n\n\n\n\n\n\n\n\n\n"
23
+ },
24
+ {
25
+ case_no: 2,
26
+ case_title: 'no count case',
27
+ expected: "\n" * Ruboty::Ume::Actions::DEFAULT_COUNT
28
+ },
29
+ {
30
+ case_no: 3,
31
+ case_title: 'not Fixnum count case',
32
+ count: 'hoge',
33
+ expected: "invalid value for Integer(): \"hoge\"",
34
+ expect_error: true
35
+ }
36
+ ]
37
+
38
+ cases.each do |c|
39
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
40
+ begin
41
+ case_before c
42
+
43
+ # -- given --
44
+ message[:count] = c[:count] if c[:count]
45
+ action = Ruboty::Ume::Actions::Ume.new(message)
46
+
47
+ # -- when --
48
+ actual = action.send(:ume)
49
+
50
+ # -- then --
51
+ expect(actual).to eq(c[:expected])
52
+ ensure
53
+ case_after c
54
+ end
55
+ end
56
+
57
+ def case_before(_c)
58
+ # implement each case before
59
+ end
60
+
61
+ def case_after(_c)
62
+ # implement each case after
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty/ume/actions/umec'
4
+
5
+ describe Ruboty::Ume::Actions::Umec do
6
+ context :ume do
7
+ let(:message) do
8
+ # Dummy Message
9
+ class Message < Hash
10
+ def reply(message)
11
+ message
12
+ end
13
+ end
14
+ Message.new
15
+ end
16
+
17
+ cases = [
18
+ {
19
+ case_no: 1,
20
+ case_title: '10 count with hoge text case',
21
+ text: 'hoge',
22
+ count: 10,
23
+ expected: "hoge\nhoge\nhoge\nhoge\nhoge\nhoge\nhoge\nhoge\nhoge\nhoge\n"
24
+ },
25
+ {
26
+ case_no: 2,
27
+ case_title: 'no count hoge text case',
28
+ text: 'hoge',
29
+ expected: "hoge\n" * Ruboty::Ume::Actions::DEFAULT_COUNT
30
+ },
31
+ {
32
+ case_no: 3,
33
+ case_title: 'not Fixnum count case',
34
+ text: 'hoge',
35
+ count: 'hoge',
36
+ expected: "invalid value for Integer(): \"hoge\""
37
+ },
38
+ {
39
+ case_no: 4,
40
+ case_title: 'nil text case',
41
+ count: 2,
42
+ expected: "--\n" * 2
43
+ },
44
+ {
45
+ case_no: 5,
46
+ case_title: 'empty text case',
47
+ text: '',
48
+ count: 2,
49
+ expected: "--\n" * 2
50
+ }
51
+ ]
52
+
53
+ cases.each do |c|
54
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
55
+ begin
56
+ case_before c
57
+
58
+ # -- given --
59
+ message[:count] = c[:count] if c[:count]
60
+ message[:text] = c[:text] if c[:text]
61
+ action = Ruboty::Ume::Actions::Umec.new(message)
62
+
63
+ # -- when --
64
+ actual = action.send(:umec)
65
+
66
+ # -- then --
67
+ expect(actual).to eq(c[:expected])
68
+ ensure
69
+ case_after c
70
+ end
71
+ end
72
+
73
+ def case_before(_c)
74
+ # implement each case before
75
+ end
76
+
77
+ def case_after(_c)
78
+ # implement each case after
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
12
+ require 'ruboty/ume'
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-ume
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
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
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: An Ruboty Handler + Actions to output N line messages.
84
+ email:
85
+ - tbpgr@tbpgr.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .coveralls.yml
91
+ - .gitignore
92
+ - .rspec
93
+ - .travis.yml
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/ruboty/handlers/ume.rb
99
+ - lib/ruboty/ume.rb
100
+ - lib/ruboty/ume/actions.rb
101
+ - lib/ruboty/ume/actions/ume.rb
102
+ - lib/ruboty/ume/actions/umec.rb
103
+ - lib/ruboty/ume/version.rb
104
+ - ruboty-ume.gemspec
105
+ - spec/ruboty/handlers/ume_spec.rb
106
+ - spec/ruboty/ume/actions/ume_spec.rb
107
+ - spec/ruboty/ume/actions/umec_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: https://github.com/tbpgr/ruboty-ume
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.3.0
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: An Ruboty Handler + Actions to output N line messages.
133
+ test_files:
134
+ - spec/ruboty/handlers/ume_spec.rb
135
+ - spec/ruboty/ume/actions/ume_spec.rb
136
+ - spec/ruboty/ume/actions/umec_spec.rb
137
+ - spec/spec_helper.rb