work_md 0.2.5 → 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: 8d5b841881acd03d54092af4c2e04b6fa29356b784ac52905810a3ba021c01de
4
- data.tar.gz: 324ad983b70bd2749e7c888a21949a7c8b66ca6bbe7c3c7ebabeaeaee7f83a3d
3
+ metadata.gz: 566027a143beb9e55274abe76ef2f0d0c7a44078d4773c595e9cdce2175a2c32
4
+ data.tar.gz: d4094062e154849f8514d26c20d52d37e931d3f844f2b162cb26eab2b7a70d5d
5
5
  SHA512:
6
- metadata.gz: 7ab6691773bf32657133a362cfbb42a45e6fbace7a716dcd20f065fe081297ae720efc3b1bcaa86a297327d61886522b45101c3d65fc0bfa3edbdf2422611b28
7
- data.tar.gz: e6de20ebdf9b3a5055bc4f1c0e822de41e37ee9ea4131ddc4268c0c47e0acc5d388f2c8864dbc0171dfd419264ea7aec9bc56fe26431475cd9351b12efa704e7
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")
@@ -71,9 +62,11 @@ module WorkMd
71
62
  else
72
63
  ::TTY::Editor.open(PARSED_FILE_PATH)
73
64
  end
74
- rescue
65
+ rescue => e
75
66
  WorkMd::Cli.info(
76
67
  ::TTY::Box.frame(
68
+ "message: #{e.message}",
69
+ "",
77
70
  "Usage examples:",
78
71
  "",
79
72
  "work_md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000",
@@ -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,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,8 +10,6 @@ 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',
17
15
  pomodoros: 'Pomodoros / Ciclos',
@@ -21,8 +19,6 @@ module WorkMd
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
24
  pomodoros: 'Pomodoros / Cycles',
@@ -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
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
4
3
  module WorkMd
5
4
  module Parser
6
5
  class Engine
@@ -9,11 +8,10 @@ module WorkMd
9
8
 
10
9
  class ParsedFile
11
10
  attr_accessor :tasks,
12
- :annotations,
13
- :meeting_annotations,
14
11
  :meetings,
15
12
  :interruptions,
16
13
  :difficulties,
14
+ :date,
17
15
  :pomodoros
18
16
  end
19
17
 
@@ -27,7 +25,7 @@ module WorkMd
27
25
  raise IS_FROZEN_ERROR_MESSAGE if @frozen
28
26
 
29
27
  begin
30
- file_content = File.read(file)
28
+ file_content = ::File.read(file)
31
29
  rescue Errno::ENOENT
32
30
  return
33
31
  end
@@ -50,19 +48,6 @@ module WorkMd
50
48
  @tasks ||= @parsed_files.map(&:tasks).flatten
51
49
  end
52
50
 
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
51
  def meetings
67
52
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
68
53
 
@@ -115,18 +100,22 @@ module WorkMd
115
100
  # rubocop:disable Metrics/CyclomaticComplexity
116
101
  # rubocop:disable Metrics/PerceivedComplexity
117
102
  def parse_content(parsed_file, content)
118
- if content.start_with?(@t[:tasks])
119
- 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)
120
108
  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)
109
+ parsed_file.meetings = parse_check_list(content)
126
110
  elsif content.start_with?(@t[:interruptions])
127
- parsed_file.interruptions = parse_list(content)
111
+ parsed_file.interruptions = parse_list(content).map do |interruption|
112
+ "(#{parsed_file.date}) #{interruption}"
113
+ end
128
114
  elsif content.start_with?(@t[:difficulties])
129
- parsed_file.difficulties = parse_list(content)
115
+ parsed_file.difficulties = parse_list(content).map do |difficulty|
116
+ "(#{parsed_file.date}) #{difficulty}"
117
+ end
118
+
130
119
  elsif content.start_with?(@t[:pomodoros])
131
120
  parsed_file.pomodoros = parse_pomodoro(content)
132
121
  end
@@ -134,7 +123,7 @@ module WorkMd
134
123
  # rubocop:enable Metrics/CyclomaticComplexity
135
124
  # rubocop:enable Metrics/PerceivedComplexity
136
125
 
137
- def parse_task_list(content)
126
+ def parse_check_list(content)
138
127
  clear_list(basic_parse(content).split('- ['))
139
128
  end
140
129
 
@@ -161,4 +150,3 @@ module WorkMd
161
150
  end
162
151
  end
163
152
  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.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.5
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-14 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: