work_md 0.2.8 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: e7f163bb109aa82d9095042209b18157e3ba0ff0ab23456b43e0cd65ba90aeee
4
- data.tar.gz: a78b3daa4090a73e1bcdda5e51eb30718a4787f2932027c5945e6e14322b826b
2
+ SHA1:
3
+ metadata.gz: 60187b3467d34318e7222c4ada48b85db1a7ab51
4
+ data.tar.gz: c60ce02e0e0309da2cc5e473d2c36d5918f2e10f
5
5
  SHA512:
6
- metadata.gz: d2e117fa8755001b8f4ccb44a77666e2c3b8f25c1deb959d8c702c55096bfb4cf625923eb09cf184ff3aef14659beabfdd3718ecd492384044efb5b01010ca29
7
- data.tar.gz: 7a555df5793cbc958eff5ff7f42a5078357afeb9ab66b561ff4a82a04c0e120c565f22041e8bf1bff3b8e5f5ca345945b570cd015b66b92f037b481a4fd602b6
6
+ metadata.gz: 54c2f36629245e0d8e3f0d7f386cdb71fc90aa456afe50aaca7d0e05cd30841e7cff59a017bf13035f36fc853c59db61f2463cfff002190432394e39b749e708
7
+ data.tar.gz: 38e263f05ad79d7423af18912cb677a444742422f46d439026b51d53a922ae5e10b71f7e94e4430ec7fe5b58808f3b01b0847fac5807f6079f9788e45ba61adc
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'
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
@@ -65,7 +65,14 @@ module WorkMd
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)
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")
69
76
  end
70
77
 
71
78
  editor = WorkMd::Config.editor
@@ -76,7 +83,7 @@ module WorkMd
76
83
  ::TTY::Editor.open(PARSED_FILE_PATH)
77
84
  end
78
85
  rescue => e
79
- WorkMd::Cli.info(
86
+ WorkMd::Cli.help(
80
87
  ::TTY::Box.frame(
81
88
  "message: #{e.message}",
82
89
  "",
@@ -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
  {
@@ -25,7 +25,18 @@ module WorkMd
25
25
  observations: 'Observations',
26
26
  pomodoros: 'Pomodoros / Cycles',
27
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'
28
38
  }
39
+
29
40
  }.freeze
30
41
 
31
42
  def self.title
@@ -47,7 +58,7 @@ module WorkMd
47
58
  end
48
59
 
49
60
  def self.yaml_file
50
- YAML.load_file(DEFAULT_WORK_DIR + '/config.yml')
61
+ YAML.load_file("#{DEFAULT_WORK_DIR}/config.yml")
51
62
  rescue StandardError
52
63
  {}
53
64
  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
@@ -75,20 +75,29 @@ module WorkMd
75
75
  end
76
76
 
77
77
  def average_pomodoros
78
- if @parsed_files.size.positive? && pomodoros.positive?
79
- return (pomodoros.to_f / @parsed_files.size).round(1)
78
+ if @parsed_files.size.positive? && pomodoros_sum.positive?
79
+ return (pomodoros_sum.to_f / @parsed_files.size).round(1)
80
80
  end
81
81
 
82
82
  0
83
83
  end
84
84
 
85
- def pomodoros
85
+ def pomodoros_sum
86
86
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
87
87
 
88
- @pomodoros ||=
88
+ @pomodoros_sum ||=
89
89
  @parsed_files.reduce(0) { |sum, f| sum + f.pomodoros || 0 }
90
90
  end
91
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
+
92
101
  def freeze
93
102
  @frozen = true
94
103
  end
@@ -155,7 +164,7 @@ module WorkMd
155
164
 
156
165
  list
157
166
  .map { |s| s.gsub('---', '') unless s.nil? }
158
- .filter { |s| (s != '') && (s != "\n\n") }
167
+ .select { |s| (s != '') && (s != "\n\n") }
159
168
  .map(&:strip)
160
169
  end
161
170
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.8'
4
+ VERSION = '0.3.2'
5
5
  end
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.8
4
+ version: 0.3.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-08-13 00:00:00.000000000 Z
11
+ date: 2021-08-17 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!