fewald-worklog 0.1.8 → 0.1.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: e12db32224c9de9918c8ec94a01f033d09f4e157d53958cdc733b4555f24895e
4
- data.tar.gz: c825cdb202b22b27f14b5bba6617a0c5511f5b75721e543deb6ae6c38bdb7f6f
3
+ metadata.gz: 04c383f8fdef10be4e54ff89c59e3a89ee96c23c18688cf8d85ab972125d782d
4
+ data.tar.gz: 105a71a7563257e67573c3331baeac23a1cec8d5b5c0b50a846fae90373ec05e
5
5
  SHA512:
6
- metadata.gz: d29144ca0648fb5ad056bb7317a096bcaf7eb63dd6aa2022c6581309493c9d009811d698f2d445b57d981cbca6fe636ec0fa605489de4a49fc46f4275b710141
7
- data.tar.gz: dcbf6fc6e56340e453f745bd8eb1235c93416deee11e6109d37f240906f2e66542a06a6ffa1de5a561a07f918182d42e50e1b5d761b0c0e42636ee520613cc19
6
+ metadata.gz: 7b506d69b1abf9f0f540003d4a6c6012120d3269747840ad85ac8e055920eff99dfff63be2f899de13842033fdc3cf2ac757afb97e7294cf3749fcd32b3afb7e
7
+ data.tar.gz: 4b6171aeb03cbcc92ccda7f9eda6a7cbf32f78ef7739e80ee9aa685af8248f2a1527437506dc49392bbb17371cad5040528a47f410d45fc6e6cf126b2aa5da37
data/bin/wl CHANGED
@@ -6,6 +6,8 @@
6
6
  if ENV['WL_PATH']
7
7
  # Import the worklog CLI from the path specified in the WL_PATH environment variable
8
8
  # This is used during development to avoid having to rely on the order of the $PATH.
9
+ puts "Loading worklog from #{ENV['WL_PATH']}. This should only be used during development."
10
+ puts 'To use the installed worklog, unset the WL_PATH environment variable.'
9
11
  require_relative File.join(ENV['WL_PATH'], 'worklog', 'cli')
10
12
  else
11
13
  require_relative '../worklog/cli'
data/worklog/cli.rb CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  # frozen_string_literal: true
3
2
 
4
3
  # Add the current directory to the load path
@@ -9,12 +8,12 @@ require 'thor'
9
8
  require 'date'
10
9
  require 'logger'
11
10
 
11
+ require_relative 'worklog'
12
12
  require 'date_parser'
13
13
  require 'printer'
14
14
  require 'statistics'
15
15
  require 'storage'
16
16
  require 'webserver'
17
- require 'worklog'
18
17
  require_relative 'summary'
19
18
  require_relative 'editor'
20
19
  require_relative 'string_helper'
@@ -56,7 +55,7 @@ class WorklogCLI < Thor
56
55
  time = Time.strptime(options[:time], '%H:%M:%S')
57
56
  Storage.create_file_skeleton(date)
58
57
 
59
- daily_log = Storage.load_log(Storage.filepath(date))
58
+ daily_log = Storage.load_log!(Storage.filepath(date))
60
59
  daily_log.entries << LogEntry.new(time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
61
60
  epic: options[:epic], message:)
62
61
 
@@ -64,7 +63,8 @@ class WorklogCLI < Thor
64
63
  daily_log.entries.sort_by!(&:time)
65
64
 
66
65
  Storage.write_log(Storage.filepath(options[:date]), daily_log)
67
- WorkLogger.info Rainbow("Added to the work log for #{options[:date]}").green
66
+
67
+ WorkLogger.info Rainbow("Added entry on #{options[:date]}: #{message}").green
68
68
  end
69
69
 
70
70
  desc 'edit', 'Edit a specified day in the work log'
@@ -100,7 +100,7 @@ class WorklogCLI < Thor
100
100
  exit 1
101
101
  end
102
102
 
103
- daily_log = Storage.load_log(Storage.filepath(options[:date]))
103
+ daily_log = Storage.load_log!(Storage.filepath(options[:date]))
104
104
  if daily_log.entries.empty?
105
105
  WorkLogger.error Rainbow("No entries found for #{options[:date]}. Aborting.").red
106
106
  exit 1
@@ -260,8 +260,3 @@ class WorklogCLI < Thor
260
260
  end
261
261
  end
262
262
  end
263
-
264
- # Start the CLI if the file is executed
265
- # This prevents the CLI from starting when the file is required in another file,
266
- # which is useful for testing.
267
- WorklogCLI.start if __FILE__ == $PROGRAM_NAME
data/worklog/person.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
3
2
 
