work_md 0.2.5 → 0.2.9

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
2
  SHA256:
3
- metadata.gz: 8d5b841881acd03d54092af4c2e04b6fa29356b784ac52905810a3ba021c01de
4
- data.tar.gz: 324ad983b70bd2749e7c888a21949a7c8b66ca6bbe7c3c7ebabeaeaee7f83a3d
3
+ metadata.gz: a981624ebcb01d89fcb6097d5969c8a4953c548c5f0af0ccad81c2ae56af7945
4
+ data.tar.gz: 2e22f7de5b3fc2e72025337b7176cb637e09d67ff56e2bbfd2f025ea21108eea
5
5
  SHA512:
6
- metadata.gz: 7ab6691773bf32657133a362cfbb42a45e6fbace7a716dcd20f065fe081297ae720efc3b1bcaa86a297327d61886522b45101c3d65fc0bfa3edbdf2422611b28
7
- data.tar.gz: e6de20ebdf9b3a5055bc4f1c0e822de41e37ee9ea4131ddc4268c0c47e0acc5d388f2c8864dbc0171dfd419264ea7aec9bc56fe26431475cd9351b12efa704e7
6
+ metadata.gz: 72060087a643c751da31160dc7d24b8747655ae1f42561fd1d64b4de9172304472d22fcda8da3d10dbf11a1cab27cbed48a5406a63881113cee9cc3a64e69620
7
+ data.tar.gz: cb634d22d720628d72a13e6b7975a27934f43064ef9bcacd82eb63d67999703b8df8d00ac5adb923c6d6fa9ab21d34c811b700a6f41ec6a03c5730a4f29ec3c1
data/bin/work_md CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # require_relative '../lib/work_md'
4
5
  require 'work_md'
5
6
 
6
7
  WorkMd::Cli.execute(ARGV)
data/lib/work_md.rb CHANGED
@@ -2,7 +2,10 @@
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'
8
+ require_relative 'work_md/commands/tyesterday'
6
9
  require_relative 'work_md/parser/engine'
7
10
  require_relative 'work_md/commands/parse'
8
11
  require_relative 'work_md/cli'
data/lib/work_md/cli.rb CHANGED
@@ -7,6 +7,8 @@ module WorkMd
7
7
  ALIAS_COMMANDS =
8
8
  {
9
9
  't' => 'today',
10
+ 'ty' => 'tyesterday',
11
+ 'y' => 'yesterday',
10
12
  'p' => 'parse'
11
13
  }.freeze
12
14
 
@@ -44,6 +46,8 @@ module WorkMd
44
46
  '',
45
47
  '- work_md',
46
48
  '- work_md today',
49
+ '- work_md yesterday',
50
+ '- work_md tyesterday',
47
51
  '- work_md parse',
48
52
  '',
49
53
  'read more in github.com/henriquefernandez/work_md',
@@ -17,7 +17,7 @@ module WorkMd
17
17
 
18
18
  month = "0#{month.to_i}" if month.to_i < 10
19
19
 
20
- args['d'].split(',').each do |day|
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,11 +25,19 @@ 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
- File.delete(PARSED_FILE_PATH) if File.exist? PARSED_FILE_PATH
38
+ ::File.delete(PARSED_FILE_PATH) if ::File.exist? PARSED_FILE_PATH
31
39
 
32
- File.open(PARSED_FILE_PATH, 'w+') do |f|
40
+ ::File.open(PARSED_FILE_PATH, 'w+') do |f|
33
41
  f.puts("# #{WorkMd::Config.title}\n\n")
34
42
  f.puts("### #{t[:tasks]} (#{parser.tasks.size}):\n\n")
35
43
  parser.tasks.each do |task|
@@ -38,16 +46,7 @@ module WorkMd
38
46
  f.puts("---\n\n")
39
47
  f.puts("### #{t[:meetings]} (#{parser.meetings.size}):\n\n")
40
48
  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")
49
+ f.puts("- [#{meeting}\n\n") if meeting != ' ]'
51
50
  end
52
51
  f.puts("---\n\n")
53
52
  f.puts("### #{t[:interruptions]} (#{parser.interruptions.size}):\n\n")
@@ -60,8 +59,20 @@ module WorkMd
60
59
  f.puts("- #{difficulty}\n\n")
61
60
  end
62
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")
63
67
  f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
64
- 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")
65
76
  end
66
77
 
67
78
  editor = WorkMd::Config.editor
@@ -71,14 +82,17 @@ module WorkMd
71
82
  else
