work-md 0.3.6 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 06e074c584e95d069fbd320f73857798672c9f72f77400841b72620c2d3d4cc1
4
- data.tar.gz: 33ccf6bebcf8d0e2fdd54bb8a7071e35146fd608621fd4679e7f097b17a44ff0
2
+ SHA1:
3
+ metadata.gz: 536c5338145316ed33c03cf959b02c4ef1272f9c
4
+ data.tar.gz: 4aec526afbd5eb318727a0a7466813856dcba970
5
5
  SHA512:
6
- metadata.gz: d815119f5a6b395a27f709ea7f165bb16c817c5de2a669de678619f76f6ea8c76c88b0b8fad6bf4d689f5f10900ae98e69aa0d54fd6456f993b73f3df9ecfb6d
7
- data.tar.gz: 4b2031d4bf1f0a987d6dc3278eeefde64086981c370b23cd3fa978d59aa43573e6245b272ea22c767f3c49884e8db93d868ea494dddb72164f0008986f6ef758
6
+ metadata.gz: 52784d41c3612a41408ba48755e48790a96b61a76362059031a0509092106f5cbd1c6dd74b6d8dd50261d8f533a47b8df787be83bdfa780b6c20387bdad27232
7
+ data.tar.gz: d4c730abe51cd1ba28b3dbda73f3ad862b034215a054b904d2d6ab0b81c873c7b676e7e79aedd37ed6ca0cff40627daa7486ab8a4c48fc79be8e35b47fc198fd
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)
@@ -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
- year = args['y'] || Time.new.year
15
- month = args['m'] || Time.new.month
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
- month = "0#{month.to_i}" if month.to_i < 10
17
+ month = "0#{month.to_i}" if month.to_i < 10
18
18
 
19
- add_file_to_parser = lambda do |day|
20
- day = "0#{day.to_i}" if day.to_i < 10
19
+ add_file_to_parser = lambda do |day|
20
+ day = "0#{day.to_i}" if day.to_i < 10
21
21
 
22
- file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
22
+ file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
23
23
 
24
- parser.add_file(file_name)
25
- end
24
+ received_parser.add_file(file_name)
25
+ end
26
+
27
+ if args['d'].include?('..')
28
+ range = args['d'].split('..')
26
29
 
27
- if args['d'].include?('..')
28
- range = args['d'].split('..')
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
29
34
 
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) }
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,44 +60,41 @@ module Work
52
60
  parser.interruptions.each do |interruption|
53
61
  f.puts("- #{interruption}\n")
54
62
  end
63
+ f.puts("\n") if parser.interruptions.size > 0
55
64
  f.puts("---\n\n")
56
65
  f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
57
66
  parser.difficulties.each do |difficulty|
58
67
  f.puts("- #{difficulty}\n")
59
68
  end
69
+ f.puts("\n") if parser.difficulties.size > 0
60
70
  f.puts("---\n\n")
61
71
  f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
62
72
  parser.observations.each do |observation|
63
73
  f.puts("- #{observation}\n")
64
74
  end
75
+ f.puts("\n") if parser.observations.size > 0
65
76
  f.puts("---\n\n")
66
77
  f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
67
78
  f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
68
- f.puts("\n\n")
79
+ f.puts("\n")
69
80
  parser.pomodoros_bars.each do |pomodoro_bar|
70
81
  f.puts(pomodoro_bar)
71
- f.puts("\n\n")
82
+ f.puts("\n")
72
83
  end
73
84
  f.puts("---\n\n")
74
85
  f.puts("### #{t[:days_bars]}:\n\n")
75
86
  f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
76
87
 
77
- f.puts("\n\n")
88
+ f.puts("\n")
78
89
  parser.days_bars.each do |day_bar|
79
90
  f.puts(day_bar)
80
- f.puts("\n\n")
91
+ f.puts("\n")
81
92
  end
82
93
 
83
94
  f.puts("\n\n")
84
95
  end
85
96
 
86
- editor = Work::Md::Config.editor
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
97
+ Work::Md::File.open_in_editor([parsed_file_path])
93
98
  rescue StandardError => e
94
99
  Work::Md::Cli.help(
95
100
  ::TTY::Box.frame(
@@ -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
@@ -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.6'
5
+ VERSION = '0.3.10'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -3,6 +3,7 @@
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'
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.6
4
+ version: 0.3.10
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-09 00:00:00.000000000 Z
11
+ date: 2021-09-17 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,6 +49,7 @@ 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
@@ -58,15 +59,16 @@ files:
58
59
  - lib/work/md/commands/tyesterday.rb
59
60
  - lib/work/md/commands/yesterday.rb
60
61
  - lib/work/md/config.rb
62
+ - lib/work/md/date_file.rb
61
63
  - lib/work/md/file.rb
62
64
  - lib/work/md/parser/engine.rb
63
65
  - lib/work/md/version.rb
64
- homepage:
66
+ homepage:
65
67
  licenses:
66
68
  - MIT
67
69
  metadata:
68
70
  source_code_uri: https://github.com/work-md/work-md
69
- post_install_message:
71
+ post_install_message:
70
72
  rdoc_options: []
71
73
  require_paths:
72
74
  - lib
@@ -81,8 +83,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
- rubygems_version: 3.2.15
85
- signing_key:
86
+ rubyforge_project:
87
+ rubygems_version: 2.6.14.4
88
+ signing_key:
86
89
  specification_version: 4
87
90
  summary: Track your work activities, write annotations, recap what you did for a week,
88
91
  month or specific days... and much more!