work-md 0.3.9 → 0.4.2

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: 1d60ff8b9a7a58227c03ffdd52c61da194073d81c0e527caf567222ec1603cec
4
- data.tar.gz: c4903302aa7c56acd9522c745049d219cd9c4dcbe98f5470210fa0f7476e06a7
3
+ metadata.gz: f71380cbbd01039015727e92f5de5e621b1a3511914e4a6b81ef50de192ea43d
4
+ data.tar.gz: 7952a1d0d8c232a40ac18bdf90ff5f3b728aa57b3868170821204136492b04ff
5
5
  SHA512:
6
- metadata.gz: 205437250b4aa23ed69996b1d54fe34063fe3601bb33e4b1e91f090e8fee296916fd78a5b963238471ff2291109e29a4fd39a2faad3cb9d8eeac6c4d06bb5f0a
7
- data.tar.gz: 1965c5824034763f978a1e1ab7064b390c3c73d09d4a7580ce0e1c8c09af71c5d9d693fd77372fe3142ee25bc46a273656b78937ab0ff8547a1b7732e48f0d75
6
+ metadata.gz: 11d3bc8deb4aa7ba041a171a28b825eed5ce1690a53644ab331583f219f970a58c1dfcfcf7c95460e4ab2634efad01f5bdfe9e68a754da7f859ae40c43ab9a5d
7
+ data.tar.gz: e4a5616a87b0d249ef703b775f6956af217f578bd9fc3cd88e2becd43a45d96f5daed154704e174c7e1724cf703234be2e848e5e805932275b407727c709cef6
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,10 @@ 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)
@@ -27,7 +30,7 @@ module Work
27
30
  Object
28
31
  .const_get("Work::Md::Commands::#{command}")
29
32
  .send(:execute, argv)
30
- rescue NameError
33
+ rescue NameError => e
31
34
  puts help(
32
35
  ::TTY::Box.frame(
33
36
  "Command '#{first_argv_argument}' not found!",
@@ -50,6 +53,8 @@ module Work
50
53
  '- work-md today',
51
54
  '- work-md yesterday',
52
55
  '- work-md tyesterday',
56
+ '- work-md last',
57
+ '- work-md tlast',
53
58
  '- work-md parse',
54
59
  '- work-md annotations',
55
60
  '- 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
@@ -6,9 +6,6 @@ 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
10
  args_hash_to_parser = -> (args, received_parser) {
14
11
  year = args['y'] || Time.new.year
@@ -40,61 +37,7 @@ module Work
40
37
  args_hash_to_parser.(args_hash, parser)
41
38
  end
42
39
 
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")
95
- end
96
-
97
- Work::Md::File.open_in_editor([parsed_file_path])
40
+ Work::Md::File.create_and_open_parsed(parser)
98
41
  rescue StandardError => e
99
42
  Work::Md::Cli.help(
100
43
  ::TTY::Box.frame(
@@ -102,10 +45,11 @@ module Work
102
45
  '',
103
46
  'Usage examples:',
104
47
  '',
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',
48
+ 'work-md p -d=1 -m=5 -y=2000 # get day 1 from month 5 and year 2000',
49
+ 'work-md p -d=1,2,3 # get day 1, 2 and 3 from the current month and year',
50
+ 'work-md p -d=1,2 -m=4 # get day 1 and 2 from month 4 and current year',
51
+ 'work-md p -d=1..10 -m=4 # get day 1 to 10 from month 4 and current year',
52
+ '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
53
  **Work::Md::Cli.error_frame_style
110
54
  )
111
55
  )
@@ -0,0 +1,31 @@
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
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ 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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'byebug'
4
-
5
3
  module Work
6
4
  module Md
7
5
  module Parser
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.3.9'
5
+ VERSION = '0.4.2'
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.9
4
+ version: 0.4.2
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-11-21 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,11 +49,15 @@ 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/plast.rb
60
+ - lib/work/md/commands/tlast.rb
57
61
  - lib/work/md/commands/today.rb
58
62
  - lib/work/md/commands/tyesterday.rb
59
63
  - lib/work/md/commands/yesterday.rb
@@ -62,12 +66,12 @@ files:
62
66
  - lib/work/md/file.rb
63
67
  - lib/work/md/parser/engine.rb
64
68
  - lib/work/md/version.rb
65
- homepage:
69
+ homepage:
66
70
  licenses:
67
71
  - MIT
68
72
  metadata:
69
73
  source_code_uri: https://github.com/work-md/work-md
70
- post_install_message:
74
+ post_install_message:
71
75
  rdoc_options: []
72
76
  require_paths:
73
77
  - lib
@@ -82,8 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
86
  - !ruby/object:Gem::Version
83
87
  version: '0'
84
88
  requirements: []
85
- rubygems_version: 3.2.15
86
- signing_key:
89
+ rubygems_version: 3.2.22
90
+ signing_key:
87
91
  specification_version: 4
88
92
  summary: Track your work activities, write annotations, recap what you did for a week,
89
93
  month or specific days... and much more!