72
83
  ::TTY::Editor.open(PARSED_FILE_PATH)
73
84
  end
74
- rescue
85
+ rescue => e
75
86
  WorkMd::Cli.info(
76
87
  ::TTY::Box.frame(
88
+ "message: #{e.message}",
89
+ "",
77
90
  "Usage examples:",
78
91
  "",
79
92
  "work_md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000",
80
93
  "work_md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year",
81
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",
82
96
  **WorkMd::Cli.error_frame_style
83
97
  )
84
98
  )
@@ -5,50 +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
- editor = WorkMd::Config.editor
41
-
42
- ::FileUtils.cd(work_dir) do
43
- unless editor.nil?
44
- ::TTY::Editor.open(
45
- "#{today.strftime('%Y/%m/%d')}.md",
46
- command: editor
47
- )
48
- else
49
- ::TTY::Editor.open("#{today.strftime('%Y/%m/%d')}.md")
50
- end
51
- end
8
+ WorkMd::File.open_or_create(DateTime.now)
52
9
  end
53
10
  end
54
11
  end
@@ -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
+ filenames =
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(filenames[0], filenames[1])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ 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
@@ -10,10 +10,9 @@ module WorkMd
10
10
  {
11
11
  tasks: 'Atividades',
12
12
  meetings: 'Reuniões',
13
- annotations: 'Anotações',
14
- meeting_annotations: 'Anotações de Reunião',
15
13
  interruptions: 'Interrupções',
16
14
  difficulties: 'Dificuldades',
15
+ observations: 'Observações',
17
16
  pomodoros: 'Pomodoros / Ciclos',
18
17
  per_day: 'por dia'
19
18
  },
