todo.txt 0.0.4 → 0.0.5

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: 7af738f5e615625d77dfdbeaba750c4dfb221041
4
- data.tar.gz: f95e1617537229ccc074214a67170f1ec0587774
3
+ metadata.gz: cbbe3c577a2ed572182c84fc0529403187a78d76
4
+ data.tar.gz: 955a861d58cbabfccf886e2c9fd4ea8e9520a9da
5
5
  SHA512:
6
- metadata.gz: bad651993def5ec3c2090e259a2b81c241cca0685124f47cb0fc9bdd799861c6062c99d1694a3f91093d64dab4fe0b4dc77fa4b24bce4f04927250f3c129e3ca
7
- data.tar.gz: 42b1ae217b8cd11748206bcdd5042abe4ea84417fe49826e64babfb94a0e040e27783605a14cdae1d0e4113dfe96ef6be005ff5fdf14088cc3b0bd5690d129cb
6
+ metadata.gz: 52552da4e560a61f35007feab5dcab4c5962e5defb01792885adf71ab7170d8eac923173020d089133e56b71ee75b93e3540f81649169a1c6d0746af2d2a9a7b
7
+ data.tar.gz: 8bed646c7f788d9aa5a134fa271c05b8e887986371663da9b5030e6d7ad82162b57d3acf03a73547feff0693cee01d3518f67e2e47d8dd74ef48071fb63f8f84
data/lib/todo/cli/cmd.rb CHANGED
@@ -18,8 +18,8 @@ module Todo
18
18
  opts[:file] ? Src::File.new(opts[:file]) : Src::Io.new(slice(opts, :in, :out))
19
19
  end
20
20
 
21
- def render(list, cols = nil)
22
- View.new(list, cols).render
21
+ def render(list, opts = {})
22
+ View.new(list, opts).render
23
23
  end
24
24
  end
25
25
  end
data/lib/todo/cli/list.rb CHANGED
@@ -4,20 +4,37 @@ require 'todo/data/list'
4
4
  module Todo
5
5
  class Cli
6
6
  class List < Cmd
7
- opt '-s', '--since DATE', 'Since date' do |date|
8
- opts[:since] = normalize_date(date)
7
+ opt '-f', '--format FORMAT', 'Format' do |opts, format|
8
+ opts[:format] = format
9
9
  end
10
10
 
11
- opt '-b', '--before DATE', 'Before date' do |date|
11
+ opt '-a', '--after DATE', 'After date' do |opts, date|
12
+ opts[:after] = normalize_date(date)
13
+ end
14
+
15
+ opt '-s', '--since DATE', 'Since date' do |opts, date|
16
+ opts[:after] = normalize_date(date)
17
+ end
18
+
19
+ opt '-b', '--before DATE', 'Before date' do |opts, date|
12
20
  opts[:before] = normalize_date(date)
13
21
  end
14
22
 
15
- opt '--status STATUS', 'Status' do |status|
23
+ opt '--status STATUS', 'Status' do |opts, status|
16
24
  opts[:status] = status
17
25
  end
18
26
 
27
+ opt '-p', '--project PROJECT', 'Project' do |opts, project|
28
+ opts[:projects] ||= []
29
+ opts[:projects] << project
30
+ end
31
+
32
+ opt '-t', '--text TEXT', 'Text' do |opts, text|
33
+ opts[:text] = text
34
+ end
35
+
19
36
  def run
20
- out.write(render(list.items, [:done_date, :text]))
37
+ out.write(render(list.items, format: opts[:format] || :short))
21
38
  end
22
39
 
23
40
  private
@@ -29,8 +46,8 @@ module Todo
29
46
  end
30
47
 
31
48
  def data
32
- data = slice(opts, :status, :before, :since)
33
- # data = data.merge(text: args.first)
49
+ data = slice(opts, :status, :before, :after, :projects, :text)
50
+ data = data.merge(text: args.first) if args.first
34
51
  data
35
52
  end
36
53
 
data/lib/todo/cli/push.rb CHANGED
@@ -6,7 +6,7 @@ require 'todo/src/idonethis'
6
6
  module Todo
7
7
  class Cli
8
8
  class Push < Cmd
9
- opt '-s', '--since DATE', 'Since date' do |date|
9
+ opt '-s', '--since DATE', 'Since date' do |opts, date|
10
10
  opts[:since] = normalize_date(date)
11
11
  end
12
12
 
@@ -17,7 +17,7 @@ module Todo
17
17
  }
18
18
 
19
19
  def run
20
- lines = render(list.items, [:text, :tags, :id])
20
+ lines = render(list.items, format: [:text, :tags, :id])
21
21
  src.write(lines)
22
22
  io.write(lines)
23
23
  end
@@ -1,6 +1,19 @@
1
+ require 'todo/helpers/hash/slice'
2
+
1
3
  module Todo
2
4
  module Data
3
- class Matcher < Struct.new(:item, :data)
5
+ class Matcher
6
+ ATTRS = [:id, :text, :projects, :status, :after, :before]
7
+
8
+ include Helpers::Hash::Slice
9
+
10
+ attr_reader :item, :data
11
+
12
+ def initialize(item, data)
13
+ @item = item
14
+ @data = slice(data, *ATTRS)
15
+ end
16
+
4
17
  def matches?
5
18
  return true if data.empty?
6
19
  data[:id] ? match_id : match_data
@@ -22,12 +35,16 @@ module Todo
22
35
  item.text.include?(data[:text])
23
36
  end
24
37
 
38
+ def match_projects
39
+ item.projects & data[:projects] == data[:projects]
40
+ end
41
+
25
42
  def match_status
26
43
  item.status && item.status.to_sym == normalize_status(data[:status].to_sym)
27
44
  end
28
45
 
