work_md 0.2.3 → 0.2.7

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: e1c858bf12a976912f85e9fd1a22b39e2bd5daf4e56ec46299c1297aa4e576cb
4
- data.tar.gz: 8a542af4507b9765d9317f23ad7db72bc1f4cf8ffe7bc27342ea9c1e8f592e82
3
+ metadata.gz: 240715cce22ce57249e206aaccb86151732c059fa4af0f00b1b3d2c8f47389bb
4
+ data.tar.gz: 436b17f29758239fe959abdf6d8ffaf24f629ba3fb41315bf92e8c42eaaac4cb
5
5
  SHA512:
6
- metadata.gz: '02389407af0f604e5cf9fac532639b5cb5553179cd98d67fa18aecf56bc182cccbc2bc674cd1f8ca3f5b11ede62d82d8b85320613a55e0cf6d432f273618e06a'
7
- data.tar.gz: 3983b233410dd07224abf01bf74998c31307780b52b43cdb83495d4745ed83938c72d0f0cb449e34dcdb7cded9e28fd5dec440fedacd823446f8ec0309152457
6
+ metadata.gz: 595cc7e93141034918c3076dcf1416fe46ba9c0194fd06026e117269c73482a595d8d6cfdf7b23cc73e67a60880971d3ba2c76453a567ea6581d273c529414d7
7
+ data.tar.gz: e9599c13e70ade59262afb89dca054c8dc54821906e9eca4a113efc579716f3df2e1e2f91819d1a0b0edb77a632b8d227233aa3912b70fd87dcb509b984cd0ed
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,25 +59,33 @@ module WorkMd
60
59
  f.puts("- #{difficulty}\n\n")
61
60
  end
62
61
  f.puts("---\n\n")
63
- f.puts("### #{t[:pomodoros]}:\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")
67
+ f.puts("### #{t[:pomodoros]} (#{parser.average_pomodoros} #{t[:per_day]}):\n\n")
64
68
  f.puts(parser.pomodoros)
65
69
  end
66
70
 
67
71
  editor = WorkMd::Config.editor
68
72
 
69
73
  unless editor.nil?
70
- ::TTY::Editor.open(PARSED_FILE_PATH, {command: editor})
74
+ ::TTY::Editor.open(PARSED_FILE_PATH, command: editor)
71
75
  else
72
76
  ::TTY::Editor.open(PARSED_FILE_PATH)
73
77
  end
74
- rescue
78
+ rescue => e
75
79
  WorkMd::Cli.info(
76
80
  ::TTY::Box.frame(
81
+ "message: #{e.message}",
82
+ "",
77
83
  "Usage examples:",
78
84
  "",
79
85
  "work_md parse -d=1 -m=5 -y=2000 | get day 1 from month 5 and year 2000",
80
86
  "work_md parse -d=1,2,3 | get day 1, 2 and 3 from the current month and year",
81
87
  "work_md parse -d=1,2 -m=4 | get day 1 and 2 from month 4 and current year",
88
+ "work_md parse -d=1..10 -m=4 | get day 1 to 10 from month 4 and current year",
82
89
  **WorkMd::Cli.error_frame_style
83
90
  )
84
91
  )
@@ -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,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkMd
4
+ module Commands
5
+ class Tyesterday
6
+ class << self
7
+ def execute(_argv = [])
8
+ WorkMd::File.open_or_create(DateTime.now)
9
+ WorkMd::File.open_or_create(Date.today.prev_day)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ 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,21 +10,21 @@ 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
- pomodoros: 'Pomodoros'
15
+ observations: 'Observações',
16
+ pomodoros: 'Pomodoros / Ciclos',
17
+ per_day: 'por dia'
18
18
  },
19
19
  'en' =>
20
20
  {
21
21
  tasks: 'Tasks',
22
22
  meetings: 'Meetings',
23
- annotations: 'Annotations',
24
- meeting_annotations: 'Meeting Annotations',
25
23
  interruptions: 'Interruptions',
26
24
  difficulties: 'Difficulties',
27
- pomodoros: 'Pomodoros'
25
+ observations: 'Observations',
26
+ pomodoros: 'Pomodoros / Cycles',
27
+ per_day: 'per day'
28
28
  }
29
29
  }.freeze
30
30
 
