work-md 0.3.7 → 0.4.0

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: e3e5c50b3a58fbb2102a71ad9775bdda5a038e04b3de55239374687f8bf20ec3
4
- data.tar.gz: 6d22a2e28863587fa77752ae6fa08af6f873a150673387cb8c93df7a35dc4bf2
3
+ metadata.gz: 6b2365dee8d1e62694565724b031df8975b11a9eafab0eb2290956915fdfcc89
4
+ data.tar.gz: d1ef9938b25eb53b38535374872c9d567759c1ddddcee9ad3c54030277453d61
5
5
  SHA512:
6
- metadata.gz: 4a98486a920060972642e1f6b2ae2031bf86f9266142e5ea4b35dd414df1cb96c748052286b5d50a8424210cf71d787adb0ead59b562b61cbf0cbadac3854e76
7
- data.tar.gz: e8ebb85ee0d061208e1160f662e2aeb3ac18810014891908f09beb5d59ed4d5e0aa082f67f99a1af85650f25e52679f6c994a54dc0de44e12bcbc79a5fba2873
6
+ metadata.gz: 7e2a875215334876bc1bd28be738fe2ce8500c8186604e87797439b0f654d0dfce7049ba44f6d6d78a4f5962d72a86674d4d9b5920f1a91d56f40bcff06cc574
7
+ data.tar.gz: 6b2696a31327292c75b1b62e8f17e1cb9b0cc483cd04f44f416412a73767a20f7f9ebf7baa95117d36382bb81a1e212825cb59a8060034a2f682dc0d959cc946
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,9 @@ module Work
12
12
  'y' => 'yesterday',
13
13
  'c' => 'config',
14
14
  'p' => 'parse',
15
- 'a' => 'annotations'
15
+ 'a' => 'annotations',
16
+ 'l' => 'last',
17
+ 'tl' => 'tlast'
16
18
  }.freeze
17
19
 
18
20
  def self.execute(argv)
@@ -27,7 +29,7 @@ module Work
27
29
  Object
28
30
  .const_get("Work::Md::Commands::#{command}")
29
31
  .send(:execute, argv)
30
- rescue NameError
32
+ rescue NameError => e
31
33
  puts help(
32
34
  ::TTY::Box.frame(
33
35
  "Command '#{first_argv_argument}' not found!",
@@ -50,6 +52,8 @@ module Work
50
52
  '- work-md today',
51
53
  '- work-md yesterday',
52
54
  '- work-md tyesterday',
55
+ '- work-md last',
56
+ '- work-md tlast',
53
57
  '- work-md parse',
54
58
  '- work-md annotations',
55
59
  '- work-md config',
@@ -0,0 +1,39 @@
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..90).each do
14
+
15
+ file_name = "#{current_day.strftime('%Y/%m/%d')}.md"
16
+
17
+ if ::File.exist?("#{work_dir}/#{file_name}")
18
+ Work::Md::File.open_in_editor([file_name])
19
+ found_file = true
20
+ break
21
+ end
22
+
23
+ current_day = current_day.prev_day
24
+ end
25
+
26
+ unless found_file
27
+ Work::Md::Cli.help(
28
+ ::TTY::Box.frame(
29
+ "message: No file found in last 90 days",
30
+ **Work::Md::Cli.error_frame_style
31
+ )
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -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('..')
29
+
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
26
34
 
27
- if args['d'].include?('..')
28
- range = args['d'].split('..')
35
+ received_parser
36
+ }
29
37
 
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) }
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
@@ -94,10 +102,11 @@ module Work
94
102
  '',
95
103
  'Usage examples:',
96
104
  '',
97
- 'work-md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000',
98
- 'work-md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year',
99
- 'work-md parse -d=1,2 -m=4 | get day 1 and 2 from month 4 and current year',
100
- 'work-md parse -d=1..10 -m=4 | get day 1 to 10 from month 4 and current year',
105
+ 'work-md p -d=1 -m=5 -y=2000 # get day 1 from month 5 and year 2000',
106
+ 'work-md p -d=1,2,3 # get day 1, 2 and 3 from the current month and year',
107
+ 'work-md p -d=1,2 -m=4 # get day 1 and 2 from month 4 and current year',
108
+ 'work-md p -d=1..10 -m=4 # get day 1 to 10 from month 4 and current year',
109
+ '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',
101
110
  **Work::Md::Cli.error_frame_style
102
111
  )
103
112
  )
@@ -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..90).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
@@ -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.7'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
data/lib/work/md.rb CHANGED
@@ -9,6 +9,8 @@ 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'
14
16
  require_relative 'md/cli'
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.7
4
+ version: 0.4.0
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-10 00:00:00.000000000 Z
11
+ date: 2021-10-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,14 @@ 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/tlast.rb
57
60
  - lib/work/md/commands/today.rb
58
61
  - lib/work/md/commands/tyesterday.rb
59
62
  - lib/work/md/commands/yesterday.rb
@@ -62,12 +65,12 @@ files:
62
65
  - lib/work/md/file.rb
63
66
  - lib/work/md/parser/engine.rb
64
67
  - lib/work/md/version.rb
65
- homepage:
68
+ homepage:
66
69
  licenses:
67
70
  - MIT
68
71
  metadata:
69
72
  source_code_uri: https://github.com/work-md/work-md
70
- post_install_message:
73
+ post_install_message:
71
74
  rdoc_options: []
72
75
  require_paths:
73
76
  - lib
@@ -82,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
85
  - !ruby/object:Gem::Version
83
86
  version: '0'
84
87
  requirements: []
85
- rubygems_version: 3.2.15
86
- signing_key:
88
+ rubygems_version: 3.2.22
89
+ signing_key:
87
90
  specification_version: 4
88
91
  summary: Track your work activities, write annotations, recap what you did for a week,
89
92
  month or specific days... and much more!