work_md 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/work_md +1 -0
- data/lib/work_md.rb +2 -0
- data/lib/work_md/cli.rb +8 -6
- data/lib/work_md/commands/config.rb +35 -0
- data/lib/work_md/commands/parse.rb +24 -3
- data/lib/work_md/commands/tyesterday.rb +18 -0
- data/lib/work_md/config.rb +15 -2
- data/lib/work_md/file.rb +42 -29
- data/lib/work_md/parser/engine.rb +26 -5
- data/lib/work_md/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db1941195d4c4dddb02ca3375e3f1dcd099e8799330f7ac6b78ac62cb39984b5
|
4
|
+
data.tar.gz: 92c72a7d0909f34bab420fabe8c85959b23ce069908da3704cb4b016d036316f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5f618a78bab8117824f2819e7c4bf49999a4f3396e1dcd6c198fd78ef37ece4d708ffd7400f9d38eeac72a361109124bf6f9f8feb681730e44d2a65045c91f3
|
7
|
+
data.tar.gz: 3030407c84b51b4bb9caf485c88e851b824b1aadcda7ab1859a46c985066a623f74a19614fed3db1a0186822053637fc69deff49d288ab877f4adb9c023df4cf
|
data/bin/work_md
CHANGED
data/lib/work_md.rb
CHANGED
@@ -4,7 +4,9 @@ require_relative 'work_md/version'
|
|
4
4
|
require_relative 'work_md/config'
|
5
5
|
require_relative 'work_md/file'
|
6
6
|
require_relative 'work_md/commands/today'
|
7
|
+
require_relative 'work_md/commands/config'
|
7
8
|
require_relative 'work_md/commands/yesterday'
|
9
|
+
require_relative 'work_md/commands/tyesterday'
|
8
10
|
require_relative 'work_md/parser/engine'
|
9
11
|
require_relative 'work_md/commands/parse'
|
10
12
|
require_relative 'work_md/cli'
|
data/lib/work_md/cli.rb
CHANGED
@@ -7,12 +7,12 @@ module WorkMd
|
|
7
7
|
ALIAS_COMMANDS =
|
8
8
|
{
|
9
9
|
't' => 'today',
|
10
|
+
'ty' => 'tyesterday',
|
10
11
|
'y' => 'yesterday',
|
12
|
+
'c' => 'config',
|
11
13
|
'p' => 'parse'
|
12
14
|
}.freeze
|
13
15
|
|
14
|
-
DEFAULT_COMMAND = WorkMd::Commands::Today
|
15
|
-
|
16
16
|
def self.execute(argv)
|
17
17
|
first_argv_argument = argv.shift
|
18
18
|
|
@@ -25,17 +25,17 @@ module WorkMd
|
|
25
25
|
.const_get("WorkMd::Commands::#{command}")
|
26
26
|
.send(:execute, argv)
|
27
27
|
rescue NameError
|
28
|
-
puts
|
28
|
+
puts help(
|
29
29
|
::TTY::Box.frame(
|
30
30
|
"Command '#{first_argv_argument}' not found!",
|
31
31
|
**error_frame_style
|
32
32
|
)
|
33
33
|
)
|
34
34
|
rescue CommandMissing
|
35
|
-
|
35
|
+
help('Welcome! =)')
|
36
36
|
end
|
37
37
|
|
38
|
-
def self.
|
38
|
+
def self.help(message = '')
|
39
39
|
# rubocop:disable Layout/LineLength
|
40
40
|
puts ::TTY::Box.frame(
|
41
41
|
message,
|
@@ -46,9 +46,11 @@ module WorkMd
|
|
46
46
|
'- work_md',
|
47
47
|
'- work_md today',
|
48
48
|
'- work_md yesterday',
|
49
|
+
'- work_md tyesterday',
|
49
50
|
'- work_md parse',
|
51
|
+
'- work_md config',
|
50
52
|
'',
|
51
|
-
'
|
53
|
+
'more information in github.com/henriquefernandez/work_md',
|
52
54
|
padding: 1,
|
53
55
|
title: { top_left: '(work_md)', bottom_right: "(v#{WorkMd::VERSION})" }
|
54
56
|
)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WorkMd
|
4
|
+
module Commands
|
5
|
+
class Config
|
6
|
+
class << self
|
7
|
+
def execute(_argv = [])
|
8
|
+
file_name = 'config.yml'
|
9
|
+
work_dir = ::WorkMd::Config::DEFAULT_WORK_DIR
|
10
|
+
|
11
|
+
unless ::File.exist?("#{work_dir}/#{file_name}")
|
12
|
+
::FileUtils.mkdir_p(work_dir)
|
13
|
+
|
14
|
+
::File.open("#{work_dir}/#{file_name}", 'w+') do |f|
|
15
|
+
f.puts("# Example configuration:")
|
16
|
+
f.puts("#")
|
17
|
+
f.puts("# title: Your Name")
|
18
|
+
f.puts("# editor: vim")
|
19
|
+
f.puts("# lang: en")
|
20
|
+
f.puts("#")
|
21
|
+
f.puts("title: # Title your work_md files")
|
22
|
+
f.puts("editor: # Your default editor")
|
23
|
+
f.puts("lang: # Only 'pt', 'en' and 'es' avaiable")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
::WorkMd::File.open_in_editor(
|
28
|
+
file_names: [file_name],
|
29
|
+
dir: work_dir
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -17,7 +17,7 @@ module WorkMd
|
|
17
17
|
|
18
18
|
month = "0#{month.to_i}" if month.to_i < 10
|
19
19
|
|
20
|
-
|
20
|
+
add_file_to_parser = ->(day) do
|
21
21
|
day = "0#{day.to_i}" if day.to_i < 10
|
22
22
|
|
23
23
|
file_name = WorkMd::Config.work_dir + "/#{year}/#{month}/#{day}.md"
|
@@ -25,6 +25,14 @@ module WorkMd
|
|
25
25
|
parser.add_file(file_name)
|
26
26
|
end
|
27
27
|
|
28
|
+
if args['d'].include?('..')
|
29
|
+
range = args['d'].split('..')
|
30
|
+
|
31
|
+
(range[0].to_i..range[1].to_i).each { |day| add_file_to_parser.(day) }
|
32
|
+
else
|
33
|
+
args['d'].split(',').each { |day| add_file_to_parser.(day) }
|
34
|
+
end
|
35
|
+
|
28
36
|
parser.freeze
|
29
37
|
|
30
38
|
::File.delete(PARSED_FILE_PATH) if ::File.exist? PARSED_FILE_PATH
|
@@ -51,8 +59,20 @@ module WorkMd
|
|
51
59
|
f.puts("- #{difficulty}\n\n")
|
52
60
|
end
|
53
61
|
f.puts("---\n\n")
|
62
|
+
f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
|
63
|
+
parser.observations.each do |observation|
|
64
|
+
f.puts("- #{observation}\n\n")
|
65
|
+
end
|
66
|
+
f.puts("---\n\n")
|
54
67
|
f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
|
55
|
-
f.puts(parser.
|
68
|
+
f.puts(parser.pomodoros_sum)
|
69
|
+
f.puts("\n\n")
|
70
|
+
|
71
|
+
parser.pomodoros_bars.each do |pomodoro_bar|
|
72
|
+
f.puts(pomodoro_bar)
|
73
|
+
f.puts("\n\n")
|
74
|
+
end
|
75
|
+
f.puts("\n\n")
|
56
76
|
end
|
57
77
|
|
58
78
|
editor = WorkMd::Config.editor
|
@@ -63,7 +83,7 @@ module WorkMd
|
|
63
83
|
::TTY::Editor.open(PARSED_FILE_PATH)
|
64
84
|
end
|
65
85
|
rescue => e
|
66
|
-
WorkMd::Cli.
|
86
|
+
WorkMd::Cli.help(
|
67
87
|
::TTY::Box.frame(
|
68
88
|
"message: #{e.message}",
|
69
89
|
"",
|
@@ -72,6 +92,7 @@ module WorkMd
|
|
72
92
|
"work_md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000",
|
73
93
|
"work_md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year",
|
74
94
|
"work_md parse -d=1,2 -m=4 | get day 1 and 2 from month 4 and current year",
|
95
|
+
"work_md parse -d=1..10 -m=4 | get day 1 to 10 from month 4 and current year",
|
75
96
|
**WorkMd::Cli.error_frame_style
|
76
97
|
)
|
77
98
|
)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WorkMd
|
4
|
+
module Commands
|
5
|
+
class Tyesterday
|
6
|
+
class << self
|
7
|
+
def execute(_argv = [])
|
8
|
+
file_names =
|
9
|
+
[DateTime.now, Date.today.prev_day].map do |date|
|
10
|
+
WorkMd::File.create_if_not_exist(date)
|
11
|
+
end
|
12
|
+
|
13
|
+
WorkMd::File.open_in_editor(file_names: file_names)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/work_md/config.rb
CHANGED
@@ -4,7 +4,7 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
module WorkMd
|
6
6
|
module Config
|
7
|
-
DEFAULT_WORK_DIR = Dir.home
|
7
|
+
DEFAULT_WORK_DIR = "#{Dir.home}/work_md"
|
8
8
|
TRANSLATIONS = {
|
9
9
|
'pt' =>
|
10
10
|
{
|
@@ -12,6 +12,7 @@ module WorkMd
|
|
12
12
|
meetings: 'Reuniões',
|
13
13
|
interruptions: 'Interrupções',
|
14
14
|
difficulties: 'Dificuldades',
|
15
|
+
observations: 'Observações',
|
15
16
|
pomodoros: 'Pomodoros / Ciclos',
|
16
17
|
per_day: 'por dia'
|
17
18
|
},
|
@@ -21,9 +22,21 @@ module WorkMd
|
|
21
22
|
meetings: 'Meetings',
|
22
23
|
interruptions: 'Interruptions',
|
23
24
|
difficulties: 'Difficulties',
|
25
|
+
observations: 'Observations',
|
24
26
|
pomodoros: 'Pomodoros / Cycles',
|
25
27
|
per_day: 'per day'
|
28
|
+
},
|
29
|
+
'es' =>
|
30
|
+
{
|
31
|
+
tasks: 'Tareas',
|
32
|
+
meetings: 'Reuniones',
|
33
|
+
interruptions: 'Interrupciones',
|
34
|
+
difficulties: 'Dificultades',
|
35
|
+
observations: 'Observaciones',
|
36
|
+
pomodoros: 'Pomodoros / Ciclos',
|
37
|
+
per_day: 'por día'
|
26
38
|
}
|
39
|
+
|
27
40
|
}.freeze
|
28
41
|
|
29
42
|
def self.title
|
@@ -45,7 +58,7 @@ module WorkMd
|
|
45
58
|
end
|
46
59
|
|
47
60
|
def self.yaml_file
|
48
|
-
YAML.load_file(DEFAULT_WORK_DIR
|
61
|
+
YAML.load_file("#{DEFAULT_WORK_DIR}/config.yml")
|
49
62
|
rescue StandardError
|
50
63
|
{}
|
51
64
|
end
|
data/lib/work_md/file.rb
CHANGED
@@ -1,47 +1,60 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'byebug'
|
4
|
+
|
3
5
|
module WorkMd
|
4
6
|
class File
|
5
7
|
def self.open_or_create(some_date)
|
8
|
+
open_in_editor(file_names: [create_if_not_exist(some_date)])
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.create_if_not_exist(some_date)
|
6
12
|
t = WorkMd::Config.translations
|
7
13
|
work_dir = WorkMd::Config.work_dir
|
8
14
|
|
15
|
+
file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
|
16
|
+
|
17
|
+
return file_name if ::File.exist?("#{work_dir}/#{file_name}")
|
18
|
+
|
9
19
|
::FileUtils
|
10
20
|
.mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
|
22
|
+
::File.open(
|
23
|
+
"#{work_dir}/#{file_name}",
|
24
|
+
'w+'
|
25
|
+
) do |f|
|
26
|
+
# rubocop:disable Layout/LineLength
|
27
|
+
f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{WorkMd::Config.title} \n\n")
|
28
|
+
# rubocop:enable Layout/LineLength
|
29
|
+
f.puts("### #{t[:tasks]}:\n\n")
|
30
|
+
f.puts("- [ ]\n\n")
|
31
|
+
f.puts("---\n\n")
|
32
|
+
f.puts("### #{t[:meetings]}:\n\n")
|
33
|
+
f.puts("- [ ]\n\n")
|
34
|
+
f.puts("---\n\n")
|
35
|
+
f.puts("### #{t[:interruptions]}:\n\n")
|
36
|
+
f.puts("---\n\n")
|
37
|
+
f.puts("### #{t[:difficulties]}:\n\n")
|
38
|
+
f.puts("---\n\n")
|
39
|
+
f.puts("### #{t[:observations]}:\n\n")
|
40
|
+
f.puts("---\n\n")
|
41
|
+
f.puts("### #{t[:pomodoros]}:\n\n")
|
42
|
+
f.puts("0\n\n")
|
32
43
|
end
|
33
44
|
|
45
|
+
file_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.open_in_editor(file_names: [], dir: nil)
|
34
49
|
editor = WorkMd::Config.editor
|
50
|
+
work_dir = dir || WorkMd::Config.work_dir
|
35
51
|
|
36
52
|
::FileUtils.cd(work_dir) do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
command: editor
|
43
|
-
)
|
44
|
-
end
|
53
|
+
ENV['EDITOR'] = editor unless editor.nil?
|
54
|
+
|
55
|
+
return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
|
56
|
+
|
57
|
+
::TTY::Editor.open(file_names[0], file_names[1])
|
45
58
|
end
|
46
59
|
end
|
47
60
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module WorkMd
|
4
4
|
module Parser
|
5
|
+
# rubocop:disable Metrics/ClassLength
|
5
6
|
class Engine
|
6
7
|
IS_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is frozen'
|
7
8
|
IS_NOT_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is not frozen'
|
@@ -11,6 +12,7 @@ module WorkMd
|
|
11
12
|
:meetings,
|
12
13
|
:interruptions,
|
13
14
|
:difficulties,
|
15
|
+
:observations,
|
14
16
|
:date,
|
15
17
|
:pomodoros
|
16
18
|
end
|
@@ -66,21 +68,36 @@ module WorkMd
|
|
66
68
|
@difficulties ||= @parsed_files.map(&:difficulties).flatten
|
67
69
|
end
|
68
70
|
|
71
|
+
def observations
|
72
|
+
raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
|
73
|
+
|
74
|
+
@observations ||= @parsed_files.map(&:observations).flatten
|
75
|
+
end
|
76
|
+
|
69
77
|
def average_pomodoros
|
70
|
-
if @parsed_files.size.positive? &&
|
71
|
-
return (
|
78
|
+
if @parsed_files.size.positive? && pomodoros_sum.positive?
|
79
|
+
return (pomodoros_sum.to_f / @parsed_files.size).round(1)
|
72
80
|
end
|
73
81
|
|
74
82
|
0
|
75
83
|
end
|
76
84
|
|
77
|
-
def
|
85
|
+
def pomodoros_sum
|
78
86
|
raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
|
79
87
|
|
80
|
-
@
|
88
|
+
@pomodoros_sum ||=
|
81
89
|
@parsed_files.reduce(0) { |sum, f| sum + f.pomodoros || 0 }
|
82
90
|
end
|
83
91
|
|
92
|
+
def pomodoros_bars
|
93
|
+
raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
|
94
|
+
|
95
|
+
@pomodoros_bars ||=
|
96
|
+
@parsed_files.map do |f|
|
97
|
+
"(#{f.date}) #{(1..f.pomodoros).map { '◘' }.join}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
84
101
|
def freeze
|
85
102
|
@frozen = true
|
86
103
|
end
|
@@ -115,7 +132,10 @@ module WorkMd
|
|
115
132
|
parsed_file.difficulties = parse_list(content).map do |difficulty|
|
116
133
|
"(#{parsed_file.date}) #{difficulty}"
|
117
134
|
end
|
118
|
-
|
135
|
+
elsif content.start_with?(@t[:observations])
|
136
|
+
parsed_file.observations = parse_list(content).map do |observations|
|
137
|
+
"(#{parsed_file.date}) #{observations}"
|
138
|
+
end
|
119
139
|
elsif content.start_with?(@t[:pomodoros])
|
120
140
|
parsed_file.pomodoros = parse_pomodoro(content)
|
121
141
|
end
|
@@ -148,5 +168,6 @@ module WorkMd
|
|
148
168
|
.map(&:strip)
|
149
169
|
end
|
150
170
|
end
|
171
|
+
# rubocop:enable Metrics/ClassLength
|
151
172
|
end
|
152
173
|
end
|
data/lib/work_md/version.rb
CHANGED
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
|
+
version: 0.3.0
|
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-08-
|
11
|
+
date: 2021-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-box
|
@@ -51,8 +51,10 @@ files:
|
|
51
51
|
- bin/work_md
|
52
52
|
- lib/work_md.rb
|
53
53
|
- lib/work_md/cli.rb
|
54
|
+
- lib/work_md/commands/config.rb
|
54
55
|
- lib/work_md/commands/parse.rb
|
55
56
|
- lib/work_md/commands/today.rb
|
57
|
+
- lib/work_md/commands/tyesterday.rb
|
56
58
|
- lib/work_md/commands/yesterday.rb
|
57
59
|
- lib/work_md/config.rb
|
58
60
|
- lib/work_md/file.rb
|