timet 1.4.0 → 1.4.1
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 +4 -4
- data/README.md +3 -2
- data/lib/timet/application.rb +21 -20
- data/lib/timet/application_helper.rb +27 -0
- data/lib/timet/database.rb +35 -7
- data/lib/timet/version.rb +2 -2
- metadata +2 -3
- data/lib/timet/status_helper.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e9f44f4ee2f1ae5aab382b308364ffeaffa5e09bf21d1578e8f5267ff715f0f
|
4
|
+
data.tar.gz: 13becd17288c93925e91a3c49dcdc7f4f7e7afe41d1469a10a7f931930b2d26d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27fca2e9adef3a4695a497b21106a400e7448caff946efccba034f9bbfcb29962822a632f17e3ab51856de764826257f5d6b33458d69fd9b56eebeb91946e5b8
|
7
|
+
data.tar.gz: df46d99862c3366f63f4ad007fbece638f88ca997fa2085070a78c065306b23888ecbbd5b610ba99582898395201dd00a1a8871de0ef8983d24c9ec3edefe32b
|
data/README.md
CHANGED
@@ -106,7 +106,7 @@ gem install timet
|
|
106
106
|
+-------+------------+--------+----------+----------+----------+--------------------------+
|
107
107
|
```
|
108
108
|
---
|
109
|
-
- **timet resume**:
|
109
|
+
- **timet resume [id]**: This command allows users to quickly resume tracking a task that was previously in progress. If an id is provided, it resumes the tracking session for the specified task. If no id is provided, it resumes the last completed task.
|
110
110
|
|
111
111
|
```
|
112
112
|
Tracked time report [today]:
|
@@ -177,9 +177,10 @@ gem install timet
|
|
177
177
|
| `timet summary resume (r)` | Resume tracking the last task. | `timet su r` |
|
178
178
|
| `timet delete [id]` | Delete a task by its ID. | `timet d [id]` |
|
179
179
|
| `timet cancel` | Cancel active time tracking. | `timet c` |
|
180
|
-
| `timet edit [id]` | Update a task's notes, tag, start or end fields. | `timet e [
|
180
|
+
| `timet edit [id]` | Update a task's notes, tag, start or end fields. | `timet e [id]` |
|
181
181
|
| `timet su [date]` | Display a report of tracked time for a specific date. | `timet su 2024-01-03` |
|
182
182
|
| `timet su [start_date]..[end_date]` | Display a report of tracked time for a date range. | `timet su 2024-01-02..2024-01-03` |
|
183
|
+
| `timet resume [id]` | Resume tracking a task by ID or the last completed task. | `timet resume [id]` |
|
183
184
|
|
184
185
|
### Date Range in Summary
|
185
186
|
|
data/lib/timet/application.rb
CHANGED
@@ -69,9 +69,7 @@ module Timet
|
|
69
69
|
notes = options[:notes] || notes
|
70
70
|
pomodoro = (options[:pomodoro] || pomodoro).to_i
|
71
71
|
|
72
|
-
unless VALID_STATUSES_FOR_INSERTION.include?(@db.
|
73
|
-
return puts 'A task is currently being tracked.'
|
74
|
-
end
|
72
|
+
return puts 'A task is currently being tracked.' unless VALID_STATUSES_FOR_INSERTION.include?(@db.item_status)
|
75
73
|
|
76
74
|
@db.insert_item(start_time, tag, notes, pomodoro)
|
77
75
|
play_sound_and_notify(pomodoro * 60, tag) if pomodoro.positive?
|
@@ -87,13 +85,13 @@ module Timet
|
|
87
85
|
# @example Stop the current tracking session
|
88
86
|
# stop
|
89
87
|
#
|
90
|
-
# @note The method checks if the last tracking item is in progress by calling `@db.
|
88
|
+
# @note The method checks if the last tracking item is in progress by calling `@db.item_status`.
|
91
89
|
# @note If the last item is in progress, it fetches the last item's ID using `@db.fetch_last_id` and updates it
|
92
90
|
# with the current timestamp.
|
93
91
|
# @note The method then fetches the last item using `@db.last_item` and generates a summary if the result
|
94
92
|
# is not nil.
|
95
93
|
def stop(display = nil)
|
96
|
-
return unless @db.
|
94
|
+
return unless @db.item_status == :in_progress
|
97
95
|
|
98
96
|
last_id = @db.fetch_last_id
|
99
97
|
@db.update_item(last_id, 'end', TimeHelper.current_timestamp)
|
@@ -101,7 +99,7 @@ module Timet
|
|
101
99
|
summary unless display
|
102
100
|
end
|
103
101
|
|
104
|
-
desc 'resume (r)', 'resume last task'
|
102
|
+
desc 'resume (r) [id]', 'resume last task'
|
105
103
|
# Resumes the last tracking session if it was completed.
|
106
104
|
#
|
107
105
|
# @return [void] This method does not return a value; it performs side effects such as resuming a tracking session
|
@@ -110,23 +108,26 @@ module Timet
|
|
110
108
|
# @example Resume the last tracking session
|
111
109
|
# resume
|
112
110
|
#
|
113
|
-
# @
|
111
|
+
# @example Resume a specific task by ID
|
112
|
+
# resume(123)
|
113
|
+
#
|
114
|
+
# @note The method checks the status of the last tracking item using `@db.item_status`.
|
114
115
|
# @note If the last item is in progress, it prints a message indicating that a task is currently being tracked.
|
115
|
-
# @note If the last item is complete, it fetches the last item using `@db.last_item`,
|
116
|
+
# @note If the last item is complete, it fetches the last item using `@db.find_item` or `@db.last_item`,
|
117
|
+
# retrieves the tag and notes,
|
116
118
|
# and calls the `start` method to resume the tracking session.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
119
|
+
#
|
120
|
+
# @param id [Integer, nil] The ID of the tracking item to resume. If nil, the last item is used.
|
121
|
+
#
|
122
|
+
# @see Database#item_status
|
123
|
+
# @see Database#find_item
|
124
|
+
# @see #start
|
125
|
+
def resume(id = nil)
|
126
|
+
case @db.item_status(id)
|
121
127
|
when :in_progress
|
122
128
|
puts 'A task is currently being tracked.'
|
123
129
|
when :complete
|
124
|
-
|
125
|
-
if last_item
|
126
|
-
tag = last_item[FIELD_INDEX['tag']]
|
127
|
-
notes = last_item[FIELD_INDEX['notes']]
|
128
|
-
start(tag, notes)
|
129
|
-
end
|
130
|
+
resume_complete_task(id)
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
@@ -247,13 +248,13 @@ module Timet
|
|
247
248
|
# cancel
|
248
249
|
#
|
249
250
|
# @note The method fetches the ID of the last tracking item using `@db.fetch_last_id`.
|
250
|
-
# @note It checks if the last item is in progress by comparing `@db.
|
251
|
+
# @note It checks if the last item is in progress by comparing `@db.item_status` with `:complete`.
|
251
252
|
# @note If the last item is in progress, it deletes the item and prints a confirmation message using
|
252
253
|
# `delete_item_and_print_message(id, "Canceled active time tracking #{id}")`.
|
253
254
|
# @note If there is no active time tracking, it prints a message indicating that there is no active time tracking.
|
254
255
|
def cancel
|
255
256
|
id = @db.fetch_last_id
|
256
|
-
return puts 'There is no active time tracking' if @db.
|
257
|
+
return puts 'There is no active time tracking' if @db.item_status == :complete
|
257
258
|
|
258
259
|
delete_item_and_print_message(id, "Canceled active time tracking #{id}")
|
259
260
|
end
|
@@ -157,5 +157,32 @@ module Timet
|
|
157
157
|
@db.delete_item(id)
|
158
158
|
puts message
|
159
159
|
end
|
160
|
+
|
161
|
+
# Resumes a tracking session for a completed task.
|
162
|
+
#
|
163
|
+
# @param id [Integer, nil] The ID of the tracking item to resume. If nil, the last completed item is used.
|
164
|
+
#
|
165
|
+
# @return [void] This method does not return a value; it performs side effects such as resuming a tracking session.
|
166
|
+
#
|
167
|
+
# @example Resume the last completed task
|
168
|
+
# resume_complete_task
|
169
|
+
#
|
170
|
+
# @example Resume a specific task by ID
|
171
|
+
# resume_complete_task(123)
|
172
|
+
#
|
173
|
+
# @note The method fetches the specified or last completed item using `@db.find_item` or `@db.last_item`.
|
174
|
+
# @note If the item is found, it retrieves the tag and notes and calls the `start` method to resume the
|
175
|
+
# tracking session.
|
176
|
+
#
|
177
|
+
# @see Database#find_item
|
178
|
+
# @see Database#last_item
|
179
|
+
# @see #start
|
180
|
+
def resume_complete_task(id)
|
181
|
+
item = id ? @db.find_item(id) : @db.last_item
|
182
|
+
return unless item
|
183
|
+
|
184
|
+
tag, notes = item.values_at(Application::FIELD_INDEX['tag'], Application::FIELD_INDEX['notes'])
|
185
|
+
start(tag, notes)
|
186
|
+
end
|
160
187
|
end
|
161
188
|
end
|
data/lib/timet/database.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'sqlite3'
|
4
|
-
require_relative 'status_helper'
|
5
4
|
module Timet
|
6
5
|
# Provides database access for managing time tracking data.
|
7
6
|
class Database
|
8
|
-
include StatusHelper
|
9
|
-
|
10
7
|
# The default path to the SQLite database file.
|
11
8
|
DEFAULT_DATABASE_PATH = File.join(Dir.home, '.timet.db')
|
12
9
|
|
@@ -158,12 +155,15 @@ module Timet
|
|
158
155
|
# @return [Symbol] The status of the last item. Possible values are :no_items, :in_progress, or :complete.
|
159
156
|
#
|
160
157
|
# @example Determine the status of the last item
|
161
|
-
#
|
158
|
+
# item_status
|
162
159
|
#
|
163
160
|
# @note The method executes SQL to fetch the last item and determines its status using the `StatusHelper` module.
|
164
|
-
|
165
|
-
|
166
|
-
|
161
|
+
#
|
162
|
+
# @param id [Integer, nil] The ID of the item to check. If nil, the last item in the table is used.
|
163
|
+
#
|
164
|
+
def item_status(id = nil)
|
165
|
+
id = fetch_last_id if id.nil?
|
166
|
+
determine_status(find_item(id))
|
167
167
|
end
|
168
168
|
|
169
169
|
# Finds an item in the items table by its ID.
|
@@ -241,5 +241,33 @@ module Timet
|
|
241
241
|
|
242
242
|
format '%<hours>02d:%<minutes>02d:%<seconds>02d', hours: hours, minutes: minutes, seconds: seconds
|
243
243
|
end
|
244
|
+
|
245
|
+
# Determines the status of a time tracking result based on the presence and end time of items.
|
246
|
+
#
|
247
|
+
# @param result [Array] The result set containing time tracking items.
|
248
|
+
#
|
249
|
+
# @return [Symbol] The status of the time tracking result. Possible values are
|
250
|
+
# :no_items, :in_progress, or :complete.
|
251
|
+
#
|
252
|
+
# @example Determine the status of an empty result set
|
253
|
+
# StatusHelper.determine_status([]) # => :no_items
|
254
|
+
#
|
255
|
+
# @example Determine the status of a result set with an in-progress item
|
256
|
+
# StatusHelper.determine_status([[1, nil]]) # => :in_progress
|
257
|
+
#
|
258
|
+
# @example Determine the status of a result set with a completed item
|
259
|
+
# StatusHelper.determine_status([[1, 1633072800]]) # => :complete
|
260
|
+
#
|
261
|
+
# @note The method checks if the result set is empty and returns :no_items if true.
|
262
|
+
# @note If the last item in the result set has no end time, it returns :in_progress.
|
263
|
+
# @note If the last item in the result set has an end time, it returns :complete.
|
264
|
+
def determine_status(result)
|
265
|
+
return :no_items if result.nil?
|
266
|
+
|
267
|
+
last_item_end = result[2]
|
268
|
+
return :in_progress unless last_item_end
|
269
|
+
|
270
|
+
:complete
|
271
|
+
end
|
244
272
|
end
|
245
273
|
end
|
data/lib/timet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Vielma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- lib/timet/application_helper.rb
|
83
83
|
- lib/timet/color_codes.rb
|
84
84
|
- lib/timet/database.rb
|
85
|
-
- lib/timet/status_helper.rb
|
86
85
|
- lib/timet/table.rb
|
87
86
|
- lib/timet/tag_distribution.rb
|
88
87
|
- lib/timet/time_block_chart.rb
|
data/lib/timet/status_helper.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Timet
|
4
|
-
# Provides helper methods to determine the status of time tracking results.
|
5
|
-
module StatusHelper
|
6
|
-
# Determines the status of a time tracking result based on the presence and end time of items.
|
7
|
-
#
|
8
|
-
# @param result [Array] The result set containing time tracking items.
|
9
|
-
#
|
10
|
-
# @return [Symbol] The status of the time tracking result. Possible values are
|
11
|
-
# :no_items, :in_progress, or :complete.
|
12
|
-
#
|
13
|
-
# @example Determine the status of an empty result set
|
14
|
-
# StatusHelper.determine_status([]) # => :no_items
|
15
|
-
#
|
16
|
-
# @example Determine the status of a result set with an in-progress item
|
17
|
-
# StatusHelper.determine_status([[1, nil]]) # => :in_progress
|
18
|
-
#
|
19
|
-
# @example Determine the status of a result set with a completed item
|
20
|
-
# StatusHelper.determine_status([[1, 1633072800]]) # => :complete
|
21
|
-
#
|
22
|
-
# @note The method checks if the result set is empty and returns :no_items if true.
|
23
|
-
# @note If the last item in the result set has no end time, it returns :in_progress.
|
24
|
-
# @note If the last item in the result set has an end time, it returns :complete.
|
25
|
-
def self.determine_status(result)
|
26
|
-
return :no_items if result.empty?
|
27
|
-
|
28
|
-
last_item_end = result.first[1]
|
29
|
-
return :in_progress unless last_item_end
|
30
|
-
|
31
|
-
:complete
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|