work-md 0.4.0 → 0.4.4

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
2
  SHA256:
3
- metadata.gz: 6b2365dee8d1e62694565724b031df8975b11a9eafab0eb2290956915fdfcc89
4
- data.tar.gz: d1ef9938b25eb53b38535374872c9d567759c1ddddcee9ad3c54030277453d61
3
+ metadata.gz: 7dba8433c9dbfaa9a989aeb3fd986a1917aa54d43da9bb4af2e7389a46979938
4
+ data.tar.gz: 2d1540ff631bf222f970efe6a53504704f7f6425247732d1a83340938e9e305e
5
5
  SHA512:
6
- metadata.gz: 7e2a875215334876bc1bd28be738fe2ce8500c8186604e87797439b0f654d0dfce7049ba44f6d6d78a4f5962d72a86674d4d9b5920f1a91d56f40bcff06cc574
7
- data.tar.gz: 6b2696a31327292c75b1b62e8f17e1cb9b0cc483cd04f44f416412a73767a20f7f9ebf7baa95117d36382bb81a1e212825cb59a8060034a2f682dc0d959cc946
6
+ metadata.gz: 585e1dece08f50f1b323e751f0bf3d711c69f453773996b2281aef334e11ed564fef356425cd55ea17c79dda36d38724de2759fd717777e8aec8f16a0e1d3609
7
+ data.tar.gz: 137a09fd7e7bdffa9fa64eacc26213f148509dd68461196d9d63aec359d65ac07534ae1b24f1e4dd51af10f8d2b992c33c349a165c9c0874cf5cdb971bcf8764
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 => e
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 in github.com/work-md',
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
@@ -10,8 +10,7 @@ module Work
10
10
  current_day = Date.today.prev_day
11
11
  work_dir = Work::Md::Config.work_dir
12
12
 
13
- (1..90).each do
14
-
13
+ (1..160).each do
15
14
  file_name = "#{current_day.strftime('%Y/%m/%d')}.md"
16
15
 
17
16
  if ::File.exist?("#{work_dir}/#{file_name}")
@@ -26,7 +25,7 @@ module Work
26
25
  unless found_file
27
26
  Work::Md::Cli.help(
28
27
  ::TTY::Box.frame(
29
- "message: No file found in last 90 days",
28
+ "message: No file found in last 5 months",
30
29
  **Work::Md::Cli.error_frame_style
31
30
  )
32
31
  )
@@ -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
- args_hash_to_parser = -> (args, received_parser) {
14
- year = args['y'] || Time.new.year
15
- month = args['m'] || Time.new.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,26 @@ module Work
24
21
  received_parser.add_file(file_name)
25
22
  end
26
23
 
27
- if args['d'].include?('..')
28
- range = args['d'].split('..')
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
- args['d'].split(',').each { |day| add_file_to_parser.call(day) }
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
- args_hash = Hash[args.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
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.open_in_editor([parsed_file_path])
98
- rescue StandardError => e
39
+ Work::Md::File.create_and_open_parsed(parser)
40
+ rescue StandardError
99
41
  Work::Md::Cli.help(
100
42
  ::TTY::Box.frame(
101
- "message: #{e.message}",
43
+ "message: Some of verified markdown files may be with an incorrect format",
102
44
  '',
103
45
  'Usage examples:',
104
46
  '',
@@ -0,0 +1,61 @@
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 StandardError
46
+ Work::Md::Cli.help(
47
+ ::TTY::Box.frame(
48
+ "message: Some of verified markdown files may be with an incorrect format",
49
+ '',
50
+ 'Usage example:',
51
+ '',
52
+ 'work-md pl 7 # parse the last 7 days',
53
+ **Work::Md::Cli.error_frame_style
54
+ )
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -10,7 +10,7 @@ module Work
10
10
  work_dir = Work::Md::Config.work_dir
11
11
  last_file_name = nil
12
12
 
13
- (1..90).each do
13
+ (1..160).each do
14
14
  last_file_name = "#{last_date.strftime('%Y/%m/%d')}.md"
15
15
  break if ::File.exist?("#{work_dir}/#{last_file_name}")
16
16
 
@@ -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
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
+
76
+ Work::Md::File.open_in_editor([parsed_file_path])
77
+ end
78
+ end
18
79
  end
19
80
  end
20
81
  end
@@ -28,7 +28,7 @@ module Work
28
28
  raise IS_FROZEN_ERROR_MESSAGE if @frozen
29
29
 
30
30
  begin
31
- file_content = ::File.read(file)
31
+ file_content = ::File.read(file).squeeze(' ').strip
32
32
  rescue Errno::ENOENT
33
33
  return
34
34
  end
@@ -187,7 +187,12 @@ module Work
187
187
  end
188
188
 
189
189
  def basic_parse(content, start_with: nil)
190
- return content.split("#{start_with}:\n")[1] unless start_with.nil?
190
+ unless start_with.nil?
191
+ return content
192
+ .split("#{start_with}:")[1]
193
+ .squeeze(' ')
194
+ .sub("\n\n", "\n")
195
+ end
191
196
 
192
197
  content.split(":\n\n")[1]
193
198
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.4'
6
6
  end
7
7
  end
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.0
4
+ version: 0.4.4
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-10-21 00:00:00.000000000 Z
11
+ date: 2021-11-25 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