fewald-worklog 0.1.8 → 0.1.10

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: db8631409f5e61546ef1df66fa5c25aab62c8dee8b1c1cd2f063aef110812e24
4
+ data.tar.gz: f592c82f2d2700d176d4e608cff5f0e6bb4b03ecf124a5457f94733a5d3b214f
5
5
  SHA512:
6
- metadata.gz: d29144ca0648fb5ad056bb7317a096bcaf7eb63dd6aa2022c6581309493c9d009811d698f2d445b57d981cbca6fe636ec0fa605489de4a49fc46f4275b710141
7
- data.tar.gz: dcbf6fc6e56340e453f745bd8eb1235c93416deee11e6109d37f240906f2e66542a06a6ffa1de5a561a07f918182d42e50e1b5d761b0c0e42636ee520613cc19
6
+ metadata.gz: 777233967f8f0b6140df0eb7d79c662857e64fa423be0164aa5c26950fef7dc63bf6447461436660d1c74a11e070c238bd73438a4f7070d6321b83da66aa3763
7
+ data.tar.gz: a91766b0e9bb4e6dded7bc9c2e8332f222ac8cf31855428afaff1a0f798d218dfa1750b72f21436d8a91d6be99af9937f2ebdc182fecda8fdf936ba31a23a61e
data/.version ADDED
@@ -0,0 +1 @@
1
+ 0.1.10
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,15 +8,16 @@ 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'
20
+ require_relative 'version'
21
21
 
22
22
  # CLI for the work log application
23
23
  class WorklogCLI < Thor
@@ -56,7 +56,7 @@ class WorklogCLI < Thor
56
56
  time = Time.strptime(options[:time], '%H:%M:%S')
57
57
  Storage.create_file_skeleton(date)
58
58
 
59
- daily_log = Storage.load_log(Storage.filepath(date))
59
+ daily_log = Storage.load_log!(Storage.filepath(date))
60
60
  daily_log.entries << LogEntry.new(time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
61
61
  epic: options[:epic], message:)
62
62
 
@@ -64,7 +64,8 @@ class WorklogCLI < Thor
64
64
  daily_log.entries.sort_by!(&:time)
65
65
 
66
66
  Storage.write_log(Storage.filepath(options[:date]), daily_log)
67
- WorkLogger.info Rainbow("Added to the work log for #{options[:date]}").green
67
+
68
+ WorkLogger.info Rainbow("Added entry on #{options[:date]}: #{message}").green
68
69
  end
69
70
 
70
71
  desc 'edit', 'Edit a specified day in the work log'
@@ -100,7 +101,7 @@ class WorklogCLI < Thor
100
101
  exit 1
101
102
  end
102
103
 
103
- daily_log = Storage.load_log(Storage.filepath(options[:date]))
104
+ daily_log = Storage.load_log!(Storage.filepath(options[:date]))
104
105
  if daily_log.entries.empty?
105
106
  WorkLogger.error Rainbow("No entries found for #{options[:date]}. Aborting.").red
106
107
  exit 1
@@ -219,6 +220,11 @@ class WorklogCLI < Thor
219
220
  puts Summary.generate_summary(entries)
220
221
  end
221
222
 
223
+ desc 'version', 'Show the version of the Worklog'
224
+ def version
225
+ puts "Worklog #{current_version} running on Ruby #{RUBY_VERSION}"
226
+ end
227
+
222
228
  # Define shortcuts and aliases
223
229
  map 'a' => :add
224
230
  map 'statistics' => :stats
@@ -260,8 +266,3 @@ class WorklogCLI < Thor
260
266
  end
261
267
  end
262
268
  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.10
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-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: httparty
@@ -106,6 +106,7 @@ executables:
106
106
  extensions: []
107
107
  extra_rdoc_files: []
108
108
  files:
109
+ - ".version"
109
110
  - bin/wl
110
111
  - worklog/cli.rb
111
112
  - worklog/daily_log.rb