aun 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +172 -0
- data/Rakefile +8 -0
- data/aun.gemspec +24 -0
- data/bin/aun +68 -0
- data/images/aun.gif +0 -0
- data/lib/aun/default_messages.rb +10 -0
- data/lib/aun/definition_manager.rb +33 -0
- data/lib/aun/finder.rb +30 -0
- data/lib/aun/message.rb +49 -0
- data/lib/aun/message_formatter.rb +28 -0
- data/lib/aun/version.rb +3 -0
- data/lib/aun_core.rb +9 -0
- data/rubocop-todo.yml +49 -0
- data/spec/aun/finder_spec.rb +315 -0
- data/spec/aun/message_formatter_spec.rb +183 -0
- data/spec/aun/message_spec.rb +273 -0
- data/spec/spec_helper.rb +16 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75493ad2bc8313a55e259705ab7b84fcd5fad2ae
|
4
|
+
data.tar.gz: f69acf2389fed37aa47c324a3e8ecf523b24b723
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee910d95a60feb90e1561664cb747bdd5d37f80b372fcd9b89eccd1a216e671c7915587e33ee59db9c18351bed6d9e749334f93141a77395d29a375e495bd933
|
7
|
+
data.tar.gz: 1b1b57cacdc46a2782a07a3fd1deb4e33752dde16fe7b3df3d496adcb0e476e99bd35f8bf29bc443df84d5096edf068496c5174bf21609a4685d94bc066b65a4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: rubocop-todo.yml
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
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,172 @@
|
|
1
|
+
# Aun
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/aun.svg)](http://badge.fury.io/rb/aun)
|
4
|
+
[![Build Status](https://travis-ci.org/tbpgr/aun.png?branch=master)](https://travis-ci.org/tbpgr/aun)
|
5
|
+
|
6
|
+
Aun [阿吽] は「阿吽の呼吸」、「ツー」といえば「カー」など
|
7
|
+
A に呼応して B のメッセージを返却するためのツールです。
|
8
|
+
これといって有効な用途はありません。ジョークのたぐいです。
|
9
|
+
|
10
|
+
## Demo
|
11
|
+
![demo](./images/aun.gif)
|
12
|
+
|
13
|
+
## Target Versions
|
14
|
+
* Ruby 2.0
|
15
|
+
* Ruby 2.1
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'aun'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install aun
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
### help
|
35
|
+
~~~bash
|
36
|
+
$ aun help
|
37
|
+
Commands:
|
38
|
+
aun help [COMMAND] # Describe available commands or one specific command
|
39
|
+
aun init # Generate Aundefinition.csv template
|
40
|
+
aun inspect # inspect
|
41
|
+
aun inspect_all # inspect_all
|
42
|
+
aun owner_talk # owner_talk
|
43
|
+
aun talk # talk
|
44
|
+
aun talk_with_origin # talk_with_origin
|
45
|
+
aun version # version
|
46
|
+
~~~
|
47
|
+
|
48
|
+
## デフォルトの阿吽メッセージ
|
49
|
+
下記をデフォルトとして登録してあります。
|
50
|
+
|
51
|
+
[default_messages.rb](./lib/aun/default_messages.rb)
|
52
|
+
|
53
|
+
## CLI Tool 「 aun 」の利用法
|
54
|
+
### talk
|
55
|
+
~~~bash
|
56
|
+
$ aun talk 君名前は?
|
57
|
+
田原年彦
|
58
|
+
~~~
|
59
|
+
|
60
|
+
### owner_talk
|
61
|
+
~~~bash
|
62
|
+
$ aun owner_talk 君名前は?
|
63
|
+
田原年彦「田原年彦」
|
64
|
+
~~~
|
65
|
+
|
66
|
+
### talk_with_origin
|
67
|
+
~~~bash
|
68
|
+
$ aun talk_with_origin 君名前は?
|
69
|
+
田原年彦「田原年彦」 from [行け!稲中卓球部]
|
70
|
+
~~~
|
71
|
+
|
72
|
+
### inspect
|
73
|
+
~~~bash
|
74
|
+
$ aun inspect ぬるぽ
|
75
|
+
阿:ぬるぽ 吽:ガッ 発言者:unknown 原典:unknown, ユーザー定義:false
|
76
|
+
~~~
|
77
|
+
|
78
|
+
### init
|
79
|
+
ユーザー定義データ登録用のcsvテンプレート生成
|
80
|
+
|
81
|
+
~~~bash
|
82
|
+
$ aun init
|
83
|
+
$ cat Aundefinition.csv
|
84
|
+
阿(例:海賊王に),吽(例:俺はなる),発言者(モンキー・D・ルフィ※不明の場合は空欄に),原典(One Piece※不明の場合は空欄に)
|
85
|
+
~~~
|
86
|
+
|
87
|
+
ユーザー定義データを編集して、 talk を呼び出してみます。
|
88
|
+
|
89
|
+
* Aundefinition.csv
|
90
|
+
|
91
|
+
~~~
|
92
|
+
海賊王に,俺はなる,モンキー・D・ルフィ,One Piece
|
93
|
+
~~~
|
94
|
+
|
95
|
+
* 実行
|
96
|
+
|
97
|
+
~~~bash
|
98
|
+
$ aun talk 海賊王に
|
99
|
+
俺はなる
|
100
|
+
~~~
|
101
|
+
|
102
|
+
### inspect_all
|
103
|
+
~~~bash
|
104
|
+
$ aun inspect_all
|
105
|
+
阿:君名前は? 吽:田原年彦 発言者:田原年彦 原典:行け!稲中卓球部, ユーザー定義:false
|
106
|
+
阿:山 吽:川 発言者:unknown 原典:unknown, ユーザー定義:false
|
107
|
+
阿:ぬるぽ 吽:ガッ 発言者:unknown 原典:unknown, ユーザー定義:false
|
108
|
+
阿:海賊王に 吽:俺はなる 発言者:モンキー・D・ルフィ 原典:One Piece, ユーザー定義:true
|
109
|
+
~~~
|
110
|
+
|
111
|
+
## gem を直接 require して利用する方法
|
112
|
+
|
113
|
+
### サンプルコード
|
114
|
+
~~~ruby
|
115
|
+
require 'aun_core'
|
116
|
+
|
117
|
+
messages = [
|
118
|
+
# owner, origin は省略すると :unknown になります
|
119
|
+
# user_defined は省略すると false になります
|
120
|
+
Aun::Message.new('やらないか?', 'アーッ!', owner: '阿部さん', origin: 'くそみそテクニック', user_defined: true),
|
121
|
+
Aun::Message.new('もうひといきじゃ パワーをメテオに', 'いいですとも!', owner: 'ゴルベーザ', origin: 'ファイナルファンタジーIV', user_defined: true)
|
122
|
+
]
|
123
|
+
|
124
|
+
finder = Aun::Finder.new
|
125
|
+
print finder.inspect_all, "\n"
|
126
|
+
# ユーザー定義のメッセージを追加
|
127
|
+
finder.add_messages(messages)
|
128
|
+
print finder.inspect_all, "\n"
|
129
|
+
print finder.talk('ぬるぽ'), "\n"
|
130
|
+
print finder.owner_talk('ぬるぽ'), "\n"
|
131
|
+
print finder.talk_with_origin('ぬるぽ'), "\n"
|
132
|
+
print finder.talk('やらないか?'), "\n"
|
133
|
+
print finder.owner_talk('やらないか?'), "\n"
|
134
|
+
print finder.talk_with_origin('やらないか?'), "\n"
|
135
|
+
~~~
|
136
|
+
|
137
|
+
### 出力
|
138
|
+
|
139
|
+
~~~
|
140
|
+
阿:君名前は? 吽:田原年彦 発言者:田原年彦 原典:行け!稲中卓球部, ユーザー定義:false
|
141
|
+
阿:山 吽:川 発言者:unknown 原典:unknown, ユーザー定義:false
|
142
|
+
阿:ぬるぽ 吽:ガッ 発言者:unknown 原典:unknown, ユーザー定義:false
|
143
|
+
阿:君名前は? 吽:田原年彦 発言者:田原年彦 原典:行け!稲中卓球部, ユーザー定義:false
|
144
|
+
阿:山 吽:川 発言者:unknown 原典:unknown, ユーザー定義:false
|
145
|
+
阿:ぬるぽ 吽:ガッ 発言者:unknown 原典:unknown, ユーザー定義:false
|
146
|
+
阿:やらないか? 吽:アーッ! 発言者:阿部さん 原典:くそみそテクニック, ユーザー定義:true
|
147
|
+
阿:もうひといきじゃ パワーをメテオに 吽:いいですとも! 発言者:ゴルベーザ 原典:ファイナルファンタジーIV, ユーザー定義:true
|
148
|
+
ガッ
|
149
|
+
ガッ
|
150
|
+
ガッ
|
151
|
+
アーッ!
|
152
|
+
阿部さん「アーッ!」
|
153
|
+
阿部さん「アーッ!」 from [くそみそテクニック]
|
154
|
+
~~~
|
155
|
+
|
156
|
+
## デフォルト阿吽メッセージへのプルリク
|
157
|
+
これは定番だろ!みたいなプルリクがあれば default_messages.rb を編集してプルリクください。
|
158
|
+
プルリクのメッセージに元ネタと簡単な説明を書いておいてください。
|
159
|
+
|
160
|
+
merge か reject かは独断と偏見で行います。
|
161
|
+
また元ネタの説明は出来る限り日本語でお願いします。
|
162
|
+
|
163
|
+
## History
|
164
|
+
* version 0.0.1 : First release.
|
165
|
+
|
166
|
+
## Contributing
|
167
|
+
|
168
|
+
1. Fork it ( https://github.com/tbpgr/aun/fork )
|
169
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
170
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
171
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
172
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/aun.gemspec
ADDED
@@ -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 'aun/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'aun'
|
8
|
+
spec.version = Aun::VERSION
|
9
|
+
spec.authors = ['tbpgr']
|
10
|
+
spec.email = ['tbpgr@tbpgr.jp']
|
11
|
+
spec.summary = %q(A-Un)
|
12
|
+
spec.description = %q(A-Un)
|
13
|
+
spec.homepage = 'https://github.com/tbpgr/aun'
|
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_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
end
|
data/bin/aun
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'aun_core'
|
5
|
+
require 'aun/version'
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
module Aun
|
9
|
+
# = Aun CLI
|
10
|
+
class CLI < Thor
|
11
|
+
class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
|
12
|
+
class_option :version, type: :boolean, desc: 'version'
|
13
|
+
|
14
|
+
desc 'init', 'Generate Aundefinition.csv template'
|
15
|
+
def init
|
16
|
+
Aun::DefinitionManager.new.init
|
17
|
+
exit(true)
|
18
|
+
rescue
|
19
|
+
exit(false)
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'inspect_all', 'inspect_all'
|
23
|
+
def inspect_all
|
24
|
+
call_finder_no_arity(:inspect_all)
|
25
|
+
end
|
26
|
+
|
27
|
+
%i(talk owner_talk talk_with_origin inspect).each do |m|
|
28
|
+
desc m.to_s, m.to_s
|
29
|
+
define_method m do |key|
|
30
|
+
call_finder_1_arity(m, key)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'version', 'version'
|
35
|
+
def version
|
36
|
+
p Aun::VERSION
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def call_finder_no_arity(m)
|
42
|
+
af = get_finder_instance
|
43
|
+
puts af.send(m)
|
44
|
+
exit(true)
|
45
|
+
rescue => e
|
46
|
+
STDERR.puts(e.backtrace)
|
47
|
+
exit(false)
|
48
|
+
end
|
49
|
+
|
50
|
+
def call_finder_1_arity(m, key)
|
51
|
+
af = get_finder_instance
|
52
|
+
puts af.send(m, key.encode('utf-8'))
|
53
|
+
exit(true)
|
54
|
+
rescue => e
|
55
|
+
STDERR.puts(e.backtrace)
|
56
|
+
exit(false)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_finder_instance
|
60
|
+
user_definition = Aun::DefinitionManager.new.load_user_definition
|
61
|
+
af = Aun::Finder.new
|
62
|
+
af.add_messages(user_definition)
|
63
|
+
af
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
Aun::CLI.start(ARGV)
|
data/images/aun.gif
ADDED
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Aun
|
5
|
+
class DefinitionManager
|
6
|
+
AUNDEFINITION_FILE = 'Aundefinition.csv'
|
7
|
+
AUNDEFINITION_TEMPLATE = <<-EOS
|
8
|
+
阿(例:海賊王に),吽(例:俺はなる),発言者(モンキー・D・ルフィ※不明の場合は空欄に),原典(One Piece※不明の場合は空欄に)
|
9
|
+
EOS
|
10
|
+
|
11
|
+
def init
|
12
|
+
File.open(AUNDEFINITION_FILE, 'w:UTF-8') do |f|
|
13
|
+
f.puts AUNDEFINITION_TEMPLATE
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_user_definition
|
18
|
+
return [] unless File.exist?(AUNDEFINITION_FILE)
|
19
|
+
memo = []
|
20
|
+
CSV.foreach(AUNDEFINITION_FILE, encoding: 'utf-8') do |row|
|
21
|
+
owner = row[2]
|
22
|
+
origin = row[3]
|
23
|
+
memo << Aun::Message.new(row[0], row[1], owner: row[2], origin: origin, user_defined: true)
|
24
|
+
end
|
25
|
+
memo
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def empty_to_unknown(target)
|
30
|
+
target.empty? ? :unknown : target
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/aun/finder.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'aun/message'
|
2
|
+
require 'aun/default_messages'
|
3
|
+
|
4
|
+
module Aun
|
5
|
+
class Finder
|
6
|
+
attr_reader :messages
|
7
|
+
def initialize
|
8
|
+
@messages = Aun::DefaultMessages::MESSAGES
|
9
|
+
end
|
10
|
+
|
11
|
+
%i(talk owner_talk talk_with_origin inspect).each do |m|
|
12
|
+
define_method m do |key|
|
13
|
+
message = @messages.select { |e|e.a == key }
|
14
|
+
message.empty? ? '' : message.sample.send(m)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect_all
|
19
|
+
@messages.map(&:inspect).join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
def aun_definitions
|
23
|
+
@messages
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_messages(messages = [])
|
27
|
+
@messages += messages
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/aun/message.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Aun
|
3
|
+
# Message
|
4
|
+
class Message
|
5
|
+
attr_reader :a, :un, :owner, :origin, :user_defined
|
6
|
+
def initialize(a, un, owner: :unknown, origin: :unknown, user_defined: false)
|
7
|
+
@a, @un, @owner, @origin, @user_defined = a, un, owner, origin, user_defined
|
8
|
+
end
|
9
|
+
|
10
|
+
# talk (format '@un')
|
11
|
+
def talk
|
12
|
+
@un
|
13
|
+
end
|
14
|
+
|
15
|
+
# talk (format '@owner 「@un」')
|
16
|
+
# if @owner is empty, (format '@un')
|
17
|
+
def owner_talk
|
18
|
+
return talk if unknown?(owner)
|
19
|
+
"#{@owner}「#{talk}」"
|
20
|
+
end
|
21
|
+
|
22
|
+
# talk (format '@owner 「@un」 from [@origin]')
|
23
|
+
# if @owner is empty and @origin is empty, (format '@un')
|
24
|
+
# if @owner is empty and @origin is not empty, (format '@un' from [@origin])
|
25
|
+
# if @owner is not empty and @origin is empty, (format '@owner 「@un」')
|
26
|
+
def talk_with_origin
|
27
|
+
ret = talk
|
28
|
+
ret = "#{@owner}「#{ret}」" unless unknown?(@owner)
|
29
|
+
ret = "#{ret} from [#{@origin}]" unless unknown?(@origin)
|
30
|
+
ret
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
"阿:#{@a}\t吽:#{@un}\t発言者:#{@owner}\t原典:#{@origin},\tユーザー定義:#{user_defined}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# Columns
|
38
|
+
# @return [Array(*String)] @a, @un, @owner, @origin, @user_defined
|
39
|
+
def columns
|
40
|
+
[@a, @un, @owner, @origin, @user_defined]
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def unknown?(target)
|
46
|
+
target == :unknown
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|