29
- def match_since
30
- item.done_date.to_s >= data[:since].to_s
46
+ def match_after
47
+ item.done_date.to_s >= data[:after].to_s
31
48
  end
32
49
 
33
50
  def match_before
data/lib/todo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Todo
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/todo/view.rb CHANGED
@@ -3,8 +3,11 @@ require 'todo/helpers/hash/format'
3
3
  require 'todo/helpers/object/presence'
4
4
 
5
5
  module Todo
6
- class View < Struct.new(:items, :cols)
7
- COLS = [:status, :text, :tags, :id]
6
+ class View < Struct.new(:items, :opts)
7
+ FORMATS = {
8
+ full: [:status, :text, :tags, :id],
9
+ short: [:status, :done_date, :text]
10
+ }
8
11
 
9
12
  include Helpers::Hash::Format, Helpers::Object::Presence
10
13
 
@@ -43,7 +46,12 @@ module Todo
43
46
  end
44
47
 
45
48
  def cols
46
- super || COLS
49
+ format = opts[:format] || :full
50
+ FORMATS[format.to_sym] || parse_format(opts[:format])
51
+ end
52
+
53
+ def parse_format(format)
54
+ Array(format).join(':').split(/[:,]/).map(&:to_sym)
47
55
  end
48
56
  end
49
57
  end
@@ -1,13 +1,67 @@
1
1
  require 'todo/cli/list'
2
2
 
3
3
  describe Todo::Cli::List do
4
- let(:lines) { ['- foo [1]', 'x bar done:2015-12-01 [2]'] }
5
4
  let(:io) { Support::Io.new(lines.join("\n")) }
6
5
  let(:out) { Support::Io.new }
7
- let(:opts) { { in: io, out: out } }
8
6
 
9
- subject { described_class.new(nil, opts) }
7
+ subject { described_class.new([], opts.merge(in: io, out: out)) }
10
8
  before { subject.run }
11
9
 
12
- it { expect(out.readlines).to eq ['foo', '2015-12-01 bar'] }
10
+ describe 'filtering' do
11
+ let(:lines) { ['- foo +abc [1]', 'x bar done:2015-10-01 [2]', 'x baz done:2015-11-01 [2]', 'x baz +abc done:2015-12-01 [2]'] }
12
+
13
+ describe 'unfiltered' do
14
+ let(:opts) { {} }
15
+ it { expect(out.readlines).to eq ['foo +abc', '2015-10-01 bar', '2015-11-01 baz', '2015-12-01 baz +abc'] }
16
+ end
17
+
18
+ describe 'by done date' do
19
+ let(:opts) { { after: '2015-11-31' } }
20
+ it { expect(out.readlines).to eq ['2015-12-01 baz +abc'] }
21
+ end
22
+
23
+ describe 'by status :pending' do
24
+ let(:opts) { { status: :pending } }
25
+ it { expect(out.readlines).to eq ['foo +abc'] }
26
+ end
27
+
28
+ describe 'by status :done' do
29
+ let(:opts) { { status: :done } }
30
+ it { expect(out.readlines).to eq ['2015-10-01 bar', '2015-11-01 baz', '2015-12-01 baz +abc'] }
31
+ end
32
+
33
+ describe 'by status :done and :after' do
34
+ let(:opts) { { status: :done, after: '2015-11-31' } }
35
+ it { expect(out.readlines).to eq ['2015-12-01 baz +abc'] }
36
+ end
37
+
38
+ describe 'by status :done and :after' do
39
+ let(:opts) { { status: :done, after: '2015-11-01', before: '2015-11-07' } }
40
+ it { expect(out.readlines).to eq ['2015-11-01 baz'] }
41
+ end
42
+
43
+ describe 'by project' do
44
+ let(:opts) { { projects: ['abc'] } }
45
+ it { expect(out.readlines).to eq ['foo +abc', '2015-12-01 baz +abc'] }
46
+ end
47
+
48
+ describe 'by text' do
49
+ let(:opts) { { text: 'baz' } }
50
+ it { expect(out.readlines).to eq ['2015-11-01 baz', '2015-12-01 baz +abc'] }
51
+ end
52
+ end
53
+
54
+ describe 'format' do
55
+ let(:lines) { ['- foo +abc [1]', 'x bar done:2015-12-01 [2]'] }
56
+
57
+ describe 'short' do
58
+ let(:opts) { { format: 'short' } }
59
+ it { expect(out.readlines).to eq ['foo +abc', '2015-12-01 bar'] }
60
+ end
61
+
62
+ describe 'full' do
63
+ let(:opts) { { format: 'full' } }
64
+ it { expect(out.readlines).to eq ['- foo +abc [1]', 'x bar done:2015-12-01 [2]'] }
65
+ end
66
+ end
13
67
  end
@@ -3,15 +3,20 @@ require 'todo/view'
3
3
  describe Todo::View do
4
4
  let(:lines) { ['- foo [1]', 'x bar done:2015-12-01 [2]'] }
5
5
  let(:items) { Todo::Data::List.parse(lines).items }
6
- subject { described_class.new(items, cols) }
6
+ subject { described_class.new(items, format: format) }
7
7
 
8
8
  describe 'default columns' do
9
- let(:cols) {}
9
+ let(:format) {}
10
10
  it { expect(subject.render).to eq(lines) }
11
11
  end
12
12
 
13
13
  describe 'selected columns' do
14
- let(:cols) { [:done_date, :text] }
14
+ let(:format) { 'text:tags' }
15
+ it { expect(subject.render).to eq(['foo', 'bar done:2015-12-01']) }
16
+ end
17
+
18
+ describe 'format name' do
19
+ let(:format) { :short }
15
20
  it { expect(subject.render).to eq(['foo', '2015-12-01 bar']) }
16
21
  end
17
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo.txt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs