fewald-worklog 0.2.4 → 0.2.6

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: 0bf5afbd99a91e77e5a3d16101653fecdeafdd808c5ca7c4ea23aa60be01ad54
4
- data.tar.gz: 24c33cda5e47f1878c814bcb22ab06d9295e9e4d2e3f59b39ccdcf8801d3e8d9
3
+ metadata.gz: 6006eac22572b9dfaa7907f122d1f9e1b59ed633abdb58f8e7cff1fd1ae05216
4
+ data.tar.gz: a88c31463ccf65fa26af9ad68b48b0d195ab4c0ee99724eb3cecf5ef694d5ef2
5
5
  SHA512:
6
- metadata.gz: '09d41c3cc186e650aebbca3d91840cfbec6c6207a67929c3b1b379b470008d00acacf8ff38ae20d9d648589354e2e2538220852ee86ad564a69b76e7b86607fa'
7
- data.tar.gz: d8da05a9c100cc1b59243a303910faa2a675f0c15ade7ac253fb846b5e3435895245d454c0cf0957a096a94c6dcddeca0f2a8114f7f0c12d759189413dcef690
6
+ metadata.gz: e9a68724ee65d0075d247c29ae0c4fd03790f4943f7ca11e6063c10300da4ca69872c64e3b968a8976824a9627fb781680277b02d76e408f5861b5a9cd90bbc6
7
+ data.tar.gz: 938cd3f3b08fcb78f992e996a2ad3118e8cbbaf680149943f4d6e18da5ddcaf45a8e8806ba3562552946d9a930ca858edb9f4c3b3fff061ccee1dc533ab67d85
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.6
data/lib/cli.rb CHANGED
@@ -16,7 +16,6 @@ require 'printer'
16
16
  require 'statistics'
17
17
  require 'storage'
18
18
  require 'string_helper'
19
- require 'summary'
20
19
  require 'version'
21
20
  require 'webserver'
22
21
 
@@ -104,9 +103,22 @@ class WorklogCLI < Thor
104
103
  end
105
104
 
106
105
  desc 'tags', 'Show all tags used in the work log'
107
- def tags
106
+ option :date, type: :string, default: DateTime.now.strftime('%Y-%m-%d'),
107
+ desc: <<~DESC
108
+ Show the work log for a specific date. If this option is provided, --from and --to and --days should not be used.
109
+ DESC
110
+ option :from, type: :string, desc: <<~EOF
111
+ Inclusive start date of the range. Takes precedence over --date, if defined.
112
+ EOF
113
+ option :to, type: :string, desc: <<~EOF
114
+ Inclusive end date of the range. Takes precedence over --date, if defined.
115
+ EOF
116
+ option :days, type: :numeric, desc: <<~EOF
117
+ Number of days to show starting from --date. Takes precedence over --from and --to if defined.
118
+ EOF
119
+ def tags(tag = nil)
108
120
  worklog = Worklog.new
109
- worklog.tags(options)
121
+ worklog.tags(tag, options)
110
122
  end
111
123
 
112
124
  desc 'server', 'Start the work log server'
data/lib/daily_log.rb CHANGED
@@ -15,17 +15,19 @@ class DailyLog
15
15
  @entries = params[:entries]
16
16
  end
17
17
 
18
+ # Returns true if there are people mentioned in any entry of the current day.
19
+ #
20
+ # @return [Boolean] true if there are people mentioned, false otherwise.
18
21
  def people?
19
- # Returns true if there are people mentioned in any entry of the current day.
20
22
  people.size.positive?
21
23
  end
22
24
 
25
+ # Returns a hash of people mentioned in the log for the current day
26
+ # with the number of times they are mentioned.
27
+ # People are defined as words starting with @ or ~.
28
+ #
29
+ # @return [Hash<String, Integer>]
23
30
  def people
24
- # Returns a hash of people mentioned in the log for the current day
25
- # with the number of times they are mentioned.
26
- # People are defined as words starting with @ or ~.
27
- #
28
- # @return [Hash<String, Integer>]
29
31
  entries.map(&:people).flatten.tally
30
32
  end
31
33
 
@@ -41,6 +43,10 @@ class DailyLog
41
43
  entries.flat_map(&:tags).uniq.sort
42
44
  end
43
45
 
46
+ # Equals method to compare two DailyLog objects.
47
+ #
48
+ # @param other [DailyLog] the other DailyLog object to compare with
49
+ # @return [Boolean] true if both DailyLog objects have the same date and entries, false otherwise
44
50
  def ==(other)
45
51
  date == other.date && entries == other.entries
46
52
  end
data/lib/log_entry.rb CHANGED
@@ -31,7 +31,7 @@ class LogEntry
31
31
  end
32
32
 
33
33
  # Returns the message string with formatting without the time.
34
- # @param people Hash[String, Person] A hash of people with their handles as keys.
34
+ # @param known_people Hash[String, Person] A hash of people with their handles as keys.
35
35
  def message_string(known_people = nil)
36
36
  # replace all mentions of people with their names.
37
37
  msg = @message.dup
data/lib/worklog.rb CHANGED
@@ -14,6 +14,7 @@ require 'worklogger'
14
14
  require 'string_helper'
15
15
  require 'printer'
16
16
  require 'statistics'
17
+ require 'summary'
17
18
 
18
19
  # Main class providing all worklog functionality.
19
20
  # This class is the main entry point for the application.
@@ -138,9 +139,25 @@ class Worklog
138
139
  end
139
140
  end
140
141
 
141
- def tags(_options = {})
142
- all_logs = @storage.all_days
142
+ # Show all tags used in the work log or details for a specific tag
143
+ #
144
+ # @param tag [String, nil] the tag to show details for, or nil to show all tags
145
+ # @param options [Hash] the options hash containing date range
146
+ # @return [void]
147
+ #
148
+ # @example
149
+ # worklog.tags('example_tag', from: '2023-10-01', to: '2023-10-31')
150
+ # worklog.tags(nil) # Show all tags for all time
151
+ def tags(tag = nil, options = {})
152
+ if tag.nil? || tag.empty?
153
+ tag_overview
154
+ else
155
+ tag_detail(tag, options)
156
+ end
157
+ end
143
158
 
159
+ def tag_overview
160
+ all_logs = @storage.all_days
144
161
  puts Rainbow('Tags used in the work log:').gold
145
162
 
146
163
  # Count all tags used in the work log
@@ -153,6 +170,29 @@ class Worklog
153
170
  tags.sort.each { |k, v| puts "#{Rainbow(k.ljust(max_len)).gold}: #{v} #{pluralize(v, 'occurrence')}" }
154
171
  end
155
172
 
173
+ # Show detailed information about a specific tag
174
+ #
175
+ # @param tag [String] the tag to show details for
176
+ # @param options [Hash] the options hash containing date range
177
+ # @return [void]
178
+ #
179
+ # @example
180
+ # worklog.tag_detail('example_tag', from: '2023-10-01', to: '2023-10-31')
181
+ def tag_detail(tag, options)
182
+ printer = Printer.new(@storage.load_people!)
183
+ start_date, end_date = start_end_date(options)
184
+
185
+ @storage.days_between(start_date, end_date).each do |daily_log|
186
+ next unless daily_log.tags.include?(tag)
187
+
188
+ daily_log.entries.each do |entry|
189
+ next unless entry.tags.include?(tag)
190
+
191
+ printer.print_entry(daily_log, entry, true)
192
+ end
193
+ end
194
+ end
195
+
156
196
  def stats(_options = {})
157
197
  stats = Statistics.new(@config).calculate
158
198
  puts "#{format_left('Total days')}: #{stats.total_days}"
@@ -207,9 +247,11 @@ class Worklog
207
247
  elsif options[:from]
208
248
  start_date = DateParser.parse_date_string!(options[:from], true)
209
249
  end_date = DateParser.parse_date_string!(options[:to], false) if options[:to]
210
- else
250
+ elsif options[:date]
211
251
  start_date = Date.strptime(options[:date], '%Y-%m-%d')
212
252
  end_date = start_date
253
+ else
254
+ raise ArgumentError, 'No date range specified. Use --days, --from, --to or --date options.'
213
255
  end
214
256
  [start_date, end_date]
215
257
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald