work-md 0.4.8 → 0.4.91

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: 1d958b459035344108c414ccf382b6bce83acba70585accb0c4584b634d62808
4
- data.tar.gz: db98f8a2b2a2d5dacd81cfa3951b92407455e0dffacd15e2d6e08ca6f237a98c
3
+ metadata.gz: a55beb3be3c6aa6e71b58f7522f0a78fb6093370f89b6a631a3478e62623078b
4
+ data.tar.gz: bdc684d99630d3b4b41f1f9cc2fe958bc607ef3907f75c300d504764890fdf18
5
5
  SHA512:
6
- metadata.gz: 48b5aad2d02b382d86ccf273518f87ccfd3fd7248feac6de4eca364461019533dd3497066c99139dac7c34ade603459ab806f35d646ad8cfadb664bb8e4fcfc7
7
- data.tar.gz: 5d8e4ab76582f9e462a2d6286d1f5aef1a26b8e118a0f8c711ce36e1917f5f9c500c24c3357b5ef1985060d75cc0a3a777c14ef7ceba055e0791ceb41fee119c
6
+ metadata.gz: 528f98fa5f6275186ee7057dbcf165f8a5d30edfd012d2ae86fd394511055bbddc4f3405574e205bc60e742d8c8e2dbc031de864e2b669226e4c09d9128a006f
7
+ data.tar.gz: 291f52d9d0bfba1ddd6fa09fba96c54a44aeb012fcf4c664384c92c45ad97dbb74561da14da03e13508bc5ecc86eab5a64e80f4f0776ac4cc68cc9b61e6be189
data/bin/work-md.rb CHANGED
@@ -4,4 +4,4 @@
4
4
  require_relative '../lib/work/md'
5
5
  # require 'work/md'
6
6
 
7
- Work::Md::Cli.execute(ARGV)
7
+ Work::Md::Cli.execute(ARGV, development: true)
data/lib/work/md/cli.rb CHANGED
@@ -21,7 +21,7 @@ module Work
21
21
  'tl' => 'tlast'
22
22
  }.freeze
23
23
 
24
- def self.execute(argv)
24
+ def self.execute(argv, development: false)
25
25
  first_argv_argument = argv.shift
26
26
  tag = fetch_argv_keys(argv)['tag']
27
27
 
@@ -70,6 +70,7 @@ module Work
70
70
  '- work-md parse',
71
71
  '- work-md plast',
72
72
  '- work-md annotations',
73
+ '- work-md daily',
73
74
  '- work-md open',
74
75
  '- work-md config',
75
76
  '',
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Work
4
+ module Md
5
+ module Commands
6
+ class Daily
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
+ parser_today = Work::Md::Parser::Engine.new
23
+ parser_today.add_file("#{work_dir}/#{today_file_name}")
24
+ parser_today.freeze
25
+
26
+ parser_last_day = Work::Md::Parser::Engine.new
27
+ parser_last_day.add_file("#{work_dir}/#{last_file_name}")
28
+ parser_last_day.freeze
29
+
30
+ daily_file_path = work_dir + '/daily.md'
31
+ ::File.delete(daily_file_path) if ::File.exist? daily_file_path
32
+
33
+ t = Work::Md::Config.translations
34
+
35
+ ajust_line = lambda do |line|
36
+ get_first_line = ->(multiline_string) do
37
+ lines = multiline_string.split("\n")
38
+ first_line = lines.first
39
+ return first_line
40
+ end
41
+
42
+ get_first_line.call(line.sub('x]', '-').sub(']', '-'))
43
+ end
44
+
45
+ ::File.open(daily_file_path, 'w+') do |f|
46
+ f.puts("📅 Daily\n\n")
47
+ f.puts("#{t[:did]}:\n")
48
+ parser_last_day.tasks.each do |task|
49
+ f.puts("#{ajust_line.call(task)}\n") if task != ' ]'
50
+ end
51
+ parser_last_day.meetings.each do |meeting|
52
+ f.puts("#{ajust_line.call(meeting)}\n") if meeting != ' ]'
53
+ end
54
+ f.puts("\n")
55
+ f.puts("#{t[:todo]}:\n")
56
+ parser_today.tasks.each do |task|
57
+ f.puts("#{ajust_line.call(task)}\n") if task != ' ]'
58
+ end
59
+ parser_today.meetings.each do |meeting|
60
+ f.puts("#{ajust_line.call(meeting)}\n") if meeting != ' ]'
61
+ end
62
+ end
63
+
64
+ Work::Md::File.open_in_editor([daily_file_path])
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -8,9 +8,9 @@ module Work
8
8
  def execute(argv = [])
