ruboty-todo 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bd1e0ac44d9d04aa609d980b1b0130bdea37bb0
4
- data.tar.gz: 082d74f92dccac328f289508f75d957c72687af3
3
+ metadata.gz: bc90f5e5958c246beaab630eb1c9e0de372b93d1
4
+ data.tar.gz: 23ebf15bf1daf4367d47e7f2b4c7847f2ddf2612
5
5
  SHA512:
6
- metadata.gz: c459d269a61f0e226b6be9bdb611d17f52d7f5e53d41a247bb6711d2cb36032ef2ef7704dcb8dd01d66f5d1225249c38808e5c80d7678d5a144d44fc59198bcf
7
- data.tar.gz: 54ff9308ff09c711166550a87b5ddb284a983ab7db215c5fbeffacca8f91b56b02571be393f11ef99cacc79c95fed18a85bbde736deb3e4e5f4313aa0b725fe6
6
+ metadata.gz: 9bfabfc2166cf181ab60452f22c3fadb856264b72ffe06716851dddf3532d74e95202ec4bc0a0d0c9ba8f1cccb24a851b7b2c567f0ea3ca4009554421f24394f
7
+ data.tar.gz: 54eae573eceaa3fc9e8afe3cbb3ca6fb57a6eab2596b1766c53ebe924a208e2ae69fc9971962fa9c139233a727edf2009b6f05ee90308f976a8b5877cea23c69
@@ -1,10 +1,34 @@
1
1
  module Ruboty
2
2
  module Handlers
3
3
  class Todo < Base
4
- on(/todo(\s*)?(?<data>.+)?/, name: 'todo', description: 'todo')
4
+ on(
5
+ /(?<command>list|cleanup|renum) todos\z/,
6
+ name: 'list',
7
+ description: '(list|cleanup|renum) all todo items'
8
+ )
5
9
 
6
- def todo(message)
7
- ::Ruboty::Actions::Todo.new(message).call
10
+ on(
11
+ /add todo (?<title>.+)\z/,
12
+ name: 'add',
13
+ description: 'add todo item'
14
+ )
15
+
16
+ on(
17
+ /(?<state>start|finish|delete) todo (?<id>\d+)\z/,
18
+ name: 'state',
19
+ description: 'change state of todo item'
20
+ )
21
+
22
+ def list(message)
23
+ ::Ruboty::Todo::Actions::List.new(message).call
24
+ end
25
+
26
+ def add(message)
27
+ ::Ruboty::Todo::Actions::Add.new(message).call
28
+ end
29
+
30
+ def state(message)
31
+ ::Ruboty::Todo::Actions::State.new(message).call
8
32
  end
9
33
  end
10
34
  end
data/lib/ruboty/todo.rb CHANGED
@@ -2,5 +2,8 @@ require 'ruboty'
2
2
  require 'ruboty/todo/version'
3
3
  require 'ruboty/todo/list'
4
4
  require 'ruboty/todo/item'
5
- require 'ruboty/actions/todo'
5
+ require 'ruboty/todo/actions/base'
6
+ require 'ruboty/todo/actions/list'
7
+ require 'ruboty/todo/actions/add'
8
+ require 'ruboty/todo/actions/state'
6
9
  require 'ruboty/handlers/todo'
@@ -0,0 +1,12 @@
1
+ module Ruboty
2
+ module Todo
3
+ module Actions
4
+ class Add < Base
5
+ def call
6
+ super
7
+ message.reply(todo_list.add(title: message[:title]).format(new_item: true))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module Ruboty
2
+ module Todo
3
+ module Actions
4
+ class Base < ::Ruboty::Actions::Base
5
+ attr_reader :todo_list
6
+
7
+ def call
8
+ @todo_list = ::Ruboty::Todo::List.new(message.robot.brain)
9
+ end
10
+
11
+ private
12
+
13
+ def from_owner?
14
+ return true if ENV['TODO_OWNERS'] == 'IGNORE_CHECK'
15
+ ENV['TODO_OWNERS'].split(',').map(&:strip).include?(message.from_name)
16
+ end
17
+
18
+ def find_item(arg)
19
+ id = arg.to_i
20
+ item = todo_list.find(arg.to_i)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module Ruboty
2
+ module Todo
3
+ module Actions
4
+ class List < Base
5
+ def call
6
+ super
7
+ message.reply(send(message[:command].to_sym))
8
+ end
9
+
10
+ def list
11
+ todo_list.items.map(&:format).join(?\n)
12
+ end
13
+
14
+ def cleanup
15
+ todo_list.cleanup
16
+ list
17
+ end
18
+
19
+ def renum
20
+ todo_list.renum
21
+ list
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ module Ruboty
2
+ module Todo
3
+ module Actions
4
+ class State < Base
5
+ def call
6
+ super
7
+ require 'pp'
8
+ pp message
9
+
10
+ message.reply(change_item_state(message[:id].to_i, message[:state].to_sym))
11
+ end
12
+
13
+ private
14
+
15
+ def change_item_state(id, state)
16
+ item = find_item(id)
17
+ return "item #{id} is not found" if item.nil?
18
+ item.send(state)
19
+ item.format
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Todo
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-todo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIOYA, Hiromu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-13 00:00:00.000000000 Z
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -94,9 +94,12 @@ files:
94
94
  - Rakefile
95
95
  - bin/console
96
96
  - bin/setup
97
- - lib/ruboty/actions/todo.rb
98
97
  - lib/ruboty/handlers/todo.rb
99
98
  - lib/ruboty/todo.rb
99
+ - lib/ruboty/todo/actions/add.rb
100
+ - lib/ruboty/todo/actions/base.rb
101
+ - lib/ruboty/todo/actions/list.rb
102
+ - lib/ruboty/todo/actions/state.rb
100
103
  - lib/ruboty/todo/item.rb
101
104
  - lib/ruboty/todo/list.rb
102
105
  - lib/ruboty/todo/version.rb
@@ -1,99 +0,0 @@
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
- return unless from_owner?
9
-
10
- (command, arg) = (message[:data] || '').split(/\s/, 2)
11
- command = parse_command(command)
12
- @todo_list = ::Ruboty::Todo::List.new(message.robot.brain)
13
-
14
- result = self.send(command, arg)
15
- message.reply(result)
16
- end
17
-
18
- def list(arg)
19
- todo_list.items.map(&:format).join(?\n)
20
- end
21
-
22
- def help(arg)
23
- <<EOH
24
- `todo list`
25
- show todo list
26
- `todo add [TITLE]`
27
- add list to new todo
28
- `todo start [ID]`
29
- start todo
30
- `todo finish [ID]`
31
- finish todo (will removed by `cleanup`)
32
- `todo delete [ID]`
33
- remove todo (will removed by `cleanup`)
34
- `todo cleanup`
35
- delete finished and deleted items from list
36
- `todo renum`
37
- renum id from 1
38
- `todo help`
39
- show this help
40
- EOH
41
- end
42
-
43
- def add(arg)
44
- title = arg.to_s.strip
45
- return 'specify todo title like `todo add [TITLE]`' if title == ''
46
- todo_list.add(title: title).format(new_item: true)
47
- end
48
-
49
- def start(arg)
50
- change_item_state(arg, :start)
51
- end
52
-
53
- def finish(arg)
54
- change_item_state(arg, :finish)
55
- end
56
-
57
- def delete(arg)
58
- change_item_state(arg, :delete)
59
- end
60
-
61
- def cleanup(arg)
62
- todo_list.cleanup
63
- list(arg)
64
- end
65
-
66
- def renum(arg)
67
- todo_list.renum
68
- list(arg)
69
- end
70
-
71
- private
72
-
73
- def from_owner?
74
- return true if ENV['TODO_OWNERS'] == 'IGNORE_CHECK'
75
- ENV['TODO_OWNERS'].split(',').map(&:strip).include?(message.from_name)
76
- end
77
-
78
- def change_item_state(arg, status)
79
- item = find_item(arg)
80
- return "item #{arg} is not found" if item.nil?
81
- item.send(status)
82
- item.format
83
- end
84
-
85
- def find_item(arg)
86
- id = arg.to_i
87
- item = todo_list.find(arg.to_i)
88
- end
89
-
90
- def parse_command(command)
91
- if COMMANDS.include?(command)
92
- command.to_sym
93
- else
94
- :list
95
- end
96
- end
97
- end
98
- end
99
- end