todown 0.1.0 → 0.2.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
- SHA256:
3
- metadata.gz: ccb20420435b76965ded948bf05e11d263dd83f6d2868e88caedd73e5c01b2c7
4
- data.tar.gz: 80234205a46516aa54d22db14824efe22ea248310015bea8c0a352ccf7f2d11c
2
+ SHA1:
3
+ metadata.gz: 8cbdcc511e30fb27cbc3b0754a9f73201da8ad69
4
+ data.tar.gz: 2d141a38c54a73d6e18d6a3f6c5216dae8a103ef
5
5
  SHA512:
6
- metadata.gz: 22f2820d00a3a9487156a5fa68eed59f7064b7e5b81fa400c50b600772bac7b948e2159a903b7f658fbda0a97694252fad46585c1a0890c02e7bfa5ccdea8650
7
- data.tar.gz: 99bb8570df82e1ad2cad1dcc55bbc3f78c1adc0b326253b475a815ec17b2080f4c97a0c41f9aa36f438936ca69326339474f0ed572f30c0756fbc6e976b9ce4c
6
+ metadata.gz: 636a15bd9ab11c114b3abd0da1926601f33302e3e06eabe5896405133f198941d63363a515d7c9e57f3e6ea375b83e3bca3c150e3adfd45d14344cf6eaa239a5
7
+ data.tar.gz: 8a5f485fef5ae7db93a0908a22739252d259f517d1276125df75f3f37a9c374e664b9db558431cb30836911cd877734bcfb4ad30f2bfe723170bb8481db6ae90
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- todown (0.1.0)
4
+ todown (0.2.0)
5
5
  terminal-table (~> 1.8)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Extract tasks from Markdown file.
4
4
 
5
- > I wanted to organize me without use of some too complecated software.
5
+ > I wanted to organize me without use of too complicated software.
6
6
 
7
- Example:
7
+ Example with _sample.markdown_ file:
8
8
 
9
9
  ~~~txt
10
10
  # TODO
@@ -25,46 +25,51 @@ Become bellow using
25
25
 
26
26
  ~~~bash
27
27
  $ todown sample.markdown
28
- +---+----------------------+-------------------------------------+
29
- | | Name | Attributes |
30
- +---+----------------------+-------------------------------------+
31
- | X | Milk | {} |
32
- | | Sugar | {} |
33
- | | Chocolate | {:due=>"2019-02-14"} |
34
- | X | Make something great | {:with=>"ruby", :due=>"2010-01-01"} |
35
- +---+----------------------+-------------------------------------+
36
28
  ~~~
37
-
38
- you can also aply filter
39
-
40
- ~~~bash
41
- $ todown sample.markdown --field=with
42
- +---+----------------------+-------------------------------------+
43
- | | Name | Attributes |
44
- +---+----------------------+-------------------------------------+
45
- | X | Make something great | {:with=>"ruby", :due=>"2010-01-01"} |
46
- +---+----------------------+-------------------------------------+
29
+ ~~~txt
30
+ +---+----------------------+------------+------+
31
+ | | Name | due | with |
32
+ +---+----------------------+------------+------+
33
+ | X | Milk | | |
34
+ | | Sugar | | |
35
+ | | Chocolate | 2019-02-14 | |
36
+ | X | Make something great | 2010-01-01 | ruby |
37
+ +---+----------------------+------------+------+
47
38
  ~~~
48
39
 
49
- ## Installation
50
40
 
51
- Add this line to your application's Gemfile:
41
+ ## Usage
52
42
 
53
- ```ruby
54
- gem 'todown'
55
- ```
43
+ You simply define task in your markdown file using [Github task list syntax](https://blog.github.com/2014-04-28-task-lists-in-all-markdown-documents/) like this:
44
+
45
+ ~~~txt
46
+ - [x] Make something great
47
+ ~~~
56
48
 
57
- And then execute:
49
+ You can also apply filter using `@tag=value`
58
50
 
59
- $ bundle
51
+ ~~~txt
52
+ - [x] Make something great @with=ruby @due=2010-01-01
53
+ ~~~
60
54
 
61
- Or install it yourself as:
55
+ And then you can apply filter can also aply filter
62
56
 
63
- $ gem install todown
57
+ ~~~bash
58
+ $ todown sample.markdown --field=due --after=2019-01-01
59
+ ~~~
60
+ ~~~txt
61
+ +--+-----------+------------+
62
+ | | Name | due |
63
+ +--+-----------+------------+
64
+ | | Chocolate | 2019-02-14 |
65
+ +--+-----------+------------+
66
+ ~~~
64
67
 
65
- ## Usage
68
+ ## Installation
66
69
 
67
- TODO: Write usage instructions here
70
+ ```ruby
71
+ gem install todown
72
+ ```
68
73
 
69
74
  ## Development
70
75
 
@@ -74,7 +79,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
74
79
 
75
80
  ## Contributing
76
81
 
77
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/todown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/madeindjs/todown. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
78
83
 
79
84
  ## License
80
85
 
@@ -82,4 +87,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
82
87
 
83
88
  ## Code of Conduct
84
89
 
85
- Everyone interacting in the Todown project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/todown/blob/master/CODE_OF_CONDUCT.md).
90
+ Everyone interacting in the Todown project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/madeindjs/todown/blob/master/CODE_OF_CONDUCT.md).
data/bin/todown CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'todown'
3
- require 'terminal-table'
4
3
  require 'optparse'
4
+ require 'date'
5
5
 
6
6
  options = {
7
- only_finished: false,
8
- only_unfinished: false,
7
+ only_finished: false,
8
+ only_unfinished: false,
9
9
  }
10
10
 
11
11
  OptionParser.new do |opts|
@@ -23,21 +23,15 @@ OptionParser.new do |opts|
23
23
  options[:field] = o
24
24
  end
25
25
 
26
- # opts.on '-aDATE', '--after=DATE', 'Filter tasks after given date', 'Exemple: `todown --field=due --after=2018 FILE`' do |filter|
27
- # if defined? options[:field]
28
- # puts 'You should provide `-field=FIELD` argument'
29
- # exit
30
- # end
31
- # options[:after] = v
32
- # end
33
-
34
- # opts.on '-bDATE', '--before=DATE', 'Filter tasks after given date', 'Exemple: `todown --field=due --before=2018 FILE`' do |filter|
35
- # if defined? options[:field]
36
- # puts 'You should provide `-field=FIELD` argument'
37
- # exit
38
- # end
39
- # options[:before] = v
40
- # end
26
+ opts.on '-aDATE', '--after=DATE', 'Filter tasks after given date', 'Exemple: `todown --field=due --after=2018 FILE`' do |filter|
27
+ puts 'You should provide `--field=FIELD` argument' && exit if options[:field].nil?
28
+ options[:after] = Date.parse filter
29
+ end
30
+
31
+ opts.on '-bDATE', '--before=DATE', 'Filter tasks after given date', 'Exemple: `todown --field=due --before=2018 FILE`' do |filter|
32
+ puts 'You should provide `--field=FIELD` argument' && exit if options[:field].nil?
33
+ options[:before] = Date.parse filter
34
+ end
41
35
 
42
36
  if ARGV[0].nil?
43
37
  puts "You must provide a file\r\n\r\n"
@@ -48,23 +42,42 @@ end.parse!
48
42
 
49
43
  filepath = ARGV[0]
50
44
 
51
- rows = []
52
- headings = ['', 'Name', 'Attributes']
53
45
 
54
- tasks = Task.from_file filepath do |task|
46
+ tasks = []
47
+ total_count = 0
48
+
49
+ Task.from_file(filepath) do |task|
50
+ total_count += 1
55
51
  # filter
56
52
  next if options[:only_finished] and task.finished == false
57
53
  next if options[:only_unfinished] and task.finished
58
54
 
59
55
  if options.has_key? :field
56
+ # filter only element who own the specified field
60
57
  field = options[:field]
61
58
  next unless task.attributes.has_key?(field.to_sym)
62
59
  end
63
60
 
64
- status = task.finished ? 'X' : ''
65
- rows << [status, task.name, task.attributes.to_s]
61
+ if options.has_key? :after
62
+ # filter only element who are after the given date
63
+ next if task.attributes[field.to_sym] < options[:after]
64
+ end
65
+
66
+ if options.has_key? :before
67
+ # filter only element who are after the given date
68
+ next if task.attributes[field.to_sym] > options[:before]
69
+ end
70
+
71
+ tasks << task
66
72
  end
