work-md 0.3.7 → 0.3.8
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 +4 -4
- data/lib/work/md/commands/parse.rb +34 -23
- data/lib/work/md/commands/today.rb +1 -1
- data/lib/work/md/commands/tyesterday.rb +1 -1
- data/lib/work/md/commands/yesterday.rb +1 -1
- data/lib/work/md/file.rb +39 -0
- data/lib/work/md/parser/engine.rb +18 -32
- data/lib/work/md/version.rb +1 -1
- data/lib/work/md.rb +0 -1
- metadata +2 -3
- data/lib/work/md/date_file.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9d7014d50eb0200a0a7c923da4abe0bf1e896190cded2efb79b71beadfdca6c
|
4
|
+
data.tar.gz: 246776e2647530b64c5756a9f44dc911055b6e6948f300065c7f03cadec4a41b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47051b17fe24d01c28cc9e1a0fe5fee3d3cddb09746d8edce69ca6ae567e303b72274b1edb6427e6527afc8bdf128e4318c2200f3c82cecb80e55dd85ac97d64
|
7
|
+
data.tar.gz: 1186bbea64e4826639f54f3fbe91cb4da2766f152409a0203a11ea68c2c852e4f439444fd0e95542457380d9d180c9fe2ea8041f4261c4408ab9659e9a5e16aa
|
@@ -7,29 +7,37 @@ module Work
|
|
7
7
|
class << self
|
8
8
|
def execute(argv = [])
|
9
9
|
parsed_file_path = Work::Md::Config.work_dir + '/parsed.md'
|
10
|
-
args = Hash[argv.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
|
11
|
-
parser = Work::Md::Parser::Engine.new
|
12
10
|
t = Work::Md::Config.translations
|
13
11
|
|
14
|
-
|
15
|
-
|
12
|
+
parser = Work::Md::Parser::Engine.new
|
13
|
+
args_hash_to_parser = -> (args, received_parser) {
|
14
|
+
year = args['y'] || Time.new.year
|
15
|
+
month = args['m'] || Time.new.month
|
16
16
|
|
17
|
-
|
17
|
+
month = "0#{month.to_i}" if month.to_i < 10
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
add_file_to_parser = lambda do |day|
|
20
|
+
day = "0#{day.to_i}" if day.to_i < 10
|
21
21
|
|
22
|
-
|
22
|
+
file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
received_parser.add_file(file_name)
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
if args['d'].include?('..')
|
28
|
+
range = args['d'].split('..')
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
(range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.call(day) }
|
31
|
+
else
|
32
|
+
args['d'].split(',').each { |day| add_file_to_parser.call(day) }
|
33
|
+
end
|
34
|
+
|
35
|
+
received_parser
|
36
|
+
}
|
37
|
+
|
38
|
+
argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
|
39
|
+
args_hash = Hash[args.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
|
40
|
+
args_hash_to_parser.(args_hash, parser)
|
33
41
|
end
|
34
42
|
|
35
43
|
parser.freeze
|
@@ -52,41 +60,44 @@ module Work
|
|
52
60
|
parser.interruptions.each do |interruption|
|
53
61
|
f.puts("- #{interruption}\n")
|
54
62
|
end
|
55
|
-
f.puts("\n") if parser.interruptions.size > 0
|
56
63
|
f.puts("---\n\n")
|
57
64
|
f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
|
58
65
|
parser.difficulties.each do |difficulty|
|
59
66
|
f.puts("- #{difficulty}\n")
|
60
67
|
end
|
61
|
-
f.puts("\n") if parser.difficulties.size > 0
|
62
68
|
f.puts("---\n\n")
|
63
69
|
f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
|
64
70
|
parser.observations.each do |observation|
|
65
71
|
f.puts("- #{observation}\n")
|
66
72
|
end
|
67
|
-
f.puts("\n") if parser.observations.size > 0
|
68
73
|
f.puts("---\n\n")
|
69
74
|
f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
|
70
75
|
f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
|
71
|
-
f.puts("\n")
|
76
|
+
f.puts("\n\n")
|
72
77
|
parser.pomodoros_bars.each do |pomodoro_bar|
|
73
78
|
f.puts(pomodoro_bar)
|
74
|
-
f.puts("\n")
|
79
|
+
f.puts("\n\n")
|
75
80
|
end
|
76
81
|
f.puts("---\n\n")
|
77
82
|
f.puts("### #{t[:days_bars]}:\n\n")
|
78
83
|
f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
|
79
84
|
|
80
|
-
f.puts("\n")
|
85
|
+
f.puts("\n\n")
|
81
86
|
parser.days_bars.each do |day_bar|
|
82
87
|
f.puts(day_bar)
|
83
|
-
f.puts("\n")
|
88
|
+
f.puts("\n\n")
|
84
89
|
end
|
85
90
|
|
86
91
|
f.puts("\n\n")
|
87
92
|
end
|
88
93
|
|
89
|
-
Work::Md::
|
94
|
+
editor = Work::Md::Config.editor
|
95
|
+
|
96
|
+
if editor.nil?
|
97
|
+
::TTY::Editor.open(parsed_file_path)
|
98
|
+
else
|
99
|
+
::TTY::Editor.open(parsed_file_path, command: editor)
|
100
|
+
end
|
90
101
|
rescue StandardError => e
|
91
102
|
Work::Md::Cli.help(
|
92
103
|
::TTY::Box.frame(
|
data/lib/work/md/file.rb
CHANGED
@@ -3,6 +3,45 @@
|
|
3
3
|
module Work
|
4
4
|
module Md
|
5
5
|
class File
|
6
|
+
def self.open_or_create(some_date, dir: nil)
|
7
|
+
open_in_editor([create_if_not_exist(some_date, dir: dir)], dir: dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.create_if_not_exist(some_date, dir: nil)
|
11
|
+
t = Work::Md::Config.translations
|
12
|
+
work_dir = dir || Work::Md::Config.work_dir
|
13
|
+
|
14
|
+
file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
|
15
|
+
|
16
|
+
return file_name if ::File.exist?("#{work_dir}/#{file_name}")
|
17
|
+
|
18
|
+
::FileUtils
|
19
|
+
.mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
|
20
|
+
|
21
|
+
::File.open(
|
22
|
+
"#{work_dir}/#{file_name}",
|
23
|
+
'w+'
|
24
|
+
) do |f|
|
25
|
+
f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{Work::Md::Config.title} \n\n")
|
26
|
+
f.puts("### #{t[:tasks]}:\n\n")
|
27
|
+
f.puts("- [ ]\n\n")
|
28
|
+
f.puts("---\n\n")
|
29
|
+
f.puts("### #{t[:meetings]}:\n\n")
|
30
|
+
f.puts("- [ ]\n\n")
|
31
|
+
f.puts("---\n\n")
|
32
|
+
f.puts("### #{t[:interruptions]}:\n\n")
|
33
|
+
f.puts("---\n\n")
|
34
|
+
f.puts("### #{t[:difficulties]}:\n\n")
|
35
|
+
f.puts("---\n\n")
|
36
|
+
f.puts("### #{t[:observations]}:\n\n")
|
37
|
+
f.puts("---\n\n")
|
38
|
+
f.puts("### #{t[:pomodoros]}:\n\n")
|
39
|
+
f.puts("0\n\n")
|
40
|
+
end
|
41
|
+
|
42
|
+
file_name
|
43
|
+
end
|
44
|
+
|
6
45
|
def self.open_in_editor(file_names = [], dir: nil)
|
7
46
|
editor = Work::Md::Config.editor
|
8
47
|
work_dir = dir || Work::Md::Config.work_dir
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'byebug'
|
4
|
-
|
5
3
|
module Work
|
6
4
|
module Md
|
7
5
|
module Parser
|
@@ -146,65 +144,53 @@ module Work
|
|
146
144
|
parsed_file.date =
|
147
145
|
content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
|
148
146
|
elsif content.start_with?(@t[:tasks])
|
149
|
-
parsed_file.tasks = parse_check_list(content
|
147
|
+
parsed_file.tasks = parse_check_list(content)
|
150
148
|
elsif content.start_with?(@t[:meetings])
|
151
|
-
parsed_file.meetings = parse_check_list(content
|
149
|
+
parsed_file.meetings = parse_check_list(content)
|
152
150
|
elsif content.start_with?(@t[:interruptions])
|
153
151
|
parsed_file.interruptions =
|
154
|
-
parse_list(content
|
152
|
+
parse_list(content).map do |interruption|
|
155
153
|
"(#{parsed_file.date}) #{interruption}"
|
156
154
|
end
|
157
155
|
elsif content.start_with?(@t[:difficulties])
|
158
|
-
parsed_file.difficulties =
|
159
|
-
|
160
|
-
|
161
|
-
).map do |difficulty|
|
162
|
-
"(#{parsed_file.date}) #{difficulty}"
|
163
|
-
end
|
156
|
+
parsed_file.difficulties = parse_list(content).map do |difficulty|
|
157
|
+
"(#{parsed_file.date}) #{difficulty}"
|
158
|
+
end
|
164
159
|
elsif content.start_with?(@t[:observations])
|
165
|
-
parsed_file.observations =
|
166
|
-
|
167
|
-
|
168
|
-
).map do |observations|
|
169
|
-
"(#{parsed_file.date}) #{observations}"
|
170
|
-
end
|
160
|
+
parsed_file.observations = parse_list(content).map do |observations|
|
161
|
+
"(#{parsed_file.date}) #{observations}"
|
162
|
+
end
|
171
163
|
elsif content.start_with?(@t[:pomodoros])
|
172
|
-
parsed_file.pomodoros =
|
173
|
-
parse_pomodoro(content, start_with: @t[:pomodoros])
|
164
|
+
parsed_file.pomodoros = parse_pomodoro(content)
|
174
165
|
end
|
175
166
|
end
|
176
167
|
# rubocop:enable Metrics/CyclomaticComplexity
|
177
168
|
# rubocop:enable Metrics/PerceivedComplexity
|
178
169
|
|
179
|
-
def parse_check_list(content
|
180
|
-
clear_list(basic_parse(content
|
170
|
+
def parse_check_list(content)
|
171
|
+
clear_list(basic_parse(content).split('- ['))
|
181
172
|
end
|
182
173
|
|
183
|
-
def parse_list(content
|
184
|
-
clear_list(basic_parse(content
|
174
|
+
def parse_list(content)
|
175
|
+
clear_list(basic_parse(content).split('- '))
|
185
176
|
end
|
186
177
|
|
187
|
-
def parse_pomodoro(content
|
188
|
-
basic_parse(content
|
178
|
+
def parse_pomodoro(content)
|
179
|
+
basic_parse(content).scan(/\d+/).first.to_i
|
189
180
|
end
|
190
181
|
|
191
|
-
def basic_parse(content
|
192
|
-
return content.split("#{start_with}:\n")[1] unless start_with.nil?
|
193
|
-
|
182
|
+
def basic_parse(content)
|
194
183
|
content.split(":\n\n")[1]
|
195
184
|
end
|
196
185
|
|
197
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
198
186
|
def clear_list(list)
|
199
187
|
return list unless list.is_a?(Array)
|
200
188
|
|
201
189
|
list
|
202
190
|
.map { |s| s.gsub('---', '') unless s.nil? }
|
203
|
-
.select { |s| (s !=
|
191
|
+
.select { |s| (s != '') && (s != "\n\n") }
|
204
192
|
.map(&:strip)
|
205
|
-
.reject { |s| (s == '') }
|
206
193
|
end
|
207
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
208
194
|
end
|
209
195
|
# rubocop:enable Metrics/ClassLength
|
210
196
|
end
|
data/lib/work/md/version.rb
CHANGED
data/lib/work/md.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.8
|
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-09-
|
11
|
+
date: 2021-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-box
|
@@ -58,7 +58,6 @@ files:
|
|
58
58
|
- lib/work/md/commands/tyesterday.rb
|
59
59
|
- lib/work/md/commands/yesterday.rb
|
60
60
|
- lib/work/md/config.rb
|
61
|
-
- lib/work/md/date_file.rb
|
62
61
|
- lib/work/md/file.rb
|
63
62
|
- lib/work/md/parser/engine.rb
|
64
63
|
- lib/work/md/version.rb
|
data/lib/work/md/date_file.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Work
|
4
|
-
module Md
|
5
|
-
class DateFile
|
6
|
-
def self.open_or_create(some_date, dir: nil)
|
7
|
-
Work::Md::File.open_in_editor(
|
8
|
-
[create_if_not_exist(some_date, dir: dir)], dir: dir
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.create_if_not_exist(some_date, dir: nil)
|
13
|
-
t = Work::Md::Config.translations
|
14
|
-
work_dir = dir || Work::Md::Config.work_dir
|
15
|
-
|
16
|
-
file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
|
17
|
-
|
18
|
-
return file_name if ::File.exist?("#{work_dir}/#{file_name}")
|
19
|
-
|
20
|
-
::FileUtils
|
21
|
-
.mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
|
22
|
-
|
23
|
-
::File.open(
|
24
|
-
"#{work_dir}/#{file_name}",
|
25
|
-
'w+'
|
26
|
-
) do |f|
|
27
|
-
f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{Work::Md::Config.title} \n\n")
|
28
|
-
f.puts("### #{t[:tasks]}:\n\n")
|
29
|
-
f.puts("- [ ]\n\n")
|
30
|
-
f.puts("---\n\n")
|
31
|
-
f.puts("### #{t[:meetings]}:\n\n")
|
32
|
-
f.puts("- [ ]\n\n")
|
33
|
-
f.puts("---\n\n")
|
34
|
-
f.puts("### #{t[:interruptions]}:\n\n")
|
35
|
-
f.puts("---\n\n")
|
36
|
-
f.puts("### #{t[:difficulties]}:\n\n")
|
37
|
-
f.puts("---\n\n")
|
38
|
-
f.puts("### #{t[:observations]}:\n\n")
|
39
|
-
f.puts("---\n\n")
|
40
|
-
f.puts("### #{t[:pomodoros]}:\n\n")
|
41
|
-
f.puts("0\n\n")
|
42
|
-
end
|
43
|
-
|
44
|
-
file_name
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|