@@ -0,0 +1,50 @@
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[:observations]}:\n\n")
30
+ f.puts("---\n\n")
31
+ f.puts("### #{t[:pomodoros]}:\n\n")
32
+ f.puts("0\n\n")
33
+ end
34
+ end
35
+
36
+ editor = WorkMd::Config.editor
37
+
38
+ ::FileUtils.cd(work_dir) do
39
+ if editor.nil?
40
+ ::TTY::Editor.open("#{some_date.strftime('%Y/%m/%d')}.md")
41
+ else
42
+ ::TTY::Editor.open(
43
+ "#{some_date.strftime('%Y/%m/%d')}.md",
44
+ command: editor
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -2,17 +2,18 @@
2
2
 
3
3
  module WorkMd
4
4
  module Parser
5
+ # rubocop:disable Metrics/ClassLength
5
6
  class Engine
6
7
  IS_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is frozen'
7
8
  IS_NOT_FROZEN_ERROR_MESSAGE = 'WorkMd::Parser::Engine is not frozen'
8
9
 
9
10
  class ParsedFile
10
11
  attr_accessor :tasks,
11
- :annotations,
12
- :meeting_annotations,
13
12
  :meetings,
14
13
  :interruptions,
15
14
  :difficulties,
15
+ :observations,
16
+ :date,
16
17
  :pomodoros
17
18
  end
18
19
 
@@ -26,7 +27,7 @@ module WorkMd
26
27
  raise IS_FROZEN_ERROR_MESSAGE if @frozen
27
28
 
28
29
  begin
29
- file_content = File.read(file)
30
+ file_content = ::File.read(file)
30
31
  rescue Errno::ENOENT
31
32
  return
32
33
  end
@@ -49,35 +50,36 @@ module WorkMd
49
50
  @tasks ||= @parsed_files.map(&:tasks).flatten
50
51
  end
51
52
 
52
- def annotations
53
+ def meetings
53
54
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
54
55
 
55
- @annotations ||= @parsed_files.map(&:annotations).flatten
56
+ @meetings ||= @parsed_files.map(&:meetings).flatten
56
57
  end
57
58
 
58
- def meeting_annotations
59
+ def interruptions
59
60
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
60
61
 
61
- @meeting_annotations ||=
62
- @parsed_files.map(&:meeting_annotations).flatten
62
+ @interruptions ||= @parsed_files.map(&:interruptions).flatten
63
63
  end
64
64
 
65
- def meetings
65
+ def difficulties
66
66
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
67
67
 
68
- @meetings ||= @parsed_files.map(&:meetings).flatten
68
+ @difficulties ||= @parsed_files.map(&:difficulties).flatten
69
69
  end
70
70
 
71
- def interruptions
71
+ def observations
72
72
  raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
73
73
 
74
- @interruptions ||= @parsed_files.map(&:interruptions).flatten
74
+ @observations ||= @parsed_files.map(&:observations).flatten
75
75
  end
76
76
 
77
- def difficulties
78
- raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen
77
+ def average_pomodoros
78
+ if @parsed_files.size.positive? && pomodoros.positive?
79
+ return (pomodoros.to_f / @parsed_files.size).round(1)
80
+ end
79
81
 
80
- @difficulties ||= @parsed_files.map(&:difficulties).flatten
82
+ 0
81
83
  end
82
84
 
83
85
  def pomodoros
@@ -106,18 +108,25 @@ module WorkMd
106
108
  # rubocop:disable Metrics/CyclomaticComplexity
107
109
  # rubocop:disable Metrics/PerceivedComplexity
108
110
  def parse_content(parsed_file, content)
109
- if content.start_with?(@t[:tasks])
110
- parsed_file.tasks = parse_task_list(content)
111
+ if content.start_with?('# ')
112
+ parsed_file.date =
113
+ content.split(' - ')[0].gsub('# ', '').gsub("\n\n", '')
114
+ elsif content.start_with?(@t[:tasks])
115
+ parsed_file.tasks = parse_check_list(content)
111
116
  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)
117
+ parsed_file.meetings = parse_check_list(content)
117
118
  elsif content.start_with?(@t[:interruptions])
118
- parsed_file.interruptions = parse_list(content)
119
+ parsed_file.interruptions = parse_list(content).map do |interruption|
120
+ "(#{parsed_file.date}) #{interruption}"
121
+ end
119
122
  elsif content.start_with?(@t[:difficulties])
120
- parsed_file.difficulties = parse_list(content)
123
+ parsed_file.difficulties = parse_list(content).map do |difficulty|
124
+ "(#{parsed_file.date}) #{difficulty}"
125
+ end
126
+ elsif content.start_with?(@t[:observations])
127
+ parsed_file.observations = parse_list(content).map do |observations|
128
+ "(#{parsed_file.date}) #{observations}"
129
+ end
121
130
  elsif content.start_with?(@t[:pomodoros])
122
131
  parsed_file.pomodoros = parse_pomodoro(content)
123
132
  end
@@ -125,7 +134,7 @@ module WorkMd
125
134
  # rubocop:enable Metrics/CyclomaticComplexity
126
135
  # rubocop:enable Metrics/PerceivedComplexity
127
136
 
128
- def parse_task_list(content)
137
+ def parse_check_list(content)
129
138
  clear_list(basic_parse(content).split('- ['))
130
139
  end
131
140
 
@@ -150,5 +159,6 @@ module WorkMd
150
159
  .map(&:strip)
151
160
  end
152
161
  end
162
+ # rubocop:enable Metrics/ClassLength
153
163
  end
154
164
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkMd
4
- VERSION = '0.2.3'
4
+ VERSION = '0.2.7'
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.3
4
+ version: 0.2.7
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-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: