work_md 0.2.2 → 0.2.6

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: 8c7ac71894ac4ae951f1b0b2a7e6e4c7f5bbca415b3e2a175b8ca35c9adfb4ca
4
- data.tar.gz: 8c5372912117c88e8e1c25c7245d400b585c616101f13da1094fb13f61abc81f
3
+ metadata.gz: 566027a143beb9e55274abe76ef2f0d0c7a44078d4773c595e9cdce2175a2c32
4
+ data.tar.gz: d4094062e154849f8514d26c20d52d37e931d3f844f2b162cb26eab2b7a70d5d
5
5
  SHA512:
6
- metadata.gz: c347b644ee03cab1a499f7bea1cab09bd0e5601c52b39edb41e76f2d616ae4225e1c557ae6fd77eb368e403e094188c060f56e2589ae6462e55139122d7cc8ac
7
- data.tar.gz: 81ec971d682d95fb2834c73df6615bea6448294c764f36470af1fe607784fa8d6bf47b5163a2117c03494b909cdf153282899ee0f96812743f44dbbe8732ae0a
6
+ metadata.gz: 41053f4429dfd6a4a3af74e52da1d6f131aac58c79c9034a201814a89dc67fd7a2e3feae74c25afa8c0ffc0b610cf9d8332392ee69cb66f43011779033a4af21
7
+ data.tar.gz: 4daed1478dedc190e1d3eef1719c54f16af4040519b276ab08820453e08371112fd92cd70b9aef8c3e32480cee65257daa884f3580b0748cb8d32c34c6fabd3f
data/lib/work_md.rb CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  require_relative 'work_md/version'
4
4
  require_relative 'work_md/config'
5
+ require_relative 'work_md/file'
5
6
  require_relative 'work_md/commands/today'
7
+ require_relative 'work_md/commands/yesterday'
6
8
  require_relative 'work_md/parser/engine'
7
9
  require_relative 'work_md/commands/parse'
8
10
  require_relative 'work_md/cli'
data/lib/work_md/cli.rb CHANGED
@@ -7,6 +7,7 @@ module WorkMd
7
7
  ALIAS_COMMANDS =
8
8
  {
9
9
  't' => 'today',
10
+ 'y' => 'yesterday',
10
11
  'p' => 'parse'
11
12
  }.freeze
12
13
 
@@ -44,6 +45,7 @@ module WorkMd
44
45
  '',
45
46
  '- work_md',
46
47
  '- work_md today',
48
+ '- work_md yesterday',
47
49
  '- work_md parse',
48
50
  '',
49
51
  'read more in github.com/henriquefernandez/work_md',
@@ -27,9 +27,9 @@ module WorkMd
27
27
 
28
28
  parser.freeze
29
29
 
30
- File.delete(PARSED_FILE_PATH) if File.exist? PARSED_FILE_PATH
30
+ ::File.delete(PARSED_FILE_PATH) if ::File.exist? PARSED_FILE_PATH
31
31
 
32
- File.open(PARSED_FILE_PATH, 'w+') do |f|
32
+ ::File.open(PARSED_FILE_PATH, 'w+') do |f|
33
33
  f.puts("# #{WorkMd::Config.title}\n\n")
34
34
  f.puts("### #{t[:tasks]} (#{parser.tasks.size}):\n\n")
35
35
  parser.tasks.each do |task|
@@ -38,16 +38,7 @@ module WorkMd
38
38
  f.puts("---\n\n")
39
39
  f.puts("### #{t[:meetings]} (#{parser.meetings.size}):\n\n")
40
40
  parser.meetings.each do |meeting|
41
- f.puts("- #{meeting}\n\n")
42
- end
43
- f.puts("---\n\n")
44
- f.puts("### #{t[:annotations]}:\n\n")
45
- parser.annotations.each do |annotation|
46
- f.puts("- #{annotation.gsub('###', '')}") unless annotation.nil?
47
- end
48
- f.puts("###### #{t[:meeting_annotations]}:\n\n")
49
- parser.meeting_annotations.each do |meeting_annotation|
50
- f.puts("- #{meeting_annotation}\n\n")
41
+ f.puts("- [#{meeting}\n\n") if meeting != ' ]'
51
42
  end
52
43
  f.puts("---\n\n")
53
44
  f.puts("### #{t[:interruptions]} (#{parser.interruptions.size}):\n\n")
@@ -60,14 +51,22 @@ module WorkMd
60
51
  f.puts("- #{difficulty}\n\n")
61
52
  end
62
53
  f.puts("---\n\n")
63
- f.puts("### #{t[:pomodoros]}:\n\n")
54
+ f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
64
55
  f.puts(parser.pomodoros)
65
56
  end
66
57
 