67
73
 
68
- table = Terminal::Table.new rows: rows, headings: headings
69
74
 
70
- puts table
75
+ puts Todown.task_to_table tasks
76
+
77
+ exit if total_count == 1
78
+
79
+ if options.has_key? :field
80
+ puts "%s of %s tasks displayed" % [ tasks.count, total_count]
81
+ else
82
+ puts "%s tasks displayed" % [ tasks.count ]
83
+ end
data/lib/todown/task.rb CHANGED
@@ -1,8 +1,17 @@
1
+ # Represent a task extracted from markdown file
1
2
  class Task
2
- attr_reader :name, :finished, :attributes
3
+ # @return [String] The name of the task
4
+ attr_reader :name
5
+ # @return [Boolean] The status of the task (`true` for completed, `false` for to do)
6
+ attr_reader :finished
7
+ # @return [Hash] an hash containing various attributes
8
+ attr_reader :attributes
3
9
 
4
10
  # Create many task from given filepath
5
- # @param filepath <String> filepath of readable markdown file
11
+ #
12
+ # @param filepath [String] filepath of readable markdown file
13
+ # @yield [Task]
14
+ # @return [Array<Task>]
6
15
  def self.from_file filepath
7
16
  tasks = []
8
17
 
@@ -15,6 +24,11 @@ class Task
15
24
  return tasks
16
25
  end
17
26
 
27
+ # Returns a new instance of Task
28
+ #
29
+ # @param name [String]
30
+ # @param finished [Boolean]
31
+ # @param attributes [Hash] an hash containing various attributes
18
32
  def initialize(name, finished = false, attributes = {})
19
33
  @name = name
20
34
  @finished = finished
@@ -25,6 +39,7 @@ class Task
25
39
 
26
40
  private
27
41
 
42
+ # Try to parse attributes from `Task.name`
28
43
  def parse_attributes!
29
44
  @name.scan(/@([a-z]*)=(\S+)/).each do |data|
30
45
  # insert as attribute
@@ -1,3 +1,3 @@
1
1
  module Todown
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/todown.rb CHANGED
@@ -1,6 +1,52 @@
1
1
  require "todown/version"
2
2
  require "todown/task"
3
+ require 'terminal-table'
3
4
 
4
5
  module Todown
5
- # Your code goes here...
6
+
7
+ # Create a `Terminal::Table` from many task
8
+ #
9
+ # @param tasks [Array<Task>]
10
+ # @return [Terminal::Table]
11
+ def self.task_to_table tasks
12
+ return Terminal::Table.new(Todown.task_to_hash_table(tasks))
13
+ end
14
+
15
+ # Manipulate data to transform in the expected format for `Terminal::Table`
16
+ #
17
+ # @param tasks [Array<Task>]
18
+ # @return [Hash<Symbol, Array>]
19
+ def self.task_to_hash_table tasks
20
+ rows = []
21
+ attributes_keys = []
22
+
23
+ tasks.each do |task|
24
+ task.attributes.keys.each {|key| attributes_keys << key.to_s }
25
+ end
26
+
27
+ attributes_keys.uniq!
28
+
29
+ headings = ['', 'Name'].concat attributes_keys
30
+
31
+ tasks.each do |task|
32
+ row = []
33
+ row << (task.finished ? 'X' : '')
34
+ row << task.name
35
+
36
+ # Insert attributes in the same order
37
+ attributes_keys.each do |attribute_key|
38
+ attribute_value = task.attributes[attribute_key.to_sym]
39
+ if attribute_value
40
+ row << attribute_value.to_s
41
+ else
42
+ row << ''
43
+ end
44
+ end
45
+
46
+ rows << row
47
+ end
48
+
49
+ return {rows: rows, headings: headings }
50
+ end
51
+
6
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Rousseau
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-29 00:00:00.000000000 Z
12
+ date: 2018-07-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: terminal-table
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.7.6
117
+ rubygems_version: 2.6.14
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Markdown + Task