ruboty-todo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +7 -0
- data/Rakefile +11 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/ruboty/actions/todo.rb +91 -0
- data/lib/ruboty/handlers/todo.rb +11 -0
- data/lib/ruboty/todo.rb +6 -0
- data/lib/ruboty/todo/item.rb +59 -0
- data/lib/ruboty/todo/list.rb +51 -0
- data/lib/ruboty/todo/version.rb +5 -0
- data/ruboty-todo.gemspec +29 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11e041e3f81d6c74311f8482d848194ad809e43c
|
4
|
+
data.tar.gz: 1048df7f4eff0efb516612fe0b06314b8ec0502e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b42810785dda4143fe8559eac444843bcc2888620d58c42d1f39e960fd6892c01af207ff0b2fcc7746eac2dcf18c9465bcd7f19b0e492a894772069e180d41c9
|
7
|
+
data.tar.gz: f5eb99b325263feded2a39d0c2727150315a637be6d89fa03537ed8e2683a7813fc060d49c3b5bf60a11653f5801c3ddb95fc0da36a7f95ddb588f811df76c3f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 SHIOYA, Hiromu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Actions
|
3
|
+
class Todo < Base
|
4
|
+
COMMANDS = %w[list help add start finish delete cleanup renum]
|
5
|
+
attr_reader :todo_list
|
6
|
+
|
7
|
+
def call
|
8
|
+
(command, arg) = (message[:data] || '').split(/\s/, 2)
|
9
|
+
command = parse_command(command)
|
10
|
+
@todo_list = ::Ruboty::Todo::List.new(message.robot.brain)
|
11
|
+
|
12
|
+
result = self.send(command, arg)
|
13
|
+
message.reply(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def list(arg)
|
17
|
+
todo_list.items.map(&:format).join(?\n)
|
18
|
+
end
|
19
|
+
|
20
|
+
def help(arg)
|
21
|
+
<<EOH
|
22
|
+
`todo list`
|
23
|
+
show todo list
|
24
|
+
`todo add [TITLE]`
|
25
|
+
add list to new todo
|
26
|
+
`todo start [ID}`
|
27
|
+
start todo
|
28
|
+
`todo finish [ID]`
|
29
|
+
finish todo (will removed by `cleanup`)
|
30
|
+
`todo delete [ID]`
|
31
|
+
remove todo (will removed by `cleanup`)
|
32
|
+
`todo cleanup`
|
33
|
+
delete finished and deleted items from list
|
34
|
+
`todo renum`
|
35
|
+
renum id from 1
|
36
|
+
`todo help`
|
37
|
+
show this help
|
38
|
+
EOH
|
39
|
+
end
|
40
|
+
|
41
|
+
def add(arg)
|
42
|
+
return 'specify todo tilte like `todo add [TITLE]`' if title == ''
|
43
|
+
todo_list.add(title: title).format(new_item: true)
|
44
|
+
end
|
45
|
+
|
46
|
+
def start(arg)
|
47
|
+
change_item_state(arg, :start)
|
48
|
+
end
|
49
|
+
|
50
|
+
def finish(arg)
|
51
|
+
change_item_state(arg, :finish)
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete(arg)
|
55
|
+
change_item_state(arg, :delete)
|
56
|
+
end
|
57
|
+
|
58
|
+
def cleanup(arg)
|
59
|
+
todo_list.cleanup
|
60
|
+
list(arg)
|
61
|
+
end
|
62
|
+
|
63
|
+
def renum(arg)
|
64
|
+
todo_list.renum
|
65
|
+
list(arg)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def change_item_state(arg, status)
|
71
|
+
item = find_item(arg)
|
72
|
+
return "item #{arg} is not found" if item.nil?
|
73
|
+
item.send(status)
|
74
|
+
item.format
|
75
|
+
end
|
76
|
+
|
77
|
+
def find_item(arg)
|
78
|
+
id = arg.to_i
|
79
|
+
item = todo_list.find(arg.to_i)
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_command(command)
|
83
|
+
if COMMANDS.include?(command)
|
84
|
+
command.to_sym
|
85
|
+
else
|
86
|
+
:list
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/ruboty/todo.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Todo
|
3
|
+
class Item
|
4
|
+
ATTRIBUTES = [:id, :title, :status, :deadline_at].freeze
|
5
|
+
STATUSES = [:not_yet, :doing, :done, :deleted].freeze
|
6
|
+
EMOTICONS = {
|
7
|
+
new: 'new',
|
8
|
+
not_yet: 'memo',
|
9
|
+
doing: 'rocket',
|
10
|
+
done: 'tada',
|
11
|
+
deleted: 'x',
|
12
|
+
}
|
13
|
+
|
14
|
+
ATTRIBUTES.each { |attr| attr_accessor attr }
|
15
|
+
|
16
|
+
def initialize(id, params)
|
17
|
+
self.id = id
|
18
|
+
self.status = :not_yet
|
19
|
+
ATTRIBUTES.each do |attr|
|
20
|
+
self.send("#{attr}=".to_sym, params[attr]) if params.key?(attr)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
self.status = :doing
|
26
|
+
end
|
27
|
+
|
28
|
+
def doing?
|
29
|
+
self.status == :doing
|
30
|
+
end
|
31
|
+
|
32
|
+
def finish
|
33
|
+
self.status = :done
|
34
|
+
end
|
35
|
+
|
36
|
+
def done?
|
37
|
+
self.status == :done
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete
|
41
|
+
self.status = :deleted
|
42
|
+
end
|
43
|
+
|
44
|
+
def deleted?
|
45
|
+
self.status == :deleted
|
46
|
+
end
|
47
|
+
|
48
|
+
def deadline=(deadline)
|
49
|
+
self.deadline_at = Time.parse(deadline) rescue nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def format(new_item: false)
|
53
|
+
emoticon_state = new_item ? :new : status
|
54
|
+
|
55
|
+
"[#{sprintf('%2d', id)}] :#{EMOTICONS[emoticon_state]}: #{title}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Todo
|
3
|
+
class List
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
attr_reader :brain
|
7
|
+
def_delegators :items, :count, :size, :[]
|
8
|
+
|
9
|
+
def initialize(brain)
|
10
|
+
@brain = brain
|
11
|
+
end
|
12
|
+
|
13
|
+
def items
|
14
|
+
list[:items]
|
15
|
+
end
|
16
|
+
|
17
|
+
def add(params)
|
18
|
+
item = Item.new(next_id, params)
|
19
|
+
items.push(item)
|
20
|
+
item
|
21
|
+
end
|
22
|
+
|
23
|
+
def cleanup
|
24
|
+
list[:items] = list[:items].reject { |item| item.deleted? }
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(id)
|
28
|
+
items.find { |item| item.id == id }
|
29
|
+
end
|
30
|
+
|
31
|
+
def renum
|
32
|
+
reset_id
|
33
|
+
items.each { |item| item.id = next_id }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def list
|
39
|
+
brain.data['todo_list'] ||= { last_id: 0, items: [] }
|
40
|
+
end
|
41
|
+
|
42
|
+
def next_id
|
43
|
+
list[:last_id] += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset_id
|
47
|
+
list[:last_id] = 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/ruboty-todo.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/todo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-todo"
|
8
|
+
spec.version = Ruboty::Todo::VERSION
|
9
|
+
spec.authors = ["SHIOYA, Hiromu"]
|
10
|
+
spec.email = ["kwappa.856@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'ruboty handler to manger your todo list'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/kwappa/ruboty-todo'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'ruboty'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'pry'
|
28
|
+
spec.add_development_dependency 'test-unit'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-todo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SHIOYA, Hiromu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-13 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.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
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: pry
|
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: test-unit
|
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: ruboty handler to manger your todo list
|
84
|
+
email:
|
85
|
+
- kwappa.856@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/ruboty/actions/todo.rb
|
98
|
+
- lib/ruboty/handlers/todo.rb
|
99
|
+
- lib/ruboty/todo.rb
|
100
|
+
- lib/ruboty/todo/item.rb
|
101
|
+
- lib/ruboty/todo/list.rb
|
102
|
+
- lib/ruboty/todo/version.rb
|
103
|
+
- ruboty-todo.gemspec
|
104
|
+
homepage: https://github.com/kwappa/ruboty-todo
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: ruboty handler to manger your todo list
|
128
|
+
test_files: []
|