67
- ::TTY::Editor.open(PARSED_FILE_PATH)
68
- rescue
58
+ editor = WorkMd::Config.editor
59
+
60
+ unless editor.nil?
61
+ ::TTY::Editor.open(PARSED_FILE_PATH, command: editor)
62
+ else
63
+ ::TTY::Editor.open(PARSED_FILE_PATH)
64
+ end
65
+ rescue => e
69
66
  WorkMd::Cli.info(
70
67
  ::TTY::Box.frame(
68
+ "message: #{e.message}",
69
+ "",
71
70
  "Usage examples:",
72
71
  "",
73
72
  "work_md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000",
@@ -5,41 +5,7 @@ module WorkMd
5
5
  class Today
6
6
  class << self
7
7
  def execute(_argv = [])
8
- today = DateTime.now
9
- t = WorkMd::Config.translations
10
- work_dir = WorkMd::Config.work_dir
11
-
12
- ::FileUtils
13
- .mkdir_p("#{work_dir}/#{today.strftime('%Y/%m')}")
14
- unless ::File
15
- .exist?(
16
- "#{work_dir}/#{today.strftime('%Y/%m/%d')}.md"
17
- )
18
- ::File.open(
19
- "#{work_dir}/#{today.strftime('%Y/%m/%d')}.md",
20
- 'w+'
21
- ) do |f|
22
- f.puts("# #{today.strftime('%d/%m/%Y')} - #{WorkMd::Config.title} \n\n")
23
- f.puts("### #{t[:tasks]}:\n\n")
24
- f.puts("- [ ]\n\n")
25
- f.puts("---\n\n")
26
- f.puts("### #{t[:meetings]}:\n\n")
27
- f.puts("---\n\n")
28
- f.puts("### #{t[:annotations]}:\n\n")
29
- f.puts("###### #{t[:meeting_annotations]}:\n\n")
30
- f.puts("---\n\n")
31
- f.puts("### #{t[:interruptions]}:\n\n")
32
- f.puts("---\n\n")
33
- f.puts("### #{t[:difficulties]}:\n\n")
34
- f.puts("---\n\n")
35
- f.puts("### #{t[:pomodoros]}:\n\n")
36
- f.puts("0\n\n")
37
- end
38
- end
39
-
40
- ::FileUtils.cd(work_dir) do
41
- ::TTY::Editor.open("#{today.strftime('%Y/%m/%d')}.md")
42
- end
8
+ WorkMd::File.open_or_create(DateTime.now)
43
9
  end
44
10
  end
45
11
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkMd
4
+ module Commands
5
+ class Yesterday
6
+ class << self
7
+ def execute(_argv = [])
8
+ WorkMd::File.open_or_create(Date.today.prev_day)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,27 +5,24 @@ require 'yaml'
5
5
  module WorkMd
6
6
  module Config
7
7
  DEFAULT_WORK_DIR = Dir.home + '/work_md'
8
- DEFAULT_EDITOR = 'vi'
9
8
  TRANSLATIONS = {
10
9
  'pt' =>
11
10
  {
12
11
  tasks: 'Atividades',
13
12
  meetings: 'Reuniões',
14
- annotations: 'Anotações',
15
- meeting_annotations: 'Anotações de Reunião',
16
13
  interruptions: 'Interrupções',
17
14
  difficulties: 'Dificuldades',
18
- pomodoros: 'Pomodoros'
15
+ pomodoros: 'Pomodoros / Ciclos',
16
+ per_day: 'por dia'
19
17
  },
20
18
  'en' =>
21
19
  {
22
20
  tasks: 'Tasks',
23
21
  meetings: 'Meetings',
24
- annotations: 'Annotations',
25
- meeting_annotations: 'Meeting Annotations',
26
22
  interruptions: 'Interruptions',
27
23
  difficulties: 'Difficulties',
28
- pomodoros: 'Pomodoros'
24
+ pomodoros: 'Pomodoros / Cycles',
25
+ per_day: 'per day'
29
26
  }
30
27
  }.freeze
31
28
 
@@ -34,7 +31,7 @@ module WorkMd
34
31
  end
35
32
 
36
33
  def self.editor
37
- ENV['EDITOR'] || ENV['VISUAL'] || yaml_file['editor'] || DEFAULT_EDITOR
34
+ ENV['EDITOR'] || ENV['VISUAL'] || yaml_file['editor'] || nil
38
35
  end
39
36
 
40
37
  def self.work_dir
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkMd
4
+ class File
5
+ def self.open_or_create(some_date)
6
+ t = WorkMd::Config.translations
7
+ work_dir = WorkMd::Config.work_dir
8
+
9
+ ::FileUtils
10
+ .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
11
+ unless ::File.exist?("#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md")
12
+ ::File.open(
13
+ "#{work_dir}/#{some_date.strftime('%Y/%m/%d')}.md",
14
+ 'w+'
15
+ ) do |f|
16
+ # rubocop:disable Layout/LineLength
17
+ f.puts("# #{some_date.strftime('%d/%m/%Y')} - #{WorkMd::Config.title} \n\n")
18
+ # rubocop:enable Layout/LineLength
19
+ f.puts("### #{t[:tasks]}:\n\n")
20
+ f.puts("- [ ]\n\n")
21
+ f.puts("---\n\n")
22
+ f.puts("### #{t[:meetings]}:\n\n")
23
+ f.puts("- [ ]\n\n")
24
+ f.puts("---\n\n")
25
+ f.puts("### #{t[:interruptions]}:\n\n")
26
+ f.puts("---\n\n")
27
+ f.puts("### #{t[:difficulties]}:\n\n")
28
+ f.puts("---\n\n")
29
+ f.puts("### #{t[:pomodoros]}:\n\n")
30
+ f.puts("0\n\n")
31
+ end
32
+ end
33
+
34
+ editor = WorkMd::Config.editor
35
+
36
+ ::FileUtils.cd(work_dir) do
37
+ if editor.nil?
38
+ ::TTY::Editor.open("#{some_date.strftime('%Y/%m/%d')}.md")
39
+ else
40
+ ::TTY::Editor.open(
41
+ "#{some_date.strftime('%Y/%m/%d')}.md",
42
+ command: editor
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,11 +8,10 @@ module WorkMd
8
8
 
9
9
  class ParsedFile
10
10
  attr_accessor :tasks,
11
- :annotations,
12
- :meeting_annotations,
13
11
  :meetings,
14
12
  :interruptions,
15
13
  :difficulties,
14
+ :date,
16
15
  :pomodoros
17
16
  end
18
17
 
@@ -26,7 +25,7 @@ module WorkMd
26
25
  raise IS_FROZEN_ERROR_MESSAGE if @frozen
27
26
 
28
27
  begin
29
- file_content = File.read(file)
28
+ file_content = ::File.read(file)
30
29
  rescue Errno::ENOENT
31
30
  return
32
31
  end
@@ -49,19 +48,6 @@ module WorkMd
49
48
  @tasks ||= @parsed_files.map(&:tasks).flatten
50
49
  end
51
50
 
52
- def annotations
53
- raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
54
-
55
- @annotations ||= @parsed_files.map(&:annotations).flatten
56
- end
57
-
58
- def meeting_annotations
59
- raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
60
-
61
- @meeting_annotations ||=
62
- @parsed_files.map(&:meeting_annotations).flatten
63
- end
64
-
65
51
  def meetings
66
52
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
67
53
 
@@ -80,6 +66,14 @@ module WorkMd
80
66
  @difficulties ||= @parsed_files.map(&:difficulties).flatten
81
67
  end
82
68
 
69
+ def average_pomodoros
70
+ if @parsed_files.size.positive? && pomodoros.positive?
71
+ return (pomodoros / @parsed_files.size)
72
+ end
73
+
74
+ 0
75
+ end
76
+
83
77
  def pomodoros
84
78
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
85
79
 
@@ -106,18 +100,22 @@ module WorkMd
106
100
  # rubocop:disable Metrics/CyclomaticComplexity
107
101
  # rubocop:disable Metrics/PerceivedComplexity
108
102
  def parse_content(parsed_file, content)
109
- if content.start_with?(@t[:tasks])
110
- parsed_file.tasks = parse_task_list(content)
103
+ if content.start_with?('# ')
104
+ parsed_file.date =
105
+ content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
106
+ elsif content.start_with?(@t[:tasks])
107
+ parsed_file.tasks = parse_check_list(content)
111
108
  elsif content.start_with?(@t[:meetings])
112
- parsed_file.meetings = parse_list(content)
113
- elsif content.start_with?(@t[:meeting_annotations])
114
- parsed_file.meeting_annotations = basic_parse(content)
115
- elsif content.start_with?(@t[:annotations])
116
- parsed_file.annotations = basic_parse(content)
109
+ parsed_file.meetings = parse_check_list(content)
117
110
  elsif content.start_with?(@t[:interruptions])
118
- parsed_file.interruptions = parse_list(content)
111
+ parsed_file.interruptions = parse_list(content).map do |interruption|
112
+ "(#{parsed_file.date}) #{interruption}"
113
+ end
119
114
  elsif content.start_with?(@t[:difficulties])
120
- parsed_file.difficulties = parse_list(content)
115
+ parsed_file.difficulties = parse_list(content).map do |difficulty|
116
+ "(#{parsed_file.date}) #{difficulty}"
117
+ end
118
+
121
119
  elsif content.start_with?(@t[:pomodoros])
122
120
  parsed_file.pomodoros = parse_pomodoro(content)
123
121
  end
@@ -125,7 +123,7 @@ module WorkMd
125
123
  # rubocop:enable Metrics/CyclomaticComplexity
126
124
  # rubocop:enable Metrics/PerceivedComplexity
127
125
 
128
- def parse_task_list(content)
126
+ def parse_check_list(content)
129
127
  clear_list(basic_parse(content).split('- ['))
130
128
  end
131
129
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.6'
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.2
4
+ version: 0.2.6
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-07-13 00:00:00.000000000 Z
11
+ date: 2021-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -53,7 +53,9 @@ files:
53
53
  - lib/work_md/cli.rb
54
54
  - lib/work_md/commands/parse.rb
55
55
  - lib/work_md/commands/today.rb
56
+ - lib/work_md/commands/yesterday.rb
56
57
  - lib/work_md/config.rb
58
+ - lib/work_md/file.rb
57
59
  - lib/work_md/parser/engine.rb
58
60
  - lib/work_md/version.rb
59
61
  homepage: