posto 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/posto/application.rb +32 -31
- data/lib/posto/file.rb +12 -4
- data/lib/posto/list.rb +27 -27
- data/lib/posto/template.rb +2 -2
- data/lib/posto/todo.rb +57 -0
- data/lib/posto.rb +2 -2
- data/test/list_test.rb +4 -4
- data/test/todo_test.rb +29 -0
- metadata +6 -6
- data/lib/posto/item.rb +0 -57
- data/test/item_test.rb +0 -29
data/lib/posto/application.rb
CHANGED
@@ -10,57 +10,58 @@ module Posto
|
|
10
10
|
@file = Posto::File.new(@arguments.filename)
|
11
11
|
end
|
12
12
|
|
13
|
-
def list(
|
14
|
-
|
13
|
+
def list(todos)
|
14
|
+
todos
|
15
15
|
end
|
16
16
|
|
17
|
-
def run(
|
18
|
-
@io.puts send(@arguments.command,
|
17
|
+
def run(todos)
|
18
|
+
@io.puts send(@arguments.command, todos, *@arguments.params)
|
19
19
|
end
|
20
20
|
|
21
|
-
def sort(
|
22
|
-
@file.write @list_utility.sort(
|
21
|
+
def sort(todos)
|
22
|
+
@file.write @list_utility.sort(todos)
|
23
23
|
end
|
24
24
|
|
25
|
-
def resort(
|
26
|
-
@file.write @list_utility.resort(
|
25
|
+
def resort(todos)
|
26
|
+
@file.write @list_utility.resort(todos)
|
27
27
|
end
|
28
28
|
|
29
|
-
def unsort(
|
30
|
-
@file.write @list_utility.unsort(
|
31
|
-
|
29
|
+
def unsort(todos, n = 1)
|
30
|
+
@file.write @list_utility.unsort(todos, n.to_i)
|
31
|
+
lookup_todo(todos, n)
|
32
32
|
end
|
33
33
|
|
34
|
-
def done(
|
35
|
-
@file.write @list_utility.done(
|
36
|
-
|
34
|
+
def done(todos, n = 1)
|
35
|
+
@file.write @list_utility.done(todos, n.to_i)
|
36
|
+
lookup_todo(todos, n)
|
37
37
|
end
|
38
38
|
|
39
|
-
def top(
|
40
|
-
|
41
|
-
|
42
|
-
else
|
43
|
-
@file.write @list_utility.top(items, n.to_i)
|
44
|
-
lookup_item(items, n)
|
45
|
-
end
|
39
|
+
def top(todos, n = 1)
|
40
|
+
@file.write @list_utility.top(todos, n.to_i)
|
41
|
+
lookup_todo(todos, n)
|
46
42
|
end
|
47
43
|
|
48
|
-
def quick(
|
49
|
-
@file.write @list_utility.quick(
|
50
|
-
|
44
|
+
def quick(todos, n = 1)
|
45
|
+
@file.write @list_utility.quick(todos, n.to_i)
|
46
|
+
lookup_todo(todos, n)
|
51
47
|
end
|
52
48
|
|
53
|
-
def add(
|
54
|
-
@file.write @list_utility.add(
|
55
|
-
|
49
|
+
def add(todos, todo)
|
50
|
+
@file.write @list_utility.add(todos, todo)
|
51
|
+
todo
|
56
52
|
end
|
57
53
|
|
58
|
-
def commit(
|
59
|
-
@file.commit(done(
|
54
|
+
def commit(todos, n = 1)
|
55
|
+
@file.commit(done(todos, n))
|
60
56
|
end
|
61
57
|
|
62
|
-
def
|
63
|
-
|
58
|
+
def init(todos)
|
59
|
+
@file.touch
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def lookup_todo(todos, n)
|
64
|
+
Posto::Todo.hide_markdown(todos[n.to_i - 1])
|
64
65
|
end
|
65
66
|
|
66
67
|
def method_missing(symbol, *args)
|
data/lib/posto/file.rb
CHANGED
@@ -6,17 +6,25 @@ module Posto
|
|
6
6
|
@filename = filename
|
7
7
|
end
|
8
8
|
|
9
|
-
def write(
|
10
|
-
IO.write(@filename, Template.todo_list(
|
9
|
+
def write(todos)
|
10
|
+
IO.write(@filename, Template.todo_list(todos))
|
11
11
|
end
|
12
12
|
|
13
13
|
def commit(msg)
|
14
|
-
`git add
|
14
|
+
`git add #@filename`
|
15
15
|
`git commit -m "#{msg}"`
|
16
16
|
end
|
17
17
|
|
18
|
+
def touch
|
19
|
+
`touch #@filename`
|
20
|
+
end
|
21
|
+
|
18
22
|
def lines
|
19
|
-
|
23
|
+
if ::File.exists? @filename
|
24
|
+
IO.read(@filename).split("\n")
|
25
|
+
else
|
26
|
+
[]
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/posto/list.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
require 'posto/
|
1
|
+
require 'posto/todo'
|
2
2
|
require 'posto/monkeypatch_array'
|
3
3
|
|
4
4
|
module Posto
|
5
5
|
class List
|
6
6
|
class << self
|
7
|
-
def
|
8
|
-
|
7
|
+
def number_todos(todos)
|
8
|
+
todos.each_with_index.map { |todo, i| Todo.number(todo, i + 1) }
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
lines.select { |line|
|
11
|
+
def choose_todo_lines(lines)
|
12
|
+
lines.select { |line| Todo.todo?(line) }
|
13
13
|
end
|
14
14
|
|
15
|
-
def sort(
|
16
|
-
|
15
|
+
def sort(todos)
|
16
|
+
number_todos(todos.sort { |x, y| Todo.compare_sorted_todos(x, y) or Todo.ask_human_to_compare(x, y) })
|
17
17
|
end
|
18
18
|
|
19
|
-
def starred_group(
|
20
|
-
|
19
|
+
def starred_group(todos)
|
20
|
+
todos.select { |todo| Todo.starred?(todo) }
|
21
21
|
end
|
22
22
|
|
23
|
-
def numbered_group(
|
24
|
-
sort
|
23
|
+
def numbered_group(todos)
|
24
|
+
sort todos.select { |todo| Todo.numbered?(todo) }
|
25
25
|
end
|
26
26
|
|
27
|
-
def done(
|
28
|
-
unsort(
|
27
|
+
def done(todos, n)
|
28
|
+
unsort(todos, n)[0..-2]
|
29
29
|
end
|
30
30
|
|
31
|
-
def unsort(
|
32
|
-
numbered_group(
|
31
|
+
def unsort(todos, n)
|
32
|
+
numbered_group(todos.reject_at(n - 1)) + starred_group(todos.reject_at(n - 1)) + [Todo.star(todos[n - 1])]
|
33
33
|
end
|
34
34
|
|
35
|
-
def resort(
|
36
|
-
sort
|
35
|
+
def resort(todos)
|
36
|
+
sort todos.map { |todo| Todo.star(todo) }
|
37
37
|
end
|
38
38
|
|
39
|
-
def add(
|
40
|
-
|
39
|
+
def add(todos, todo)
|
40
|
+
todos + [Todo.create(todo)]
|
41
41
|
end
|
42
42
|
|
43
|
-
def quick(
|
44
|
-
|
45
|
-
|
43
|
+
def quick(todos, n)
|
44
|
+
todos[n -1] = Todo.mark_quick(todos[n - 1])
|
45
|
+
todos
|
46
46
|
end
|
47
47
|
|
48
|
-
def top(
|
49
|
-
starred_group = starred_group(
|
50
|
-
numbered_group = numbered_group(
|
51
|
-
array = [
|
52
|
-
|
48
|
+
def top(todos, n)
|
49
|
+
starred_group = starred_group(todos.reject_at(n - 1))
|
50
|
+
numbered_group = numbered_group(todos.reject_at(n - 1))
|
51
|
+
array = [todos[n - 1]]
|
52
|
+
number_todos(array + numbered_group) + starred_group
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/lib/posto/template.rb
CHANGED
data/lib/posto/todo.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'posto/template'
|
2
|
+
|
3
|
+
module Posto
|
4
|
+
class Todo
|
5
|
+
class << self
|
6
|
+
MD_LIST_TODO = /^(\*|\d+\.) /
|
7
|
+
|
8
|
+
def ask_human_to_compare(x, y)
|
9
|
+
while true do
|
10
|
+
response = ask(Template.human_comparison(hide_markdown(x), hide_markdown(y))).to_i
|
11
|
+
return 0 if response == 0
|
12
|
+
return -1 if response == 1
|
13
|
+
return 1 if response == 2
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def compare_sorted_todos(x, y)
|
18
|
+
x = x.to_i
|
19
|
+
y = y.to_i
|
20
|
+
return nil if (x == 0 or y == 0)
|
21
|
+
x <=> y
|
22
|
+
end
|
23
|
+
|
24
|
+
def hide_markdown(todo)
|
25
|
+
todo.sub(MD_LIST_TODO, "")
|
26
|
+
end
|
27
|
+
|
28
|
+
def star(todo)
|
29
|
+
todo.sub MD_LIST_TODO, "* "
|
30
|
+
end
|
31
|
+
|
32
|
+
def number(todo, n)
|
33
|
+
todo.sub MD_LIST_TODO, "#{n}. "
|
34
|
+
end
|
35
|
+
|
36
|
+
def todo?(line)
|
37
|
+
MD_LIST_TODO =~ line
|
38
|
+
end
|
39
|
+
|
40
|
+
def create(todo)
|
41
|
+
todo.sub(/^(\* )?/, "* ")
|
42
|
+
end
|
43
|
+
|
44
|
+
def mark_quick(todo)
|
45
|
+
todo.sub(/( \(quick\))?$/, " (quick)")
|
46
|
+
end
|
47
|
+
|
48
|
+
def starred?(todo)
|
49
|
+
/^\* / =~ todo
|
50
|
+
end
|
51
|
+
|
52
|
+
def numbered?(todo)
|
53
|
+
/^\d+\. / =~ todo
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/posto.rb
CHANGED
@@ -8,8 +8,8 @@ module Posto
|
|
8
8
|
class << self
|
9
9
|
def main(args)
|
10
10
|
arguments = Arguments.new(args)
|
11
|
-
|
12
|
-
Application.new(arguments).run(
|
11
|
+
todos = List.choose_todo_lines(File.new(arguments.filename).lines)
|
12
|
+
Application.new(arguments).run(todos)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/test/list_test.rb
CHANGED
@@ -4,12 +4,12 @@ require 'posto/list'
|
|
4
4
|
class ListTest < MiniTest::Unit::TestCase
|
5
5
|
def test_replace_stars
|
6
6
|
assert_equal(["1. this is one", "2. this is another", "3. card molly"],
|
7
|
-
Posto::List.
|
7
|
+
Posto::List.number_todos(["* this is one", "* this is another", "99. card molly"]))
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
assert_equal(["99. bottles", "* unsorted
|
12
|
-
Posto::List.
|
10
|
+
def test_choose_todo_lines
|
11
|
+
assert_equal(["99. bottles", "* unsorted todo"],
|
12
|
+
Posto::List.choose_todo_lines(["TODO", "======", "99. bottles", "* unsorted todo", "END", ""]))
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_starred_group
|
data/test/todo_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'posto/todo'
|
3
|
+
|
4
|
+
class TodoTest < MiniTest::Unit::TestCase
|
5
|
+
def test_hide_markdown
|
6
|
+
assert_equal "bottles", Posto::Todo.hide_markdown("99. bottles")
|
7
|
+
assert_equal "unsorted todo", Posto::Todo.hide_markdown("* unsorted todo")
|
8
|
+
assert_equal "funky * todo with 99. junk", Posto::Todo.hide_markdown("* funky * todo with 99. junk")
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_compare_sorted_todos
|
12
|
+
assert_equal(1, Posto::Todo.compare_sorted_todos("99. bottles", "50. cents"))
|
13
|
+
assert_equal(-1, Posto::Todo.compare_sorted_todos("1. lonliest number", "50. cents"))
|
14
|
+
assert_equal(0, Posto::Todo.compare_sorted_todos("1. lonliest number", "1. The Only One"))
|
15
|
+
assert_equal(nil, Posto::Todo.compare_sorted_todos("* kleene", "* twinkle twinkle"))
|
16
|
+
assert_equal(nil, Posto::Todo.compare_sorted_todos("* twinkle twinkle", "1. The Only One"))
|
17
|
+
assert_equal(nil, Posto::Todo.compare_sorted_todos("99. bottles", "* twinkle twinkle"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_star
|
21
|
+
assert_equal "* bottles", Posto::Todo.star("99. bottles")
|
22
|
+
assert_equal "* fruit", Posto::Todo.star("* fruit")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_number
|
26
|
+
assert_equal "99. bottles", Posto::Todo.number("* bottles", 99)
|
27
|
+
assert_equal "99. cents", Posto::Todo.number("50. cents", 99)
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -58,15 +58,15 @@ files:
|
|
58
58
|
- lib/posto/template.rb
|
59
59
|
- lib/posto/application.rb
|
60
60
|
- lib/posto/list.rb
|
61
|
+
- lib/posto/todo.rb
|
61
62
|
- lib/posto/file.rb
|
62
|
-
- lib/posto/item.rb
|
63
63
|
- lib/posto/arguments.rb
|
64
64
|
- lib/posto.rb
|
65
65
|
- test/list_test.rb
|
66
|
-
- test/item_test.rb
|
67
66
|
- test/arguments_test.rb
|
68
67
|
- test/test_helper.rb
|
69
68
|
- test/monkeypatch_array_test.rb
|
69
|
+
- test/todo_test.rb
|
70
70
|
homepage: http://github.com/mattraibert/posto
|
71
71
|
licenses:
|
72
72
|
- GPLv3
|
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
segments:
|
84
84
|
- 0
|
85
|
-
hash:
|
85
|
+
hash: -2327369408914751837
|
86
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
@@ -97,7 +97,7 @@ specification_version: 3
|
|
97
97
|
summary: CLI to sort your todo list.
|
98
98
|
test_files:
|
99
99
|
- test/list_test.rb
|
100
|
-
- test/item_test.rb
|
101
100
|
- test/arguments_test.rb
|
102
101
|
- test/test_helper.rb
|
103
102
|
- test/monkeypatch_array_test.rb
|
103
|
+
- test/todo_test.rb
|
data/lib/posto/item.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'posto/template'
|
2
|
-
|
3
|
-
module Posto
|
4
|
-
class Item
|
5
|
-
class << self
|
6
|
-
MD_LIST_ITEM = /^(\*|\d+\.) /
|
7
|
-
|
8
|
-
def ask_human_to_compare(x, y)
|
9
|
-
while true do
|
10
|
-
response = ask(Template.human_comparison(hide_markdown(x), hide_markdown(y))).to_i
|
11
|
-
return 0 if response == 0
|
12
|
-
return -1 if response == 1
|
13
|
-
return 1 if response == 2
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def compare_sorted_items(x, y)
|
18
|
-
x = x.to_i
|
19
|
-
y = y.to_i
|
20
|
-
return nil if (x == 0 or y == 0)
|
21
|
-
x <=> y
|
22
|
-
end
|
23
|
-
|
24
|
-
def hide_markdown(item)
|
25
|
-
item.sub(MD_LIST_ITEM, "")
|
26
|
-
end
|
27
|
-
|
28
|
-
def star(item)
|
29
|
-
item.sub MD_LIST_ITEM, "* "
|
30
|
-
end
|
31
|
-
|
32
|
-
def number(item, n)
|
33
|
-
item.sub MD_LIST_ITEM, "#{n}. "
|
34
|
-
end
|
35
|
-
|
36
|
-
def item?(line)
|
37
|
-
MD_LIST_ITEM =~ line
|
38
|
-
end
|
39
|
-
|
40
|
-
def create(item)
|
41
|
-
item.sub(/^(\* )?/, "* ")
|
42
|
-
end
|
43
|
-
|
44
|
-
def mark_quick(item)
|
45
|
-
item.sub(/( \(quick\))?$/, " (quick)")
|
46
|
-
end
|
47
|
-
|
48
|
-
def starred?(item)
|
49
|
-
/^\* / =~ item
|
50
|
-
end
|
51
|
-
|
52
|
-
def numbered?(item)
|
53
|
-
/^\d+\. / =~ item
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/test/item_test.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'posto/item'
|
3
|
-
|
4
|
-
class ItemTest < MiniTest::Unit::TestCase
|
5
|
-
def test_hide_markdown
|
6
|
-
assert_equal "bottles", Posto::Item.hide_markdown("99. bottles")
|
7
|
-
assert_equal "unsorted item", Posto::Item.hide_markdown("* unsorted item")
|
8
|
-
assert_equal "funky * item with 99. junk", Posto::Item.hide_markdown("* funky * item with 99. junk")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_compare_sorted_items
|
12
|
-
assert_equal(1, Posto::Item.compare_sorted_items("99. bottles", "50. cents"))
|
13
|
-
assert_equal(-1, Posto::Item.compare_sorted_items("1. lonliest number", "50. cents"))
|
14
|
-
assert_equal(0, Posto::Item.compare_sorted_items("1. lonliest number", "1. The Only One"))
|
15
|
-
assert_equal(nil, Posto::Item.compare_sorted_items("* kleene", "* twinkle twinkle"))
|
16
|
-
assert_equal(nil, Posto::Item.compare_sorted_items("* twinkle twinkle", "1. The Only One"))
|
17
|
-
assert_equal(nil, Posto::Item.compare_sorted_items("99. bottles", "* twinkle twinkle"))
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_star
|
21
|
-
assert_equal "* bottles", Posto::Item.star("99. bottles")
|
22
|
-
assert_equal "* fruit", Posto::Item.star("* fruit")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_number
|
26
|
-
assert_equal "99. bottles", Posto::Item.number("* bottles", 99)
|
27
|
-
assert_equal "99. cents", Posto::Item.number("50. cents", 99)
|
28
|
-
end
|
29
|
-
end
|