work_md 0.2.9 → 0.3.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
- SHA256:
3
- metadata.gz: a981624ebcb01d89fcb6097d5969c8a4953c548c5f0af0ccad81c2ae56af7945
4
- data.tar.gz: 2e22f7de5b3fc2e72025337b7176cb637e09d67ff56e2bbfd2f025ea21108eea
2
+ SHA1:
3
+ metadata.gz: 1b324912bdc2b9d7db489110bdc56623c26de285
4
+ data.tar.gz: cda8ba5718f0420da7593340f67213570672c18c
5
5
  SHA512:
6
- metadata.gz: 72060087a643c751da31160dc7d24b8747655ae1f42561fd1d64b4de9172304472d22fcda8da3d10dbf11a1cab27cbed48a5406a63881113cee9cc3a64e69620
7
- data.tar.gz: cb634d22d720628d72a13e6b7975a27934f43064ef9bcacd82eb63d67999703b8df8d00ac5adb923c6d6fa9ab21d34c811b700a6f41ec6a03c5730a4f29ec3c1
6
+ metadata.gz: f96829690a7ff140f4fafdf7545944fff09fc9459c41119b13f3c965491a2d7dab6a39b9dba64acce475596b498e7c4957e31b4349aa59a80081ee197404a425
7
+ data.tar.gz: 161880115ce5a27df36dfa390e0fd08a0597ea0efd72d1ce4ad26008a3463058d2adcb6141059e0a30ae22dac5ec02d2b372d67eb6db46d8e6a4c7f3425947f0
data/lib/work_md/cli.rb CHANGED
@@ -9,11 +9,10 @@ module WorkMd
9
9
  't' => 'today',
10
10
  'ty' => 'tyesterday',
11
11
  'y' => 'yesterday',
12
+ 'c' => 'config',
12
13
  'p' => 'parse'
13
14
  }.freeze
14
15
 
15
- DEFAULT_COMMAND = WorkMd::Commands::Today
16
-
17
16
  def self.execute(argv)
18
17
  first_argv_argument = argv.shift
19
18
 
@@ -26,17 +25,17 @@ module WorkMd
26
25
  .const_get("WorkMd::Commands::#{command}")
27
26
  .send(:execute, argv)
28
27
  rescue NameError