9
9
  prompt = TTY::Prompt.new
10
10
 
11
- file_names = Work::Md::DateFile.list_file_names_by_argv_query(argv)
11
+ file_paths = Work::Md::DateFile.list_file_paths_by_argv_query(argv)
12
12
 
13
- if file_names == []
13
+ if file_paths == []
14
14
  puts ::TTY::Box.frame(
15
15
  "message: File(s) not found!",
16
16
  **Work::Md::Cli.error_frame_style
@@ -19,7 +19,7 @@ module Work
19
19
  return
20
20
  end
21
21
 
22
- file_names.each do |file_name|
22
+ file_paths.each do |file_name|
23
23
  if prompt.yes?("Do you really want to delete \"#{file_name}\"!?")
24
24
  ::File.delete(file_name)
25
25
  end
@@ -27,7 +27,7 @@ module Work
27
27
  rescue StandardError
28
28
  Work::Md::Cli.help(
29
29
  ::TTY::Box.frame(
30
- "message: Some error occurred interpreting your command!",
30
+ "message: Some error occurred interpreting your command or the date sent is invalid!",
31
31
  '',
32
32
  'Usage examples:',
33
33
  '',
@@ -6,9 +6,13 @@ module Work
6
6
  class Open
7
7
  class << self
8
8
  def execute(argv = [])
9
- file_names = Work::Md::DateFile.list_file_names_by_argv_query(argv)
9
+ file_paths =
10
+ Work::Md::DateFile.list_file_paths_by_argv_query(
11
+ argv,
12
+ create_inexistent: true
13
+ )
10
14
 
11
- if file_names == []
15
+ if file_paths == []
12
16
  puts ::TTY::Box.frame(
13
17
  "message: File(s) not found!",
14
18
  **Work::Md::Cli.error_frame_style
@@ -17,11 +21,11 @@ module Work
17
21
  return
18
22
  end
19
23
 
20
- Work::Md::File.open_in_editor(file_names)
21
- rescue StandardError
24
+ Work::Md::File.open_in_editor(file_paths)
25
+ rescue
22
26
  Work::Md::Cli.help(
23
27
  ::TTY::Box.frame(
24
- "message: Some error occurred interpreting your command!",
28
+ "message: Some error occurred interpreting your command or the date sent is invalid!",
25
29
  '',
26
30
  'Usage examples:',
27
31
  '',
@@ -9,8 +9,8 @@ module Work
9
9
  parser = Work::Md::Parser::Engine.new
10
10
 
11
11
  Work::Md::DateFile
12
- .list_file_names_by_argv_query(argv)
13
- .each { |file_name| parser.add_file(file_name) }
12
+ .list_file_paths_by_argv_query(argv)
13
+ .each { |file_path| parser.add_file(file_path) }
14
14
 
15
15
  Work::Md::File.create_and_open_parsed(parser)
16
16
  rescue Work::Md::Parser::Error => e
@@ -17,7 +17,9 @@ module Work
17
17
  pomodoros: 'Pomodoros / Ciclos',
18
18
  per_day: 'por dia',
19
19
  total: 'total',
20
- days_bars: 'Resumo'
20
+ days_bars: 'Resumo',
21
+ did: 'Feito',
22
+ todo: 'Planejado'
21
23
  },
22
24
  'en' =>
23
25
  {
@@ -29,7 +31,9 @@ module Work
29
31
  pomodoros: 'Pomodoros / Cycles',
30
32
  per_day: 'per day',
31
33
  total: 'all',
32
- days_bars: 'Summary'
34
+ days_bars: 'Summary',
35
+ did: 'Done',
36
+ todo: 'To do'
33
37
  },
34
38
  'es' =>
35
39
  {
@@ -41,7 +45,9 @@ module Work
41
45
  pomodoros: 'Pomodoros / Ciclos',
42
46
  per_day: 'por día',
43
47
  total: 'total',
44
- days_bars: 'Abstracto'
48
+ days_bars: 'Abstracto',
49
+ did: 'Hecho',
50
+ todo: 'Planificado'
45
51
  }
46
52
  }.freeze
47
53
 
@@ -3,60 +3,63 @@
3
3
  module Work
4
4
  module Md
5
5
  class DateFile
6
- def self.open_or_create(some_date, dir: nil)
6
+ def self.open_or_create(some_date)
7
7
  Work::Md::File.open_in_editor(
8
- [create_if_not_exist(some_date, dir: dir)], dir: dir
8
+ [create_if_not_exist(some_date)]
9
9
  )
10
10
  end
11
11
 
12
- def self.list_file_names_by_argv_query(argv)
13
- file_names = []
12
+ def self.list_file_paths_by_argv_query(argv, create_inexistent: false)
13
+ file_paths = []
14
14
 
15
- argv_keys_to_files = -> (argv_keys, acc_file_names) {
15
+ argv_keys_to_files = lambda { |argv_keys, acc_file_paths|
16
16
  year = argv_keys['y'] || Time.new.year
17
17
  month = argv_keys['m'] || Time.new.month
18
18
 
19
19
  month = "0#{month.to_i}" if month.to_i < 10
20
20
 
21
- add_file_to_open = lambda do |day|
21
+ add_file_to_acc = lambda do |day|
22
22
  day = "0#{day.to_i}" if day.to_i < 10
23
23
 
24
- file_name = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
24
+ file_path = Work::Md::Config.work_dir + "/#{year}/#{month}/#{day}.md"
25
25
 
26
- acc_file_names.push(file_name) if ::File.exist? file_name
26
+ if create_inexistent
27
+ create_if_not_exist(DateTime.new(year.to_i, month.to_i, day.to_i))
28
+
29
+ acc_file_paths.push(file_path)
30
+ elsif ::File.exist? file_path
31
+ acc_file_paths.push(file_path)
32
+ end
27
33
  end
28
34
 
29
35
  if argv_keys['d'].include?('..')
30
36
  range = argv_keys['d'].split('..')
31
37
 
32
- (range[0].to_i..range[1].to_i).each { |day| add_file_to_open.call(day) }
38
+ (range[0].to_i..range[1].to_i).each { |day| add_file_to_acc.call(day) }
33
39
  else
34
- argv_keys['d'].split(',').each { |day| add_file_to_open.call(day) }
40
+ argv_keys['d'].split(',').each { |day| add_file_to_acc.call(day) }
35
41
  end
36
42
 
37
- acc_file_names
43
+ acc_file_paths
38
44
  }
39
45
 
40
- argv.join('#').split('#and#').map { |v| v.split("#") }.each do |args|
41
- argv_keys_to_files.(Work::Md::Cli.fetch_argv_keys(args), file_names)
46
+ argv.join('#').split('#and#').map { |v| v.split('#') }.each do |args|
47
+ argv_keys_to_files.call(Work::Md::Cli.fetch_argv_keys(args), file_paths)
42
48
  end
43
49
 
44
- file_names
50
+ file_paths
45
51
  end
46
52
 
47
- def self.create_if_not_exist(some_date, dir: nil)
53
+ def self.create_if_not_exist(some_date)
48
54
  t = Work::Md::Config.translations
49
- work_dir = dir || Work::Md::Config.work_dir
50
-
51
- file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
52
-
53
- return file_name if ::File.exist?("#{work_dir}/#{file_name}")
55
+ file = date_to_file_locations(some_date)
56
+ return file[:name] if ::File.exist?(file[:path])
54
57
 
55
58
  ::FileUtils
56
- .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
59
+ .mkdir_p(file[:dir])
57
60
 
58
61
  ::File.open(
59
- "#{work_dir}/#{file_name}",
62
+ file[:path],
60
63
  'w+'
61
64
  ) do |f|
62
65
  f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{Work::Md::Config.title} \n\n")
@@ -76,7 +79,17 @@ module Work
76
79
  f.puts("0\n\n")
77
80
  end
78
81
 
79
- file_name
82
+ file[:name]
83
+ end
84
+
85
+ def self.date_to_file_locations(some_date)
86
+ work_dir = Work::Md::Config.work_dir
87
+
88
+ {
89
+ name: "#{some_date.strftime('%Y/%m/%d')}.md",
90
+ dir: "#{work_dir}/#{some_date.strftime('%Y/%m')}",
91
+ path: "#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md"
92
+ }
80
93
  end
81
94
  end
82
95
  end
data/lib/work/md/file.rb CHANGED
@@ -3,23 +3,10 @@
3
3
  module Work
4
4
  module Md
5
5
  class File
6
- def self.open_in_editor(file_names = [], dir: nil)
7
- editor = Work::Md::Config.editor
8
- work_dir = dir || Work::Md::Config.work_dir
9
-
10
- ::FileUtils.cd(work_dir) do
11
- ENV['EDITOR'] = editor unless editor.nil?
12
-
13
- return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
14
-
15
- ::TTY::Editor.open(file_names[0], file_names[1])
16
- end
17
- end
18
-
19
6
  def self.create_and_open_parsed(parser)
20
7
  parser.freeze
21
8
 
22
- parsed_file_path = Work::Md::Config.work_dir + '/parsed.md'
9
+ parsed_file_path = "#{Work::Md::Config.work_dir}/parsed.md"
23
10
  t = Work::Md::Config.translations
24
11
 
25
12
  ::File.delete(parsed_file_path) if ::File.exist? parsed_file_path
@@ -76,6 +63,19 @@ module Work
76
63
 
77
64
  Work::Md::File.open_in_editor([parsed_file_path])
78
65
  end
66
+
67
+ def self.open_in_editor(file_names = [])
68
+ editor = Work::Md::Config.editor
69
+ work_dir = Work::Md::Config.work_dir
70
+
71
+ ::FileUtils.cd(work_dir) do
72
+ ENV['EDITOR'] = editor unless editor.nil?
73
+
74
+ return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
75
+
76
+ ::TTY::Editor.open(*file_names)
77
+ end
78
+ end
79
79
  end
80
80
  end
81
81
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Work
4
4
  module Md
5
- VERSION = '0.4.8'
5
+ VERSION = '0.4.91'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -17,6 +17,7 @@ require_relative 'md/commands/delete'
17
17
  require_relative 'md/parser/engine'
18
18
  require_relative 'md/commands/parse'
19
19
  require_relative 'md/commands/plast'
20
+ require_relative 'md/commands/daily'
20
21
  require_relative 'md/cli'
21
22
  require 'date'
22
23
  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.8
4
+ version: 0.4.91
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-12-29 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -68,6 +68,7 @@ files:
68
68
  - lib/work/md/cli.rb
69
69
  - lib/work/md/commands/annotations.rb
70
70
  - lib/work/md/commands/config.rb
71
+ - lib/work/md/commands/daily.rb
71
72
  - lib/work/md/commands/delete.rb
72
73
  - lib/work/md/commands/last.rb
73
74
  - lib/work/md/commands/open.rb
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
- rubygems_version: 3.2.22
107
+ rubygems_version: 3.3.7
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Track your work activities, write annotations, recap what you did for a week,