posto 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +3 -3
- data/README.md +1 -1
- data/lib/posto/application.rb +27 -14
- data/lib/posto/arguments.rb +1 -1
- data/lib/posto/file.rb +0 -1
- data/lib/posto/item.rb +16 -0
- data/lib/posto/list.rb +17 -5
- data/lib/posto/monkeypatch_array.rb +7 -0
- data/lib/posto.rb +1 -1
- data/test/application_test.rb +23 -5
- data/test/arguments_test.rb +1 -1
- data/test/list_test.rb +19 -1
- data/test/monkeypatch_array_test.rb +9 -0
- metadata +7 -4
data/LICENSE.txt
CHANGED
@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
|
|
631
631
|
state the exclusion of warranty; and each file should have at least
|
632
632
|
the "copyright" line and a pointer to where the full notice is found.
|
633
633
|
|
634
|
-
|
635
|
-
Copyright (C)
|
634
|
+
command line utility for your todo lists
|
635
|
+
Copyright (C) 2012 Matt Raibert
|
636
636
|
|
637
637
|
This program is free software: you can redistribute it and/or modify
|
638
638
|
it under the terms of the GNU General Public License as published by
|
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|
652
652
|
If the program does terminal interaction, make it output a short
|
653
653
|
notice like this when it starts in an interactive mode:
|
654
654
|
|
655
|
-
|
655
|
+
posto Copyright (C) 2012 Matt Raibert
|
656
656
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
657
657
|
This is free software, and you are welcome to redistribute it
|
658
658
|
under certain conditions; type `show c' for details.
|
data/README.md
CHANGED
data/lib/posto/application.rb
CHANGED
@@ -2,34 +2,47 @@ require 'posto/list'
|
|
2
2
|
|
3
3
|
module Posto
|
4
4
|
class Application
|
5
|
-
def initialize(arguments,
|
5
|
+
def initialize(arguments, list = List, io = STDOUT)
|
6
6
|
@arguments = arguments
|
7
|
-
@items = items
|
8
7
|
@list = list
|
8
|
+
@io = io
|
9
9
|
end
|
10
10
|
|
11
|
-
def run
|
12
|
-
send(@arguments.command, *@arguments.params)
|
11
|
+
def run(items)
|
12
|
+
send(@arguments.command, items, *@arguments.params)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
@
|
15
|
+
def list(items)
|
16
|
+
@io.puts items
|
17
|
+
items
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
|
20
|
+
def sort(items)
|
21
|
+
list @list.sort(items)
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
-
|
24
|
+
def unsort(items, n = 1)
|
25
|
+
list @list.unsort(items, n.to_i)
|
25
26
|
end
|
26
27
|
|
27
|
-
def
|
28
|
-
|
28
|
+
def resort(items)
|
29
|
+
list @list.resort(items)
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
-
|
32
|
+
def done(items, n = 1)
|
33
|
+
list @list.done(items, n.to_i)
|
34
|
+
end
|
35
|
+
|
36
|
+
def add(items, item)
|
37
|
+
list @list.add(items, item)
|
38
|
+
end
|
39
|
+
|
40
|
+
def top(items, n = 1)
|
41
|
+
list @list.top(items, n.to_i)
|
42
|
+
end
|
43
|
+
|
44
|
+
def quick(items, n = 1)
|
45
|
+
list @list.quick(items, n.to_i)
|
33
46
|
end
|
34
47
|
|
35
48
|
def method_missing(symbol, *args)
|
data/lib/posto/arguments.rb
CHANGED
data/lib/posto/file.rb
CHANGED
data/lib/posto/item.rb
CHANGED
@@ -36,6 +36,22 @@ module Posto
|
|
36
36
|
def item?(line)
|
37
37
|
MD_LIST_ITEM =~ line
|
38
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
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
data/lib/posto/list.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'posto/item'
|
2
|
+
require 'posto/monkeypatch_array'
|
2
3
|
|
3
4
|
module Posto
|
4
5
|
class List
|
@@ -16,11 +17,11 @@ module Posto
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def starred_group(items)
|
19
|
-
items.select { |item|
|
20
|
+
items.select { |item| Item.starred?(item) }
|
20
21
|
end
|
21
22
|
|
22
23
|
def numbered_group(items)
|
23
|
-
sort items.select { |item|
|
24
|
+
sort items.select { |item| Item.numbered?(item) }
|
24
25
|
end
|
25
26
|
|
26
27
|
def done(items, n)
|
@@ -28,8 +29,7 @@ module Posto
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def unsort(items, n)
|
31
|
-
|
32
|
-
numbered_group(items) + starred_group(items) + [Item.star(item)]
|
32
|
+
numbered_group(items.reject_at(n - 1)) + starred_group(items.reject_at(n - 1)) + [Item.star(items[n - 1])]
|
33
33
|
end
|
34
34
|
|
35
35
|
def resort(items)
|
@@ -37,7 +37,19 @@ module Posto
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def add(items, item)
|
40
|
-
items + [
|
40
|
+
items + [Item.create(item)]
|
41
|
+
end
|
42
|
+
|
43
|
+
def quick(items, n)
|
44
|
+
items[n -1] = Item.mark_quick(items[n - 1])
|
45
|
+
items
|
46
|
+
end
|
47
|
+
|
48
|
+
def top(items, n)
|
49
|
+
starred_group = starred_group(items.reject_at(n - 1))
|
50
|
+
numbered_group = numbered_group(items.reject_at(n - 1))
|
51
|
+
array = [items[n - 1]]
|
52
|
+
number_items(array + numbered_group) + starred_group
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
data/lib/posto.rb
CHANGED
@@ -10,7 +10,7 @@ module Posto
|
|
10
10
|
arguments = Arguments.new(args)
|
11
11
|
file = File.new(arguments.filename)
|
12
12
|
items = List.choose_item_lines(file.lines)
|
13
|
-
result = Application.new(arguments
|
13
|
+
result = Application.new(arguments).run(items)
|
14
14
|
file.write(result)
|
15
15
|
end
|
16
16
|
end
|
data/test/application_test.rb
CHANGED
@@ -4,33 +4,51 @@ require 'grasshopper'
|
|
4
4
|
require 'minitest/mock'
|
5
5
|
|
6
6
|
class ApplicationTest < MiniTest::Unit::TestCase
|
7
|
+
def test_default
|
8
|
+
array = []
|
9
|
+
result = Posto::Application.new(Stub.like(:command => "list", :params => []), Mock.new, Mock.new).run(array)
|
10
|
+
assert_same(array, result)
|
11
|
+
end
|
12
|
+
|
7
13
|
def test_sort
|
8
14
|
mock = Mock.new
|
9
|
-
Posto::Application.new(Stub.like(:command => "sort", :params => []),
|
15
|
+
Posto::Application.new(Stub.like(:command => "sort", :params => []), mock, Mock.new).run([])
|
10
16
|
Mock.verify(mock).sort([])
|
11
17
|
end
|
12
18
|
|
13
19
|
def test_unsort
|
14
20
|
mock = Mock.new
|
15
|
-
Posto::Application.new(Stub.like(:command => "unsort", :params => ["4"]),
|
21
|
+
Posto::Application.new(Stub.like(:command => "unsort", :params => ["4"]), mock, Mock.new).run([])
|
16
22
|
Mock.verify(mock).unsort([], 4)
|
17
23
|
end
|
18
24
|
|
19
25
|
def test_resort
|
20
26
|
mock = Mock.new
|
21
|
-
Posto::Application.new(Stub.like(:command => "resort", :params => []),
|
27
|
+
Posto::Application.new(Stub.like(:command => "resort", :params => []), mock, Mock.new).run([])
|
22
28
|
Mock.verify(mock).resort([])
|
23
29
|
end
|
24
30
|
|
25
31
|
def test_done
|
26
32
|
mock = Mock.new
|
27
|
-
Posto::Application.new(Stub.like(:command => "done", :params => ["4"]),
|
33
|
+
Posto::Application.new(Stub.like(:command => "done", :params => ["4"]), mock, Mock.new).run([])
|
28
34
|
Mock.verify(mock).done([], 4)
|
29
35
|
end
|
30
36
|
|
31
37
|
def test_add
|
32
38
|
mock = Mock.new
|
33
|
-
Posto::Application.new(Stub.like(:command => "add", :params => ["a brand new item"]),
|
39
|
+
Posto::Application.new(Stub.like(:command => "add", :params => ["a brand new item"]), mock, Mock.new).run([])
|
34
40
|
Mock.verify(mock).add([], "a brand new item")
|
35
41
|
end
|
42
|
+
|
43
|
+
def test_quick
|
44
|
+
mock = Mock.new
|
45
|
+
Posto::Application.new(Stub.like(:command => "quick", :params => ["4"]), mock, Mock.new).run([])
|
46
|
+
Mock.verify(mock).quick([], 4)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_top
|
50
|
+
mock = Mock.new
|
51
|
+
Posto::Application.new(Stub.like(:command => "top", :params => ["4"]), mock, Mock.new).run([])
|
52
|
+
Mock.verify(mock).top([], 4)
|
53
|
+
end
|
36
54
|
end
|
data/test/arguments_test.rb
CHANGED
@@ -10,7 +10,7 @@ class ArgumentsTest < MiniTest::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_command
|
13
|
-
assert_equal("
|
13
|
+
assert_equal("list", Posto::Arguments.new([]).command)
|
14
14
|
assert_equal("sort", Posto::Arguments.new(%w(sort)).command)
|
15
15
|
assert_equal("done", Posto::Arguments.new(%w(done 5)).command)
|
16
16
|
end
|
data/test/list_test.rb
CHANGED
@@ -42,10 +42,28 @@ class ListTest < MiniTest::Unit::TestCase
|
|
42
42
|
Posto::List.done(["1. this is one", "2. this is another", "* card molly"], 2))
|
43
43
|
end
|
44
44
|
|
45
|
+
def test_quick
|
46
|
+
assert_equal(["1. this is one (quick)", "2. this is another", "3. card molly"],
|
47
|
+
Posto::List.quick(["1. this is one", "2. this is another", "3. card molly"], 1))
|
48
|
+
assert_equal(["1. this is one (quick)", "2. this is another", "3. card molly"],
|
49
|
+
Posto::List.quick(["1. this is one (quick)", "2. this is another", "3. card molly"], 1))
|
50
|
+
assert_equal(["1. this is one", "2. this is another (quick)", "* card molly"],
|
51
|
+
Posto::List.quick(["1. this is one", "2. this is another", "* card molly"], 2))
|
52
|
+
end
|
53
|
+
|
45
54
|
def test_add
|
46
55
|
assert_equal(["1. this is another", "2. card molly", "* this is one"],
|
47
56
|
Posto::List.add(["1. this is another", "2. card molly"], "* this is one"))
|
48
57
|
assert_equal(["1. this is another", "2. card molly", "* this is one"],
|
49
|
-
|
58
|
+
Posto::List.add(["1. this is another", "2. card molly"], "this is one"))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_top
|
62
|
+
assert_equal(["1. card molly", "2. this is one", "3. this is another",],
|
63
|
+
Posto::List.top(["1. this is one", "2. this is another", "3. card molly"], 3))
|
64
|
+
assert_equal(["1. this is another", "2. this is one", "3. card molly"],
|
65
|
+
Posto::List.top(["1. this is one", "2. this is another", "3. card molly"], 2))
|
66
|
+
assert_equal(["1. this is another", "2. this is one", "* card molly"],
|
67
|
+
Posto::List.top(["1. this is one", "2. this is another", "* card molly"], 2))
|
50
68
|
end
|
51
69
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'posto/monkeypatch_array'
|
3
|
+
|
4
|
+
class MonkeypatchArrayTest < MiniTest::Unit::TestCase
|
5
|
+
def test_reject_at_returns_a_modified_array_doesnt_modify_original
|
6
|
+
remainder = [1, 2, 3].freeze.reject_at(2)
|
7
|
+
assert_equal([1, 2], remainder)
|
8
|
+
end
|
9
|
+
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.
|
4
|
+
version: 0.2.0
|
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-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description: Sort your todo list.
|
46
|
+
description: Sort your todo list from the command line.
|
47
47
|
email: mattraibert@gmail.com
|
48
48
|
executables:
|
49
49
|
- posto
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- README.md
|
55
55
|
- LICENSE.txt
|
56
56
|
- bin/posto
|
57
|
+
- lib/posto/monkeypatch_array.rb
|
57
58
|
- lib/posto/template.rb
|
58
59
|
- lib/posto/application.rb
|
59
60
|
- lib/posto/list.rb
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- test/arguments_test.rb
|
67
68
|
- test/test_helper.rb
|
68
69
|
- test/application_test.rb
|
70
|
+
- test/monkeypatch_array_test.rb
|
69
71
|
homepage: http://github.com/mattraibert/posto
|
70
72
|
licenses:
|
71
73
|
- GPLv3
|
@@ -90,10 +92,11 @@ rubyforge_project:
|
|
90
92
|
rubygems_version: 1.8.24
|
91
93
|
signing_key:
|
92
94
|
specification_version: 3
|
93
|
-
summary:
|
95
|
+
summary: CLI to sort your todo list.
|
94
96
|
test_files:
|
95
97
|
- test/list_test.rb
|
96
98
|
- test/item_test.rb
|
97
99
|
- test/arguments_test.rb
|
98
100
|
- test/test_helper.rb
|
99
101
|
- test/application_test.rb
|
102
|
+
- test/monkeypatch_array_test.rb
|