work-md 0.3.6 → 0.3.7
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/commands/parse.rb +8 -11
- 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/date_file.rb +48 -0
- data/lib/work/md/file.rb +0 -39
- data/lib/work/md/parser/engine.rb +32 -18
- 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: e3e5c50b3a58fbb2102a71ad9775bdda5a038e04b3de55239374687f8bf20ec3
|
4
|
+
data.tar.gz: 6d22a2e28863587fa77752ae6fa08af6f873a150673387cb8c93df7a35dc4bf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a98486a920060972642e1f6b2ae2031bf86f9266142e5ea4b35dd414df1cb96c748052286b5d50a8424210cf71d787adb0ead59b562b61cbf0cbadac3854e76
|
7
|
+
data.tar.gz: e8ebb85ee0d061208e1160f662e2aeb3ac18810014891908f09beb5d59ed4d5e0aa082f67f99a1af85650f25e52679f6c994a54dc0de44e12bcbc79a5fba2873
|
@@ -52,44 +52,41 @@ module Work
|
|
52
52
|
parser.interruptions.each do |interruption|
|
53
53
|
f.puts("- #{interruption}\n")
|
54
54
|
end
|
55
|
+
f.puts("\n") if parser.interruptions.size > 0
|
55
56
|
f.puts("---\n\n")
|
56
57
|
f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
|
57
58
|
parser.difficulties.each do |difficulty|
|
58
59
|
f.puts("- #{difficulty}\n")
|
59
60
|
end
|
61
|
+
f.puts("\n") if parser.difficulties.size > 0
|
60
62
|
f.puts("---\n\n")
|
61
63
|
f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
|
62
64
|
parser.observations.each do |observation|
|
63
65
|
f.puts("- #{observation}\n")
|
64
66
|
end
|
67
|
+
f.puts("\n") if parser.observations.size > 0
|
65
68
|
f.puts("---\n\n")
|
66
69
|
f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
|
67
70
|
f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
|
68
|
-
f.puts("\n
|
71
|
+
f.puts("\n")
|
69
72
|
parser.pomodoros_bars.each do |pomodoro_bar|
|
70
73
|
f.puts(pomodoro_bar)
|
71
|
-
f.puts("\n
|
74
|
+
f.puts("\n")
|
72
75
|
end
|
73
76
|
f.puts("---\n\n")
|
74
77
|
f.puts("### #{t[:days_bars]}:\n\n")
|
75
78
|
f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
|
76
79
|
|
77
|
-
f.puts("\n
|
80
|
+
f.puts("\n")
|
78
81
|
parser.days_bars.each do |day_bar|
|
79
82
|
f.puts(day_bar)
|
80
|
-
f.puts("\n
|
83
|
+
f.puts("\n")
|
81
84
|
end
|
82
85
|
|
83
86
|
f.puts("\n\n")
|
84
87
|
end
|
85
88
|
|
86
|
-
|
87
|
-
|
88
|
-
if editor.nil?
|
89
|
-
::TTY::Editor.open(parsed_file_path)
|
90
|
-
else
|
91
|
-
::TTY::Editor.open(parsed_file_path, command: editor)
|
92
|
-
end
|
89
|
+
Work::Md::File.open_in_editor([parsed_file_path])
|
93
90
|
rescue StandardError => e
|
94
91
|
Work::Md::Cli.help(
|
95
92
|
::TTY::Box.frame(
|
@@ -0,0 +1,48 @@
|
|
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
|
data/lib/work/md/file.rb
CHANGED
@@ -3,45 +3,6 @@
|
|
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
|
-
|
45
6
|
def self.open_in_editor(file_names = [], dir: nil)
|
46
7
|
editor = Work::Md::Config.editor
|
47
8
|
work_dir = dir || Work::Md::Config.work_dir
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'byebug'
|
4
|
+
|
3
5
|
module Work
|
4
6
|
module Md
|
5
7
|
module Parser
|
@@ -144,53 +146,65 @@ module Work
|
|
144
146
|
parsed_file.date =
|
145
147
|
content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
|
146
148
|
elsif content.start_with?(@t[:tasks])
|
147
|
-
parsed_file.tasks = parse_check_list(content)
|
149
|
+
parsed_file.tasks = parse_check_list(content, start_with: @t[:tasks])
|
148
150
|
elsif content.start_with?(@t[:meetings])
|
149
|
-
parsed_file.meetings = parse_check_list(content)
|
151
|
+
parsed_file.meetings = parse_check_list(content, start_with: @t[:meetings])
|
150
152
|
elsif content.start_with?(@t[:interruptions])
|
151
153
|
parsed_file.interruptions =
|
152
|
-
parse_list(content).map do |interruption|
|
154
|
+
parse_list(content, start_with: @t[:interruptions]).map do |interruption|
|
153
155
|
"(#{parsed_file.date}) #{interruption}"
|
154
156
|
end
|
155
157
|
elsif content.start_with?(@t[:difficulties])
|
156
|
-
parsed_file.difficulties =
|
157
|
-
|
158
|
-
|
158
|
+
parsed_file.difficulties =
|
159
|
+
parse_list(
|
160
|
+
content, start_with: @t[:difficulties]
|
161
|
+
).map do |difficulty|
|
162
|
+
"(#{parsed_file.date}) #{difficulty}"
|
163
|
+
end
|
159
164
|
elsif content.start_with?(@t[:observations])
|
160
|
-
parsed_file.observations =
|
161
|
-
|
162
|
-
|
165
|
+
parsed_file.observations =
|
166
|
+
parse_list(
|
167
|
+
content, start_with: @t[:observations]
|
168
|
+
).map do |observations|
|
169
|
+
"(#{parsed_file.date}) #{observations}"
|
170
|
+
end
|
163
171
|
elsif content.start_with?(@t[:pomodoros])
|
164
|
-
parsed_file.pomodoros =
|
172
|
+
parsed_file.pomodoros =
|
173
|
+
parse_pomodoro(content, start_with: @t[:pomodoros])
|
165
174
|
end
|
166
175
|
end
|
167
176
|
# rubocop:enable Metrics/CyclomaticComplexity
|
168
177
|
# rubocop:enable Metrics/PerceivedComplexity
|
169
178
|
|
170
|
-
def parse_check_list(content)
|
171
|
-
clear_list(basic_parse(content).split('- ['))
|
179
|
+
def parse_check_list(content, start_with: nil)
|
180
|
+
clear_list(basic_parse(content, start_with: start_with).split('- ['))
|
172
181
|
end
|
173
182
|
|
174
|
-
def parse_list(content)
|
175
|
-
clear_list(basic_parse(content).split('- '))
|
183
|
+
def parse_list(content, start_with: nil)
|
184
|
+
clear_list(basic_parse(content, start_with: start_with).split('- '))
|
176
185
|
end
|
177
186
|
|
178
|
-
def parse_pomodoro(content)
|
179
|
-
basic_parse(content).scan(/\d+/).first.to_i
|
187
|
+
def parse_pomodoro(content, start_with: nil)
|
188
|
+
basic_parse(content, start_with: start_with).scan(/\d+/).first.to_i
|
180
189
|
end
|
181
190
|
|
182
|
-
def basic_parse(content)
|
191
|
+
def basic_parse(content, start_with: nil)
|
192
|
+
return content.split("#{start_with}:\n")[1] unless start_with.nil?
|
193
|
+
|
183
194
|
content.split(":\n\n")[1]
|
184
195
|
end
|
185
196
|
|
197
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
186
198
|
def clear_list(list)
|
187
199
|
return list unless list.is_a?(Array)
|
188
200
|
|
189
201
|
list
|
190
202
|
.map { |s| s.gsub('---', '') unless s.nil? }
|
191
|
-
.select { |s| (s !=
|
203
|
+
.select { |s| (s != "\n\n") && (s != "\n\n\n") }
|
192
204
|
.map(&:strip)
|
205
|
+
.reject { |s| (s == '') }
|
193
206
|
end
|
207
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
194
208
|
end
|
195
209
|
# rubocop:enable Metrics/ClassLength
|
196
210
|
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.7
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-box
|
@@ -58,6 +58,7 @@ 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
|
61
62
|
- lib/work/md/file.rb
|
62
63
|
- lib/work/md/parser/engine.rb
|
63
64
|
- lib/work/md/version.rb
|