29
- puts info(
28
+ puts help(
30
29
  ::TTY::Box.frame(
31
30
  "Command '#{first_argv_argument}' not found!",
32
31
  **error_frame_style
33
32
  )
34
33
  )
35
34
  rescue CommandMissing
36
- DEFAULT_COMMAND.execute(argv)
35
+ help('Welcome! =)')
37
36
  end
38
37
 
39
- def self.info(message = '')
38
+ def self.help(message = '')
40
39
  # rubocop:disable Layout/LineLength
41
40
  puts ::TTY::Box.frame(
42
41
  message,
@@ -49,8 +48,9 @@ module WorkMd
49
48
  '- work_md yesterday',
50
49
  '- work_md tyesterday',
51
50
  '- work_md parse',
51
+ '- work_md config',
52
52
  '',
53
- 'read more in github.com/henriquefernandez/work_md',
53
+ 'more information in github.com/henriquefernandez/work_md',
54
54
  padding: 1,
55
55
  title: { top_left: '(work_md)', bottom_right: "(v#{WorkMd::VERSION})" }
56
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
@@ -51,27 +51,36 @@ module WorkMd
51
51
  f.puts("---\n\n")
52
52
  f.puts("### #{t[:interruptions]} (#{parser.interruptions.size}):\n\n")
53
53
  parser.interruptions.each do |interruption|
54
- f.puts("- #{interruption}\n\n")
54
+ f.puts("- #{interruption}\n")
55
55
  end
56
56
  f.puts("---\n\n")
57
57
  f.puts("### #{t[:difficulties]} (#{parser.difficulties.size}):\n\n")
58
58
  parser.difficulties.each do |difficulty|
59
- f.puts("- #{difficulty}\n\n")
59
+ f.puts("- #{difficulty}\n")
60
60
  end
61
61
  f.puts("---\n\n")
62
62
  f.puts("### #{t[:observations]} (#{parser.observations.size}):\n\n")
63
63
  parser.observations.each do |observation|
64
- f.puts("- #{observation}\n\n")
64
+ f.puts("- #{observation}\n")
65
65
  end
66
66
  f.puts("---\n\n")
67
67
  f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
68
- f.puts(parser.pomodoros_sum)
68
+ f.puts("**#{t[:total]}: #{parser.pomodoros_sum}**")
69
69
  f.puts("\n\n")
70
-
71
70
  parser.pomodoros_bars.each do |pomodoro_bar|
72
71
  f.puts(pomodoro_bar)
73
72
  f.puts("\n\n")
74
73
  end
74
+ f.puts("---\n\n")
75
+ f.puts("### #{t[:days_bars]}:\n\n")
76
+ f.puts("**#{t[:pomodoros]}: ⬛ | #{t[:meetings]}: 📅 | #{t[:interruptions]}: ⚠️ | #{t[:difficulties]}: 😓 | #{t[:observations]}: 📝 | #{t[:tasks]}: ✔️**")
77
+
78
+ f.puts("\n\n")
79
+ parser.days_bars.each do |day_bar|
80
+ f.puts(day_bar)
81
+ f.puts("\n\n")
82
+ end
83
+
75
84
  f.puts("\n\n")
76
85
  end
77
86
 
@@ -83,7 +92,7 @@ module WorkMd
83
92
  ::TTY::Editor.open(PARSED_FILE_PATH)
84
93
  end
85
94
  rescue => e
86
- WorkMd::Cli.info(
95
+ WorkMd::Cli.help(
87
96
  ::TTY::Box.frame(
88
97
  "message: #{e.message}",
89
98
  "",
@@ -5,12 +5,12 @@ module WorkMd
5
5
  class Tyesterday
6
6
  class << self
7
7
  def execute(_argv = [])
8
- filenames =
8
+ file_names =
9
9
  [DateTime.now, Date.today.prev_day].map do |date|
10
10
  WorkMd::File.create_if_not_exist(date)
11
11
  end
12
12
 
13
- WorkMd::File.open_in_editor(filenames[0], filenames[1])
13
+ WorkMd::File.open_in_editor(file_names: file_names)
14
14
  end
15
15
  end
16
16
  end
@@ -4,7 +4,7 @@ require 'yaml'
4
4
 
5
5
  module WorkMd
6
6
  module Config
7
- DEFAULT_WORK_DIR = Dir.home + '/work_md'
7
+ DEFAULT_WORK_DIR = "#{Dir.home}/work_md"
8
8
  TRANSLATIONS = {
9
9
  'pt' =>
10
10
  {
@@ -14,7 +14,9 @@ module WorkMd
14
14
  difficulties: 'Dificuldades',
15
15
  observations: 'Observações',
16
16
  pomodoros: 'Pomodoros / Ciclos',
17
- per_day: 'por dia'
17
+ per_day: 'por dia',
18
+ total: 'total',
19
+ days_bars: 'Resumo'
18
20
  },
19
21
  'en' =>
20
22
  {
@@ -24,8 +26,24 @@ module WorkMd
24
26
  difficulties: 'Difficulties',
25
27
  observations: 'Observations',
26
28
  pomodoros: 'Pomodoros / Cycles',
27
- per_day: 'per day'
29
+ per_day: 'per day',
30
+ total: 'all',
31
+ days_bars: 'Summary'
32
+
33
+ },
34
+ 'es' =>
35
+ {
36
+ tasks: 'Tareas',
37
+ meetings: 'Reuniones',
38
+ interruptions: 'Interrupciones',
39
+ difficulties: 'Dificultades',
40
+ observations: 'Observaciones',
41
+ pomodoros: 'Pomodoros / Ciclos',
42
+ per_day: 'por día',
43
+ total: 'total',
44
+ days_bars: 'Abstracto'
28
45
  }
46
+
29
47
  }.freeze
30
48
 
31
49
  def self.title
@@ -47,7 +65,7 @@ module WorkMd
47
65
  end
48
66
 
49
67
  def self.yaml_file
50
- YAML.load_file(DEFAULT_WORK_DIR + '/config.yml')
68
+ YAML.load_file("#{DEFAULT_WORK_DIR}/config.yml")
51
69
  rescue StandardError
52
70
  {}
53
71
  end
data/lib/work_md/file.rb CHANGED
@@ -1,26 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'byebug'
4
-
5
3
  module WorkMd
6
4
  class File
7
5
  def self.open_or_create(some_date)
8
- open_in_editor(create_if_not_exist(some_date))
6
+ open_in_editor(file_names: [create_if_not_exist(some_date)])
9
7
  end
10
8
 
11
9
  def self.create_if_not_exist(some_date)
12
10
  t = WorkMd::Config.translations
13
11
  work_dir = WorkMd::Config.work_dir
14
12
 
15
- ::FileUtils
16
- .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
13
+ file_name = "#{some_date.strftime('%Y/%m/%d')}.md"
17
14
 
18
- filename = "#{some_date.strftime('%Y/%m/%d')}.md"
15
+ return file_name if ::File.exist?("#{work_dir}/#{file_name}")
19
16
 
20
- return filename if ::File.exist?("#{work_dir}/#{filename}")
17
+ ::FileUtils
18
+ .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
21
19
 
22
20
  ::File.open(
23
- "#{work_dir}/#{filename}",
21
+ "#{work_dir}/#{file_name}",
24
22
  'w+'
25
23
  ) do |f|
26
24
  # rubocop:disable Layout/LineLength
@@ -42,18 +40,19 @@ module WorkMd
42
40
  f.puts("0\n\n")
43
41
  end
44
42
 
45
- filename
43
+ file_name
46
44
  end
47
45
 
48
- def self.open_in_editor(filename1, filename2 = nil)
46
+ def self.open_in_editor(file_names: [], dir: nil)
49
47
  editor = WorkMd::Config.editor
48
+ work_dir = dir || WorkMd::Config.work_dir
50
49
 
51
- ::FileUtils.cd(WorkMd::Config.work_dir) do
50
+ ::FileUtils.cd(work_dir) do
52
51
  ENV['EDITOR'] = editor unless editor.nil?
53
52
 
54
- return ::TTY::Editor.open(filename1) if filename2.nil?
53
+ return ::TTY::Editor.open(file_names[0]) if file_names[1].nil?
55
54
 
56
- ::TTY::Editor.open(filename1, filename2)
55
+ ::TTY::Editor.open(file_names[0], file_names[1])
57
56
  end
58
57
  end
59
58
  end
@@ -41,7 +41,7 @@ module WorkMd
41
41
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
42
42
 
43
43
  @done_tasks ||=
44
- tasks.filter { |t| t.start_with?('x]') || t.start_with?('X]') }
44
+ tasks.select { |t| t.start_with?('x]') || t.start_with?('X]') }
45
45
  end
46
46
 
47
47
  def tasks
@@ -89,15 +89,37 @@ module WorkMd
89
89
  @parsed_files.reduce(0) { |sum, f| sum + f.pomodoros || 0 }
90
90
  end
91
91
 
92
- def pomodoros_bars
92
+ def pomodoros_bars(_file = nil)
93
93
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
94
94
 
95
95
  @pomodoros_bars ||=
96
96
  @parsed_files.map do |f|
97
- "(#{f.date}) #{(1..f.pomodoros).map { '' }.join }"
97
+ "(#{f.date}) #{(1..f.pomodoros).map { '' }.join}"
98
98
  end
99
99
  end
100
100
 
101
+ # rubocop:disable Metrics/CyclomaticComplexity
102
+ # rubocop:disable Metrics/PerceivedComplexity
103
+ def days_bars
104
+ raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
105
+
106
+ return @days_bars if @days_bars
107
+
108
+ @days_bars ||=
109
+ @parsed_files.map do |f|
110
+ pom = (1..f.pomodoros).map { '⬛' }.join
111
+ mee = f.meetings.map { '📅' }.join
112
+ int = f.interruptions.map { '⚠️' }.join
113
+ dif = f.difficulties.map { '😓' }.join
114
+ obs = f.observations.map { '📝' }.join
115
+ tas = f.tasks.map { '✔️' }.join
116
+
117
+ "(#{f.date}) #{pom}#{mee}#{int}#{dif}#{obs}#{tas}"
118
+ end
119
+ end
120
+ # rubocop:enable Metrics/CyclomaticComplexity
121
+ # rubocop:enable Metrics/PerceivedComplexity
122
+
101
123
  def freeze
102
124
  @frozen = true
103
125
  end
@@ -164,7 +186,7 @@ module WorkMd
164
186
 
165
187
  list
166
188
  .map { |s| s.gsub('---', '') unless s.nil? }
167
- .filter { |s| (s != '') && (s != "\n\n") }
189
+ .select { |s| (s != '') && (s != "\n\n") }
168
190
  .map(&:strip)
169
191
  end
170
192
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.9'
4
+ VERSION = '0.3.3'
5
5
  end
data/lib/work_md.rb CHANGED
@@ -4,6 +4,7 @@ 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'
8
9
  require_relative 'work_md/commands/tyesterday'
9
10
  require_relative 'work_md/parser/engine'
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.2.9
4
+ version: 0.3.3
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-08-13 00:00:00.000000000 Z
11
+ date: 2021-09-01 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:
@@ -51,6 +51,7 @@ 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
56
57
  - lib/work_md/commands/tyesterday.rb
@@ -59,12 +60,12 @@ files:
59
60
  - lib/work_md/file.rb
60
61
  - lib/work_md/parser/engine.rb
61
62
  - lib/work_md/version.rb
62
- homepage:
63
+ homepage:
63
64
  licenses:
64
65
  - MIT
65
66
  metadata:
66
67
  source_code_uri: https://github.com/henriquefernandez/work_md
67
- post_install_message:
68
+ post_install_message:
68
69
  rdoc_options: []
69
70
  require_paths:
70
71
  - lib
@@ -79,8 +80,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.2.15
83
- signing_key:
83
+ rubyforge_project:
84
+ rubygems_version: 2.6.14.4
85
+ signing_key:
84
86
  specification_version: 4
85
87
  summary: Track your work activities, write annotations, recap what you did for a week,
86
88
  month or specific days... and much more!