work-md 0.4.1 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/work/md/cli.rb +16 -2
- data/lib/work/md/commands/parse.rb +12 -68
- data/lib/work/md/commands/plast.rb +63 -0
- data/lib/work/md/file.rb +61 -0
- data/lib/work/md/parser/engine.rb +30 -8
- data/lib/work/md/version.rb +1 -1
- data/lib/work/md.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e11b12242f29e25b4cd175693b475d548e37c422f966cca7c4ecdd7ae7bbf23
|
4
|
+
data.tar.gz: 7707b5b4ddbcf93fcfa22209eafcfd214de35cf56faec7739ed2b3239af33cd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49da10202bf64a92baff477f92ad3cb510e8445ef4792b64298f0449680862b0b241ed8a710f047dd846ee5cf9d53930b9bc1594ca1a4e9fcaa29b6adef8ad0e
|
7
|
+
data.tar.gz: 932cc585bf763de7d26eade30b48a903885ba23a17a5a6594e3d088f598a7b99fbb99414bb98b0042b2b351f7a32e740c8c0bd74f82851afd2960235ec5aa06d
|
data/lib/work/md/cli.rb
CHANGED
@@ -12,6 +12,7 @@ module Work
|
|
12
12
|
'y' => 'yesterday',
|
13
13
|
'c' => 'config',
|
14
14
|
'p' => 'parse',
|
15
|
+
'pl' => 'plast',
|
15
16
|
'a' => 'annotations',
|
16
17
|
'l' => 'last',
|
17
18
|
'tl' => 'tlast'
|
@@ -19,6 +20,14 @@ module Work
|
|
19
20
|
|
20
21
|
def self.execute(argv)
|
21
22
|
first_argv_argument = argv.shift
|
23
|
+
tag = fetch_argv_keys(argv)['tag']
|
24
|
+
|
25
|
+
if tag
|
26
|
+
ENV['WORK_MD_TAG'] = tag
|
27
|
+
argv.reject! { |arg| arg.include?('-tag=') }
|
28
|
+
end
|
29
|
+
|
30
|
+
::FileUtils.mkdir_p(Work::Md::Config.work_dir)
|
22
31
|
|
23
32
|
raise CommandMissing if first_argv_argument.nil?
|
24
33
|
|
@@ -29,7 +38,7 @@ module Work
|
|
29
38
|
Object
|
30
39
|
.const_get("Work::Md::Commands::#{command}")
|
31
40
|
.send(:execute, argv)
|
32
|
-
rescue NameError
|
41
|
+
rescue NameError
|
33
42
|
puts help(
|
34
43
|
::TTY::Box.frame(
|
35
44
|
"Command '#{first_argv_argument}' not found!",
|
@@ -55,10 +64,11 @@ module Work
|
|
55
64
|
'- work-md last',
|
56
65
|
'- work-md tlast',
|
57
66
|
'- work-md parse',
|
67
|
+
'- work-md plast',
|
58
68
|
'- work-md annotations',
|
59
69
|
'- work-md config',
|
60
70
|
'',
|
61
|
-
'more information
|
71
|
+
'for more information: github.com/work-md',
|
62
72
|
padding: 1,
|
63
73
|
title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
|
64
74
|
)
|
@@ -71,6 +81,10 @@ module Work
|
|
71
81
|
title: { top_left: '(error)' }
|
72
82
|
}
|
73
83
|
end
|
84
|
+
|
85
|
+
def self.fetch_argv_keys(argv)
|
86
|
+
Hash[argv.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
|
87
|
+
end
|
74
88
|
end
|
75
89
|
end
|
76
90
|
end
|
@@ -6,13 +6,10 @@ module Work
|
|
6
6
|
class Parse
|
7
7
|
class << self
|
8
8
|
def execute(argv = [])
|
9
|
-
parsed_file_path = Work::Md::Config.work_dir + '/parsed.md'
|
10
|
-
t = Work::Md::Config.translations
|
11
|
-
|
12
9
|
parser = Work::Md::Parser::Engine.new
|
13
|
-
|
14
|
-
year =
|
15
|
-
month =
|
10
|
+
argv_keys_to_parser = -> (argv_keys, received_parser) {
|
11
|
+
year = argv_keys['y'] || Time.new.year
|
12
|
+
month = argv_keys['m'] || Time.new.month
|
16
13
|
|
17
14
|
month = "0#{month.to_i}" if month.to_i < 10
|
18
15
|
|
@@ -24,81 +21,28 @@ module Work
|
|
24
21
|
received_parser.add_file(file_name)
|
25
22
|
end
|
26
23
|
|
27
|
-
if
|
28
|
-
range =
|
24
|
+
if argv_keys['d'].include?('..')
|
25
|
+
range = argv_keys['d'].split('..')
|
29
26
|
|
30
27
|
(range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.call(day) }
|
31
28
|
else
|
32
|
-
|
29
|
+
argv_keys['d'].split(',').each { |day| add_file_to_parser.call(day) }
|
33
30
|
end
|
34
31
|
|
35
32
|
received_parser
|
36
33
|
}
|
37
34
|
|
38
35
|
argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
|
39
|
-
|
40
|
-
args_hash_to_parser.(args_hash, parser)
|
41
|
-
end
|
42
|
-
|
43
|
-
parser.freeze
|
44
|
-
|
45
|
-
::File.delete(parsed_file_path) if ::File.exist? parsed_file_path
|
46
|
-
|
47
|
-
::File.open(parsed_file_path, 'w+') do |f|
|
48
|
-
f.puts("# #{Work::Md::Config.title}\n\n")
|
49
|
-
f.puts("### #{t[:tasks]} (#{parser.tasks.size}):\n\n")
|
50
|
-
parser.tasks.each do |task|
|
51
|
-
f.puts("- [#{task}\n\n") if task != ' ]'
|
52
|
-
end
|
53
|
-
f.puts("---\n\n")
|
54
|
-
f.puts("### #{t[:meetings]} (#{parser.meetings.size}):\n\n")
|
55
|
-
parser.meetings.each do |meeting|
|
56
|
-
f.puts("- [#{meeting}\n\n") if meeting != ' ]'
|
57
|
-
end
|
58
|
-
f.puts("---\n\n")
|
59
|
-
f.puts("### #{t[:interruptions]} (#{parser.interruptions.size}):\n\n")
|
60
|
-
parser.interruptions.each do |interruption|
|
61
|
-
f.puts("- #{interruption}\n")
|
62
|
-
end
|
63
|
-
f.puts("\n") if parser.interruptions.size > 0
|
64
|
-
f.puts("---\n\n")
|
65
|
-
f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
|
66
|
-
parser.difficulties.each do |difficulty|
|
67
|
-
f.puts("- #{difficulty}\n")
|
68
|
-
end
|
69
|
-
f.puts("\n") if parser.difficulties.size > 0
|
70
|
-
f.puts("---\n\n")
|
71
|
-
f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
|
72
|
-
parser.observations.each do |observation|
|
73
|
-
f.puts("- #{observation}\n")
|
74
|
-
end
|
75
|
-
f.puts("\n") if parser.observations.size > 0
|
76
|
-
f.puts("---\n\n")
|
77
|
-
f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
|
78
|
-
f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
|
79
|
-
f.puts("\n")
|
80
|
-
parser.pomodoros_bars.each do |pomodoro_bar|
|
81
|
-
f.puts(pomodoro_bar)
|
82
|
-
f.puts("\n")
|
83
|
-
end
|
84
|
-
f.puts("---\n\n")
|
85
|
-
f.puts("### #{t[:days_bars]}:\n\n")
|
86
|
-
f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
|
87
|
-
|
88
|
-
f.puts("\n")
|
89
|
-
parser.days_bars.each do |day_bar|
|
90
|
-
f.puts(day_bar)
|
91
|
-
f.puts("\n")
|
92
|
-
end
|
93
|
-
|
94
|
-
f.puts("\n\n")
|
36
|
+
argv_keys_to_parser.(Work::Md::Cli.fetch_argv_keys(args), parser)
|
95
37
|
end
|
96
38
|
|
97
|
-
Work::Md::File.
|
98
|
-
rescue
|
39
|
+
Work::Md::File.create_and_open_parsed(parser)
|
40
|
+
rescue Work::Md::Parser::Error => e
|
41
|
+
Work::Md::Cli.help(e.message)
|
42
|
+
rescue StandardError
|
99
43
|
Work::Md::Cli.help(
|
100
44
|
::TTY::Box.frame(
|
101
|
-
"message:
|
45
|
+
"message: Some of verified markdown files may be with an incorrect format",
|
102
46
|
'',
|
103
47
|
'Usage examples:',
|
104
48
|
'',
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Work
|
4
|
+
module Md
|
5
|
+
module Commands
|
6
|
+
class Plast
|
7
|
+
class << self
|
8
|
+
def execute(argv = [])
|
9
|
+
is_numeric = ->(str) {
|
10
|
+
str == "#{str.to_f}" || str == "#{str.to_i}"
|
11
|
+
}
|
12
|
+
|
13
|
+
if is_numeric.(argv.first)
|
14
|
+
last_n = argv.first.to_i
|
15
|
+
else
|
16
|
+
Work::Md::Cli.help(
|
17
|
+
::TTY::Box.frame(
|
18
|
+
"message: 'plast' command accept only numeric arguments, you give: #{argv.inspect}",
|
19
|
+
'',
|
20
|
+
'Usage example:',
|
21
|
+
'',
|
22
|
+
'work-md pl 7 # parse the last 7 days',
|
23
|
+
**Work::Md::Cli.error_frame_style
|
24
|
+
)
|
25
|
+
)
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
last_date = Date.today.prev_day
|
30
|
+
work_dir = Work::Md::Config.work_dir
|
31
|
+
parser = Work::Md::Parser::Engine.new
|
32
|
+
|
33
|
+
(1..last_n).map do
|
34
|
+
last_file_name = "#{last_date.strftime('%Y/%m/%d')}.md"
|
35
|
+
if ::File.exist?("#{work_dir}/#{last_file_name}")
|
36
|
+
parser.add_file("#{work_dir}/#{last_file_name}")
|
37
|
+
else
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
last_date = last_date.prev_day
|
42
|
+
end
|
43
|
+
|
44
|
+
Work::Md::File.create_and_open_parsed(parser)
|
45
|
+
rescue Work::Md::Parser::Error => e
|
46
|
+
Work::Md::Cli.help(e.message)
|
47
|
+
rescue StandardError => e
|
48
|
+
Work::Md::Cli.help(
|
49
|
+
::TTY::Box.frame(
|
50
|
+
"message: Some of verified markdown files may be with an incorrect format",
|
51
|
+
'',
|
52
|
+
'Usage example:',
|
53
|
+
'',
|
54
|
+
'work-md pl 7 # parse the last 7 days',
|
55
|
+
**Work::Md::Cli.error_frame_style
|
56
|
+
)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/work/md/file.rb
CHANGED
@@ -15,6 +15,67 @@ module Work
|
|
15
15
|
::TTY::Editor.open(file_names[0], file_names[1])
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.create_and_open_parsed(parser)
|
20
|
+
parser.freeze
|
21
|
+
|
22
|
+
parsed_file_path = Work::Md::Config.work_dir + '/parsed.md'
|
23
|
+
t = Work::Md::Config.translations
|
24
|
+
|
25
|
+
::File.delete(parsed_file_path) if ::File.exist? parsed_file_path
|
26
|
+
|
27
|
+
::File.open(parsed_file_path, 'w+') do |f|
|
28
|
+
f.puts("# #{Work::Md::Config.title}\n\n")
|
29
|
+
f.puts("### #{t[:tasks]} (#{parser.tasks.size}):\n\n")
|
30
|
+
parser.tasks.each do |task|
|
31
|
+
f.puts("- [#{task}\n\n") if task != ' ]'
|
32
|
+
end
|
33
|
+
f.puts("---\n\n")
|
34
|
+
f.puts("### #{t[:meetings]} (#{parser.meetings.size}):\n\n")
|
35
|
+
parser.meetings.each do |meeting|
|
36
|
+
f.puts("- [#{meeting}\n\n") if meeting != ' ]'
|
37
|
+
end
|
38
|
+
f.puts("---\n\n")
|
39
|
+
f.puts("### #{t[:interruptions]} (#{parser.interruptions.size}):\n\n")
|
40
|
+
parser.interruptions.each do |interruption|
|
41
|
+
f.puts("- #{interruption}\n")
|
42
|
+
end
|
43
|
+
f.puts("\n") if parser.interruptions.size.positive?
|
44
|
+
f.puts("---\n\n")
|
45
|
+
f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
|
46
|
+
parser.difficulties.each do |difficulty|
|
47
|
+
f.puts("- #{difficulty}\n")
|
48
|
+
end
|
49
|
+
f.puts("\n") if parser.difficulties.size.positive?
|
50
|
+
f.puts("---\n\n")
|
51
|
+
f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
|
52
|
+
parser.observations.each do |observation|
|
53
|
+
f.puts("- #{observation}\n")
|
54
|
+
end
|
55
|
+
f.puts("\n") if parser.observations.size.positive?
|
56
|
+
f.puts("---\n\n")
|
57
|
+
f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
|
58
|
+
f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
|
59
|
+
f.puts("\n")
|
60
|
+
parser.pomodoros_bars.each do |pomodoro_bar|
|
61
|
+
f.puts(pomodoro_bar)
|
62
|
+
f.puts("\n")
|
63
|
+
end
|
64
|
+
f.puts("---\n\n")
|
65
|
+
f.puts("### #{t[:days_bars]}:\n\n")
|
66
|
+
f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
|
67
|
+
|
68
|
+
f.puts("\n")
|
69
|
+
parser.days_bars.each do |day_bar|
|
70
|
+
f.puts(day_bar)
|
71
|
+
f.puts("\n")
|
72
|
+
end
|
73
|
+
|
74
|
+
f.puts("\n\n")
|
75
|
+
end
|
76
|
+
|
77
|
+
Work::Md::File.open_in_editor([parsed_file_path])
|
78
|
+
end
|
18
79
|
end
|
19
80
|
end
|
20
81
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
3
5
|
module Work
|
4
6
|
module Md
|
5
7
|
module Parser
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
6
10
|
# rubocop:disable Metrics/ClassLength
|
7
11
|
class Engine
|
8
12
|
IS_FROZEN_ERROR_MESSAGE = 'Work::Md::Parser::Engine is frozen'
|
@@ -28,7 +32,7 @@ module Work
|
|
28
32
|
raise IS_FROZEN_ERROR_MESSAGE if @frozen
|
29
33
|
|
30
34
|
begin
|
31
|
-
file_content = ::File.read(file)
|
35
|
+
file_content = ::File.read(file).squeeze(' ').strip
|
32
36
|
rescue Errno::ENOENT
|
33
37
|
return
|
34
38
|
end
|
@@ -108,12 +112,12 @@ module Work
|
|
108
112
|
|
109
113
|
@days_bars ||=
|
110
114
|
@parsed_files.map do |f|
|
111
|
-
pom = (1..f.pomodoros).map { '⬛' }.join
|
112
|
-
mee = f.meetings.map { '📅' }.join
|
113
|
-
int = f.interruptions.map { '⚠️' }.join
|
114
|
-
dif = f.difficulties.map { '😓' }.join
|
115
|
-
obs = f.observations.map { '📝' }.join
|
116
|
-
tas = f.tasks.map { '✔️' }.join
|
115
|
+
pom = (1..f.pomodoros).map { '⬛' }.join if f.pomodoros
|
116
|
+
mee = f.meetings.map { '📅' }.join if f.meetings
|
117
|
+
int = f.interruptions.map { '⚠️' }.join if f.interruptions
|
118
|
+
dif = f.difficulties.map { '😓' }.join if f.difficulties
|
119
|
+
obs = f.observations.map { '📝' }.join if f.observations
|
120
|
+
tas = f.tasks.map { '✔️' }.join if f.tasks
|
117
121
|
|
118
122
|
"(#{f.date}) #{pom}#{mee}#{int}#{dif}#{obs}#{tas}"
|
119
123
|
end
|
@@ -170,6 +174,19 @@ module Work
|
|
170
174
|
parsed_file.pomodoros =
|
171
175
|
parse_pomodoro(content, start_with: @t[:pomodoros])
|
172
176
|
end
|
177
|
+
rescue StandardError
|
178
|
+
# TODO: Write tests for this scenario
|
179
|
+
file_name = Date.strptime(parsed_file.date, '%d/%m/%Y').strftime('%Y/%m/%d.md')
|
180
|
+
message = ::TTY::Box.frame(
|
181
|
+
"message: Cannot parse file '#{file_name}' maybe it's in an incorrect format.",
|
182
|
+
'',
|
183
|
+
'Usage example:',
|
184
|
+
'',
|
185
|
+
'work-md pl 7 # parse the last 7 days',
|
186
|
+
**Work::Md::Cli.error_frame_style
|
187
|
+
)
|
188
|
+
|
189
|
+
raise Error, message
|
173
190
|
end
|
174
191
|
# rubocop:enable Metrics/CyclomaticComplexity
|
175
192
|
# rubocop:enable Metrics/PerceivedComplexity
|
@@ -187,7 +204,12 @@ module Work
|
|
187
204
|
end
|
188
205
|
|
189
206
|
def basic_parse(content, start_with: nil)
|
190
|
-
|
207
|
+
unless start_with.nil?
|
208
|
+
return content
|
209
|
+
.split("#{start_with}:")[1]
|
210
|
+
.squeeze(' ')
|
211
|
+
.sub("\n\n", "\n")
|
212
|
+
end
|
191
213
|
|
192
214
|
content.split(":\n\n")[1]
|
193
215
|
end
|
data/lib/work/md/version.rb
CHANGED
data/lib/work/md.rb
CHANGED
@@ -13,6 +13,7 @@ require_relative 'md/commands/last'
|
|
13
13
|
require_relative 'md/commands/tlast'
|
14
14
|
require_relative 'md/parser/engine'
|
15
15
|
require_relative 'md/commands/parse'
|
16
|
+
require_relative 'md/commands/plast'
|
16
17
|
require_relative 'md/cli'
|
17
18
|
require 'date'
|
18
19
|
require 'fileutils'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: work-md
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Fernandez Teixeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-box
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/work/md/commands/config.rb
|
57
57
|
- lib/work/md/commands/last.rb
|
58
58
|
- lib/work/md/commands/parse.rb
|
59
|
+
- lib/work/md/commands/plast.rb
|
59
60
|
- lib/work/md/commands/tlast.rb
|
60
61
|
- lib/work/md/commands/today.rb
|
61
62
|
- lib/work/md/commands/tyesterday.rb
|