work-md 0.3.8 → 0.4.1

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
  SHA256:
3
- metadata.gz: c9d7014d50eb0200a0a7c923da4abe0bf1e896190cded2efb79b71beadfdca6c
4
- data.tar.gz: 246776e2647530b64c5756a9f44dc911055b6e6948f300065c7f03cadec4a41b
3
+ metadata.gz: 785ba0c00e62f155b5d1f0bd99e8aabe1f2e2a21ab969ee2d2a537cacdea905a
4
+ data.tar.gz: 1b0e7d575c2cc1dfa12286ae3a81f7e6407c23bc7e7779cacf04f88fccc3bede
5
5
  SHA512:
6
- metadata.gz: 47051b17fe24d01c28cc9e1a0fe5fee3d3cddb09746d8edce69ca6ae567e303b72274b1edb6427e6527afc8bdf128e4318c2200f3c82cecb80e55dd85ac97d64
7
- data.tar.gz: 1186bbea64e4826639f54f3fbe91cb4da2766f152409a0203a11ea68c2c852e4f439444fd0e95542457380d9d180c9fe2ea8041f4261c4408ab9659e9a5e16aa
6
+ metadata.gz: 2f29dee5202dbda4cac2ba534b4fec472188153db6f0aeda0dff409fcb0b20a0dc3a9fbb8d67b0e4ef43c492bdbf5a0aabd0ad6d1e356d4cea0d7aa5b572aa31
7
+ data.tar.gz: 7908a13d8c2515a0d149f63aa896aad7c476efde33664a66f08da9178e979f8f761a25ad5ed6b41fc6a44fa2898d3ca934ad9021575ccd6ca1079233b9a10219
data/bin/work-md.rb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/work/md'
5
+ # require 'work/md'
6
+
7
+ Work::Md::Cli.execute(ARGV)
data/lib/work/md/cli.rb CHANGED
@@ -12,7 +12,9 @@ module Work
12
12
  'y' => 'yesterday',
13
13
  'c' => 'config',
14
14
  'p' => 'parse',
15
- 'a' => 'annotations'
15
+ 'a' => 'annotations',
16
+ 'l' => 'last',
17
+ 'tl' => 'tlast'
16
18
  }.freeze
17
19
 
18
20
  def self.execute(argv)
@@ -27,7 +29,7 @@ module Work
27
29
  Object
28
30
  .const_get("Work::Md::Commands::#{command}")
29
31
  .send(:execute, argv)
30
- rescue NameError
32
+ rescue NameError => e
31
33
  puts help(
32
34
  ::TTY::Box.frame(
33
35
  "Command '#{first_argv_argument}' not found!",
@@ -50,6 +52,8 @@ module Work
50
52
  '- work-md today',
51
53
  '- work-md yesterday',
52
54
  '- work-md tyesterday',
55
+ '- work-md last',
56
+ '- work-md tlast',
53
57
  '- work-md parse',
54
58
  '- work-md annotations',
55
59
  '- work-md config',
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Work
4
+ module Md
5
+ module Commands
6
+ class Last
7
+ class << self
8
+ def execute(_argv = [])
9
+ found_file = false
10
+ current_day = Date.today.prev_day
11
+ work_dir = Work::Md::Config.work_dir
12
+
13
+ (1..160).each do
14
+ file_name = "#{current_day.strftime('%Y/%m/%d')}.md"
15
+
16
+ if ::File.exist?("#{work_dir}/#{file_name}")
17
+ Work::Md::File.open_in_editor([file_name])
18
+ found_file = true
19
+ break
20
+ end
21
+
22
+ current_day = current_day.prev_day
23
+ end
24
+
25
+ unless found_file
26
+ Work::Md::Cli.help(
27
+ ::TTY::Box.frame(
28
+ "message: No file found in last 5 months",
29
+ **Work::Md::Cli.error_frame_style
30
+ )
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -60,44 +60,41 @@ module Work
60
60
  parser.interruptions.each do |interruption|
61
61
  f.puts("- #{interruption}\n")
62
62
  end
63
+ f.puts("\n") if parser.interruptions.size > 0
63
64
  f.puts("---\n\n")
64
65
  f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
65
66
  parser.difficulties.each do |difficulty|
66
67
  f.puts("- #{difficulty}\n")
67
68
  end
69
+ f.puts("\n") if parser.difficulties.size > 0
68
70
  f.puts("---\n\n")
69
71
  f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
70
72
  parser.observations.each do |observation|
71
73
  f.puts("- #{observation}\n")
72
74
  end
75
+ f.puts("\n") if parser.observations.size > 0
73
76
  f.puts("---\n\n")
74
77
  f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
75
78
  f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
76
- f.puts("\n\n")
79
+ f.puts("\n")
77
80
  parser.pomodoros_bars.each do |pomodoro_bar|
78
81
  f.puts(pomodoro_bar)
79
- f.puts("\n\n")
82
+ f.puts("\n")
80
83
  end
81
84
  f.puts("---\n\n")
82
85
  f.puts("### #{t[:days_bars]}:\n\n")
83
86
  f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
84
87
 
85
- f.puts("\n\n")
88
+ f.puts("\n")
86
89
  parser.days_bars.each do |day_bar|
87
90
  f.puts(day_bar)
88
- f.puts("\n\n")
91
+ f.puts("\n")
89
92
  end
90
93
 
91
94
  f.puts("\n\n")
92
95
  end
93
96
 
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
97
+ Work::Md::File.open_in_editor([parsed_file_path])
101
98
  rescue StandardError => e
102
99
  Work::Md::Cli.help(
103
100
  ::TTY::Box.frame(
@@ -105,10 +102,11 @@ module Work
105
102
  '',
106
103
  'Usage examples:',
107
104
  '',
108
- 'work-md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000',
109
- 'work-md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year',
110
- 'work-md parse -d=1,2 -m=4 | get day 1 and 2 from month 4 and current year',
111
- 'work-md parse -d=1..10 -m=4 | get day 1 to 10 from month 4 and current year',
105
+ 'work-md p -d=1 -m=5 -y=2000 # get day 1 from month 5 and year 2000',
106
+ 'work-md p -d=1,2,3 # get day 1, 2 and 3 from the current month and year',
107
+ 'work-md p -d=1,2 -m=4 # get day 1 and 2 from month 4 and current year',
108
+ 'work-md p -d=1..10 -m=4 # get day 1 to 10 from month 4 and current year',
109
+ 'work-md p -d=1..25 -m=2 and -d=1..25 -m=2 -y=1999 # get day 1 to 25 from month 2 and current year and 1 to 25 from month 2 in 1999',
112
110
  **Work::Md::Cli.error_frame_style
113
111
  )
114
112
  )
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Work
4
+ module Md
5
+ module Commands
6
+ class Tlast
7
+ class << self
8
+ def execute(_argv = [])
9
+ last_date = Date.today.prev_day
10
+ work_dir = Work::Md::Config.work_dir
11
+ last_file_name = nil
12
+
13
+ (1..160).each do
14
+ last_file_name = "#{last_date.strftime('%Y/%m/%d')}.md"
15
+ break if ::File.exist?("#{work_dir}/#{last_file_name}")
16
+
17
+ last_date = last_date.prev_day
18
+ end
19
+
20
+ today_file_name = Work::Md::DateFile.create_if_not_exist(DateTime.now)
21
+
22
+ Work::Md::File.open_in_editor([today_file_name, last_file_name].compact)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -6,7 +6,7 @@ module Work
6
6
  class Today
7
7
  class << self
8
8
  def execute(_argv = [])
9
- Work::Md::File.open_or_create(DateTime.now)
9
+ Work::Md::DateFile.open_or_create(DateTime.now)
10
10
  end
11
11
  end
12
12
  end
@@ -8,7 +8,7 @@ module Work
8
8
  def execute(_argv = [])
9
9
  file_names =
10
10
  [DateTime.now, Date.today.prev_day].map do |date|
11
- Work::Md::File.create_if_not_exist(date)
11
+ Work::Md::DateFile.create_if_not_exist(date)
12
12
  end
13
13
 
14
14
  Work::Md::File.open_in_editor(file_names)
@@ -6,7 +6,7 @@ module Work
6
6
  class Yesterday
7
7
  class << self
8
8
  def execute(_argv = [])
9
- Work::Md::File.open_or_create(Date.today.prev_day)
9
+ Work::Md::DateFile.open_or_create(Date.today.prev_day)
10
10
  end
11
11
  end
12
12
  end
@@ -54,7 +54,12 @@ module Work
54
54
  end
55
55
 
56
56
  def self.work_dir
57
- ENV['WORK_MD_DIR'] || DEFAULT_WORK_DIR
57
+ dir =
58
+ ENV['WORK_MD_DIR'] || DEFAULT_WORK_DIR
59
+
60
+ return "#{dir}/#{ENV['WORK_MD_TAG']}" if ENV['WORK_MD_TAG']
61
+
62
+ dir
58
63
  end
59
64
 
60
65
  def self.translations
@@ -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
@@ -144,53 +144,65 @@ module Work
144
144
  parsed_file.date =
145
145
  content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
146
146
  elsif content.start_with?(@t[:tasks])
147
- parsed_file.tasks = parse_check_list(content)
147
+ parsed_file.tasks = parse_check_list(content, start_with: @t[:tasks])
148
148
  elsif content.start_with?(@t[:meetings])
149
- parsed_file.meetings = parse_check_list(content)
149
+ parsed_file.meetings = parse_check_list(content, start_with: @t[:meetings])
150
150
  elsif content.start_with?(@t[:interruptions])
151
151
  parsed_file.interruptions =
152
- parse_list(content).map do |interruption|
152
+ parse_list(content, start_with: @t[:interruptions]).map do |interruption|
153
153
  "(#{parsed_file.date}) #{interruption}"
154
154
  end
155
155
  elsif content.start_with?(@t[:difficulties])
156
- parsed_file.difficulties = parse_list(content).map do |difficulty|
157
- "(#{parsed_file.date}) #{difficulty}"
158
- end
156
+ parsed_file.difficulties =
157
+ parse_list(
158
+ content, start_with: @t[:difficulties]
159
+ ).map do |difficulty|
160
+ "(#{parsed_file.date}) #{difficulty}"
161
+ end
159
162
  elsif content.start_with?(@t[:observations])
160
- parsed_file.observations = parse_list(content).map do |observations|
161
- "(#{parsed_file.date}) #{observations}"
162
- end
163
+ parsed_file.observations =
164
+ parse_list(
165
+ content, start_with: @t[:observations]
166
+ ).map do |observations|
167
+ "(#{parsed_file.date}) #{observations}"
168
+ end
163
169
  elsif content.start_with?(@t[:pomodoros])
164
- parsed_file.pomodoros = parse_pomodoro(content)
170
+ parsed_file.pomodoros =
171
+ parse_pomodoro(content, start_with: @t[:pomodoros])
165
172
  end
166
173
  end
167
174
  # rubocop:enable Metrics/CyclomaticComplexity
168
175
  # rubocop:enable Metrics/PerceivedComplexity
169
176
 
170
- def parse_check_list(content)
171
- clear_list(basic_parse(content).split('- ['))
177
+ def parse_check_list(content, start_with: nil)
178
+ clear_list(basic_parse(content, start_with: start_with).split('- ['))
172
179
  end
173
180
 
174
- def parse_list(content)
175
- clear_list(basic_parse(content).split('- '))
181
+ def parse_list(content, start_with: nil)
182
+ clear_list(basic_parse(content, start_with: start_with).split('- '))
176
183
  end
177
184
 
178
- def parse_pomodoro(content)
179
- basic_parse(content).scan(/\d+/).first.to_i
185
+ def parse_pomodoro(content, start_with: nil)
186
+ basic_parse(content, start_with: start_with).scan(/\d+/).first.to_i
180
187
  end
181
188
 
182
- def basic_parse(content)
189
+ def basic_parse(content, start_with: nil)
190
+ return content.split("#{start_with}:\n")[1] unless start_with.nil?
191
+
183
192
  content.split(":\n\n")[1]
184
193
  end
185
194
 
195
+ # rubocop:disable Metrics/CyclomaticComplexity
186
196
  def clear_list(list)
187
197
  return list unless list.is_a?(Array)
188
198
 
189
199
  list
190
200
  .map { |s| s.gsub('---', '') unless s.nil? }
191
- .select { |s| (s != '') && (s != "\n\n") }
201
+ .select { |s| (s != "\n\n") && (s != "\n\n\n") }
192
202
  .map(&:strip)
203
+ .reject { |s| (s == '') }
193
204
  end
205
+ # rubocop:enable Metrics/CyclomaticComplexity
194
206
  end
195
207
  # rubocop:enable Metrics/ClassLength
196
208
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.3.8'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -3,11 +3,14 @@
3
3
  require_relative 'md/version'
4
4
  require_relative 'md/config'
5
5
  require_relative 'md/file'
6
+ require_relative 'md/date_file'
6
7
  require_relative 'md/commands/today'
7
8
  require_relative 'md/commands/config'
8
9
  require_relative 'md/commands/yesterday'
9
10
  require_relative 'md/commands/tyesterday'
10
11
  require_relative 'md/commands/annotations'
12
+ require_relative 'md/commands/last'
13
+ require_relative 'md/commands/tlast'
11
14
  require_relative 'md/parser/engine'
12
15
  require_relative 'md/commands/parse'
13
16
  require_relative 'md/cli'
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.8
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Fernandez Teixeira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-12 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.0
41
- description:
41
+ description:
42
42
  email:
43
43
  - hriqueft@gmail.com
44
44
  executables:
@@ -49,24 +49,28 @@ files:
49
49
  - bin/console
50
50
  - bin/setup
51
51
  - bin/work-md
52
+ - bin/work-md.rb
52
53
  - lib/work/md.rb
53
54
  - lib/work/md/cli.rb
54
55
  - lib/work/md/commands/annotations.rb
55
56
  - lib/work/md/commands/config.rb
57
+ - lib/work/md/commands/last.rb
56
58
  - lib/work/md/commands/parse.rb
59
+ - lib/work/md/commands/tlast.rb
57
60
  - lib/work/md/commands/today.rb
58
61
  - lib/work/md/commands/tyesterday.rb
59
62
  - lib/work/md/commands/yesterday.rb
60
63
  - lib/work/md/config.rb
64
+ - lib/work/md/date_file.rb
61
65
  - lib/work/md/file.rb
62
66
  - lib/work/md/parser/engine.rb
63
67
  - lib/work/md/version.rb
64
- homepage:
68
+ homepage:
65
69
  licenses:
66
70
  - MIT
67
71
  metadata:
68
72
  source_code_uri: https://github.com/work-md/work-md
69
- post_install_message:
73
+ post_install_message:
70
74
  rdoc_options: []
71
75
  require_paths:
72
76
  - lib
@@ -81,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
85
  - !ruby/object:Gem::Version
82
86
  version: '0'
83
87
  requirements: []
84
- rubygems_version: 3.2.15
85
- signing_key:
88
+ rubygems_version: 3.2.22
89
+ signing_key:
86
90
  specification_version: 4
87
91
  summary: Track your work activities, write annotations, recap what you did for a week,
88
92
  month or specific days... and much more!