@@ -21,10 +20,9 @@ module WorkMd
21
20
  {
22
21
  tasks: 'Tasks',
23
22
  meetings: 'Meetings',
24
- annotations: 'Annotations',
25
- meeting_annotations: 'Meeting Annotations',
26
23
  interruptions: 'Interruptions',
27
24
  difficulties: 'Difficulties',
25
+ observations: 'Observations',
28
26
  pomodoros: 'Pomodoros / Cycles',
29
27
  per_day: 'per day'
30
28
  }
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'byebug'
4
+
5
+ module WorkMd
6
+ class File
7
+ def self.open_or_create(some_date)
8
+ open_in_editor(create_if_not_exist(some_date))
9
+ end
10
+
11
+ def self.create_if_not_exist(some_date)
12
+ t = WorkMd::Config.translations
13
+ work_dir = WorkMd::Config.work_dir
14
+
15
+ ::FileUtils
16
+ .mkdir_p("#{work_dir}/#{some_date.strftime('%Y/%m')}")
17
+
18
+ filename = "#{some_date.strftime('%Y/%m/%d')}.md"
19
+
20
+ return filename if ::File.exist?("#{work_dir}/#{filename}")
21
+
22
+ ::File.open(
23
+ "#{work_dir}/#{filename}",
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")
43
+ end
44
+
45
+ filename
46
+ end
47
+
48
+ def self.open_in_editor(filename1, filename2 = nil)
49
+ editor = WorkMd::Config.editor
50
+
51
+ ::FileUtils.cd(WorkMd::Config.work_dir) do
52
+ ENV['EDITOR'] = editor unless editor.nil?
53
+
54
+ return ::TTY::Editor.open(filename1) if filename2.nil?
55
+
56
+ ::TTY::Editor.open(filename1, filename2)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
4
3
  module WorkMd
5
4
  module Parser
5
+ # rubocop:disable Metrics/ClassLength
6
6
  class Engine
7
7
  IS_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is frozen'
8
8
  IS_NOT_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is not frozen'
9
9
 
10
10
  class ParsedFile
11
11
  attr_accessor :tasks,
12
- :annotations,
13
- :meeting_annotations,
14
12
  :meetings,
15
13
  :interruptions,
16
14
  :difficulties,
15
+ :observations,
16
+ :date,
17
17
  :pomodoros
18
18
  end
19
19
 
@@ -27,7 +27,7 @@ module WorkMd
27
27
  raise IS_FROZEN_ERROR_MESSAGE if @frozen
28
28
 
29
29
  begin
30
- file_content = File.read(file)
30
+ file_content = ::File.read(file)
31
31
  rescue Errno::ENOENT
32
32
  return
33
33
  end
@@ -50,19 +50,6 @@ module WorkMd
50
50
  @tasks ||= @parsed_files.map(&:tasks).flatten
51
51
  end
52
52
 
53
- def annotations
54
- raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
55
-
56
- @annotations ||= @parsed_files.map(&:annotations).flatten
57
- end
58
-
59
- def meeting_annotations
60
- raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
61
-
62
- @meeting_annotations ||=
63
- @parsed_files.map(&:meeting_annotations).flatten
64
- end
65
-
66
53
  def meetings
67
54
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
68
55
 
@@ -81,21 +68,36 @@ module WorkMd
81
68
  @difficulties ||= @parsed_files.map(&:difficulties).flatten
82
69
  end
83
70
 
71
+ def observations
72
+ raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
73
+
74
+ @observations ||= @parsed_files.map(&:observations).flatten
75
+ end
76
+
84
77
  def average_pomodoros
85
- if @parsed_files.size.positive? && pomodoros.positive?
86
- return (pomodoros / @parsed_files.size)
78
+ if @parsed_files.size.positive? && pomodoros_sum.positive?
79
+ return (pomodoros_sum.to_f / @parsed_files.size).round(1)
87
80
  end
88
81
 
89
82
  0
90
83
  end
91
84
 
92
- def pomodoros
85
+ def pomodoros_sum
93
86
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
94
87
 
95
- @pomodoros ||=
88
+ @pomodoros_sum ||=
96
89
  @parsed_files.reduce(0) { |sum, f| sum + f.pomodoros || 0 }
97
90
  end
98
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
+
99
101
  def freeze
100
102
  @frozen = true
101
103
  end
@@ -115,18 +117,25 @@ module WorkMd
115
117
  # rubocop:disable Metrics/CyclomaticComplexity
116
118
  # rubocop:disable Metrics/PerceivedComplexity
117
119
  def parse_content(parsed_file, content)
118
- if content.start_with?(@t[:tasks])
119
- parsed_file.tasks = parse_task_list(content)
120
+ if content.start_with?('# ')
121
+ parsed_file.date =
122
+ content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
123
+ elsif content.start_with?(@t[:tasks])
124
+ parsed_file.tasks = parse_check_list(content)
120
125
  elsif content.start_with?(@t[:meetings])
121
- parsed_file.meetings = parse_list(content)
122
- elsif content.start_with?(@t[:meeting_annotations])
123
- parsed_file.meeting_annotations = basic_parse(content)
124
- elsif content.start_with?(@t[:annotations])
125
- parsed_file.annotations = basic_parse(content)
126
+ parsed_file.meetings = parse_check_list(content)
126
127
  elsif content.start_with?(@t[:interruptions])
127
- parsed_file.interruptions = parse_list(content)
128
+ parsed_file.interruptions = parse_list(content).map do |interruption|
129
+ "(#{parsed_file.date}) #{interruption}"
130
+ end
128
131
  elsif content.start_with?(@t[:difficulties])
129
- parsed_file.difficulties = parse_list(content)
132
+ parsed_file.difficulties = parse_list(content).map do |difficulty|
133
+ "(#{parsed_file.date}) #{difficulty}"
134
+ end
135
+ elsif content.start_with?(@t[:observations])
136
+ parsed_file.observations = parse_list(content).map do |observations|
137
+ "(#{parsed_file.date}) #{observations}"
138
+ end
130
139
  elsif content.start_with?(@t[:pomodoros])
131
140
  parsed_file.pomodoros = parse_pomodoro(content)
132
141
  end
@@ -134,7 +143,7 @@ module WorkMd
134
143
  # rubocop:enable Metrics/CyclomaticComplexity
135
144
  # rubocop:enable Metrics/PerceivedComplexity
136
145
 
137
- def parse_task_list(content)
146
+ def parse_check_list(content)
138
147
  clear_list(basic_parse(content).split('- ['))
139
148
  end
140
149
 
@@ -159,6 +168,6 @@ module WorkMd
159
168
  .map(&:strip)
160
169
  end
161
170
  end
171
+ # rubocop:enable Metrics/ClassLength
162
172
  end
163
173
  end
164
- # rubocop:enable Metrics/ClassLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.5'
4
+ VERSION = '0.2.9'
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.5
4
+ version: 0.2.9
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-14 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -53,7 +53,10 @@ 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/tyesterday.rb
57
+ - lib/work_md/commands/yesterday.rb
56
58
  - lib/work_md/config.rb
59
+ - lib/work_md/file.rb
57
60
  - lib/work_md/parser/engine.rb
58
61
  - lib/work_md/version.rb
59
62
  homepage: