work-md 0.3.10 → 0.4.3

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
- SHA1:
3
- metadata.gz: 536c5338145316ed33c03cf959b02c4ef1272f9c
4
- data.tar.gz: 4aec526afbd5eb318727a0a7466813856dcba970
2
+ SHA256:
3
+ metadata.gz: 7f44d4a6782b7211c58b01812b8ad00048ac2509abbdc60a20397dd2c16ee3a3
4
+ data.tar.gz: e1bc2d24ec7dbe29540e0105663d31c93b8da49c5a29056217ff6c7d311dee60
5
5
  SHA512:
6
- metadata.gz: 52784d41c3612a41408ba48755e48790a96b61a76362059031a0509092106f5cbd1c6dd74b6d8dd50261d8f533a47b8df787be83bdfa780b6c20387bdad27232
7
- data.tar.gz: d4c730abe51cd1ba28b3dbda73f3ad862b034215a054b904d2d6ab0b81c873c7b676e7e79aedd37ed6ca0cff40627daa7486ab8a4c48fc79be8e35b47fc198fd
6
+ metadata.gz: 587defdc3bf40c0801ea7b1f624974345e2c112cecb6417637fac295891066735440f43c3845574c524357c36453e2b84a33ade5b4ff62881f475cc3c3ecc200
7
+ data.tar.gz: 96389252eabac8037b98e2f05d56fab7631b64df53f99bc727cac903e80ffd9c22251f80ab9a29175f8768f9a11c7b9178bb68653fdaf2bd062db9120b7ff441
data/lib/work/md/cli.rb CHANGED
@@ -12,11 +12,22 @@ module Work
12
12
  'y' => 'yesterday',
13
13
  'c' => 'config',
14
14
  'p' => 'parse',
15
- 'a' => 'annotations'
15
+ 'pl' => 'plast',
16
+ 'a' => 'annotations',
17
+ 'l' => 'last',
18
+ 'tl' => 'tlast'
16
19
  }.freeze
17
20
 
18
21
  def self.execute(argv)
19
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)
20
31
 
21
32
  raise CommandMissing if first_argv_argument.nil?
22
33
 
@@ -50,11 +61,14 @@ module Work
50
61
  '- work-md today',
51
62
  '- work-md yesterday',
52
63
  '- work-md tyesterday',
64
+ '- work-md last',
65
+ '- work-md tlast',
53
66
  '- work-md parse',
67
+ '- work-md plast',
54
68
  '- work-md annotations',
55
69
  '- work-md config',
56
70
  '',
57
- 'more information in github.com/work-md',
71
+ 'for more information: github.com/work-md',
58
72
  padding: 1,
59
73
  title: { top_left: '(work-md)', bottom_right: "(v#{Work::Md::VERSION})" }
60
74
  )
@@ -67,6 +81,10 @@ module Work
67
81
  title: { top_left: '(error)' }
68
82
  }
69
83
  end
84
+
85
+ def self.fetch_argv_keys(argv)
86
+ Hash[argv.join(' ').scan(/-?([^=\s]+)(?:=(\S+))?/)]
87
+ end
70
88
  end
71
89
  end
72
90
  end
@@ -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
@@ -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,88 +21,34 @@ 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
  '',
105
- 'work-md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000',
106
- 'work-md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year',
107
- 'work-md parse -d=1,2 -m=4 | get day 1 and 2 from month 4 and current year',
108
- 'work-md parse -d=1..10 -m=4 | get day 1 to 10 from month 4 and current year',
47
+ 'work-md p -d=1 -m=5 -y=2000 # get day 1 from month 5 and year 2000',
48
+ 'work-md p -d=1,2,3 # get day 1, 2 and 3 from the current month and year',
49
+ 'work-md p -d=1,2 -m=4 # get day 1 and 2 from month 4 and current year',
50
+ 'work-md p -d=1..10 -m=4 # get day 1 to 10 from month 4 and current year',
51
+ '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',
109
52
  **Work::Md::Cli.error_frame_style
110
53
  )
111
54
  )
@@ -0,0 +1,42 @@
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
+ last_n = argv.first.to_i
10
+ last_date = Date.today.prev_day
11
+ work_dir = Work::Md::Config.work_dir
12
+ parser = Work::Md::Parser::Engine.new
13
+
14
+ (1..last_n).map do
15
+ last_file_name = "#{last_date.strftime('%Y/%m/%d')}.md"
16
+ if ::File.exist?("#{work_dir}/#{last_file_name}")
17
+ parser.add_file("#{work_dir}/#{last_file_name}")
18
+ else
19
+ nil
20
+ end
21
+
22
+ last_date = last_date.prev_day
23
+ end
24
+
25
+ Work::Md::File.create_and_open_parsed(parser)
26
+ rescue StandardError
27
+ Work::Md::Cli.help(
28
+ ::TTY::Box.frame(
29
+ "message: Some of verified markdown files may be with an incorrect format",
30
+ '',
31
+ 'Usage example:',
32
+ '',
33
+ 'work-md pl 7 # parse the last 7 days',
34
+ **Work::Md::Cli.error_frame_style
35
+ )
36
+ )
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -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
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.3.10'
5
+ VERSION = '0.4.3'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -9,8 +9,11 @@ require_relative 'md/commands/config'
9
9
  require_relative 'md/commands/yesterday'
10
10
  require_relative 'md/commands/tyesterday'
11
11
  require_relative 'md/commands/annotations'
12
+ require_relative 'md/commands/last'
13
+ require_relative 'md/commands/tlast'
12
14
  require_relative 'md/parser/engine'
13
15
  require_relative 'md/commands/parse'
16
+ require_relative 'md/commands/plast'
14
17
  require_relative 'md/cli'
15
18
  require 'date'
16
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.3.10
4
+ version: 0.4.3
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-17 00:00:00.000000000 Z
11
+ date: 2021-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -54,7 +54,10 @@ files:
54
54
  - lib/work/md/cli.rb
55
55
  - lib/work/md/commands/annotations.rb
56
56
  - lib/work/md/commands/config.rb
57
+ - lib/work/md/commands/last.rb
57
58
  - lib/work/md/commands/parse.rb
59
+ - lib/work/md/commands/plast.rb
60
+ - lib/work/md/commands/tlast.rb
58
61
  - lib/work/md/commands/today.rb
59
62
  - lib/work/md/commands/tyesterday.rb
60
63
  - lib/work/md/commands/yesterday.rb
@@ -83,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
85
88
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.6.14.4
89
+ rubygems_version: 3.2.22
88
90
  signing_key:
89
91
  specification_version: 4
90
92
  summary: Track your work activities, write annotations, recap what you did for a week,