4
3
  # Represents a person at work.
5
4
  class Person
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'date'
4
- require 'storage'
4
+ require_relative 'storage'
5
5
 
6
6
  STATS = Data.define(:total_days, :total_entries, :total_epics, :avg_entries, :first_entry, :last_entry)
7
7
 
8
8
  # Module for calculating statistics for the work log.
9
9
  module Statistics
10
10
  # Calculate statistics for the work log for all days.
11
- # @return [STATS]
11
+ # @return [STATS] The statistics for the work log
12
12
  def self.calculate
13
13
  all_entries = Storage.all_days
14
14
  return STATS.new(0, 0, 0, 0, Date.today, Date.today) if all_entries.empty?
data/worklog/storage.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rainbow'
4
4
  require_relative 'daily_log'
5
5
  require_relative 'logger'
6
+ require_relative 'person'
6
7
 
7
8
  module Storage
8
9
  # LogNotFoundError is raised when a log file is not found
@@ -16,11 +17,14 @@ module Storage
16
17
  end
17
18
 
18
19
  # Return all days with logs
20
+ # @return [Array<DailyLog>] List of logs
19
21
  def self.all_days
20
22
  return [] unless folder_exists?
21
23
 
22
24
  logs = []
23
25
  Dir.glob(File.join(DATA_DIR, "*#{FILE_SUFFIX}")).map do |file|
26
+ next if file.end_with?('people.yaml')
27
+
24
28
  logs << load_log(file)
25
29
  end
26
30
 
@@ -44,7 +48,7 @@ module Storage
44
48
 
45
49
  while start_date <= end_date
46
50
  if File.exist?(filepath(start_date))
47
- tmp_logs = load_log(filepath(start_date))
51
+ tmp_logs = load_log!(filepath(start_date))
48
52
  tmp_logs.entries.keep_if { |entry| entry.epic? } if epics_only
49
53
 
50
54
  if tags_filter
@@ -61,6 +65,7 @@ module Storage
61
65
  end
62
66
 
63
67
  # Create file for a new day if it does not exist
68
+ # @param [Date] date The date, used as the file name.
64
69
  def self.create_file_skeleton(date)
65
70
  create_folder
66
71
 
@@ -98,11 +103,31 @@ module Storage
98
103
  end
99
104
 
100
105
  def self.load_single_log_file(file, headline = true)
101
- daily_log = load_log(file)
106
+ daily_log = load_log!(file)
102
107
  puts "Work log for #{Rainbow(daily_log.date).gold}:" if headline
103
108
  daily_log.entries
104
109
  end
105
110
 
111
+ # Load all people from the people file
112
+ # @return [Array<Person>] List of people
113
+ def self.load_people!
114
+ people_file = File.join(DATA_DIR, 'people.yaml')
115
+ return [] unless File.exist?(people_file)
116
+
117
+ YAML.load_file(people_file, permitted_classes: [Person])
118
+ end
119
+
120
+ # Write people to the people file
121
+ # @param [Array<Person>] people List of people
122
+ def self.write_people!(people)
123
+ create_folder
124
+
125
+ people_file = File.join(DATA_DIR, 'people.yaml')
126
+ File.open(people_file, 'w') do |f|
127
+ f.puts people.to_yaml
128
+ end
129
+ end
130
+
106
131
  private
107
132
 
108
133
  # Create folder if not exists already.
@@ -110,8 +135,10 @@ module Storage
110
135
  Dir.mkdir(DATA_DIR) unless Dir.exist?(DATA_DIR)
111
136
  end
112
137
 
138
+ # Construct filepath for a given date.
139
+ # @param [Date] date The date
140
+ # @return [String] The filepath
113
141
  def filepath(date)
114
- # Construct filepath for a given date.
115
142
  File.join(DATA_DIR, "#{date}#{FILE_SUFFIX}")
116
143
  end
117
144
 
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- # typed: true
3
2
 
4
3
  # Helpers for String manipulation
5
4
  module StringHelper
data/worklog/worklog.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'optparse'
5
+ require 'rainbow'
6
+ require 'yaml'
7
+
4
8
  require_relative 'hash'
5
9
  require_relative 'daily_log'
6
10
  require_relative 'log_entry'
7
11
  require_relative 'storage'
8
12
 
9
- require 'optparse'
10
- require 'rainbow'
11
- require 'yaml'
12
-
13
13
  module Worklog
14
14
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-13 00:00:00.000000000 Z
10
+ date: 2025-03-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: httparty