timet 0.8.2 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5eda40ea4aafce60dc6fef1270ca9d013724c45b29ba43e7974b8212f55ac231
4
- data.tar.gz: b5a45e366bbfdb073ccf32ad545b572faac79f018c3a6f8eac60622aed96b02b
3
+ metadata.gz: 7b90eeedf6f1653e70f0d90fc2181ebeec88c3788bbc88dbcd072f5a6f2fe821
4
+ data.tar.gz: c2fbc67fd45bb9d3923a91f737f03fc2a74599193cbe932fbeaadbb44a2d21be
5
5
  SHA512:
6
- metadata.gz: 0d0cc2dfa64d2af724b2be8543d67f63f5485c4fe81746a29cea29db9b51d1ba5fcf4df98f7cdadb16961f30cd24dff0e65bef93c6f297fe9b61bc9a07b0e15e
7
- data.tar.gz: fdd6364f4dad16defed0c484eb29adf27479427387be6cd43587bcdbfb628eea2a99a0712c708a5821e50e1064c476b2481cd2efc49cb302d533b0d632c3f08a
6
+ metadata.gz: 475f77e1febf29ccdb1e17bfdd309a829b3d309d4d670afe95ede0926ab897173006ab89d165de4f87c3c3663c5114a08e54ada2f6835453fc4d99fb86134c62
7
+ data.tar.gz: ca865940ccafb9e60eb682d9085202e3946e1029f5df01b0ece8e998d9dcbe3746f1a196d4638e9a94cb587425198cba4fd93182e2934185d4e849407d34f81c
data/CHANGELOG.md CHANGED
@@ -1,23 +1,69 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.1] - 2024-10-04
4
+
5
+ **Improvements:**
6
+
7
+ - Added YARD documentation
8
+ - Refactored the `start` method to use `@db.insert_item` directly if the last item status is valid for insertion.
9
+ - Removed the `insert_item_if_valid` private method as it is no longer needed.
10
+ - Updated the README.md to reflect the latest changes and improvements.
11
+ - Added a badge displaying the current gem version in the README.md.
12
+
13
+ ## [0.9.0] - 2024-10-03
14
+
15
+ **Improvements:**
16
+
17
+ - Enhanced the gemspec metadata by adding a documentation URI for better discoverability and reference.
18
+ - Improved the `summary` and `edit` methods for better readability and functionality.
19
+ - Simplified the `summary` method by using safe navigation operators and improved conditional checks.
20
+ - Modified the `edit` method to use the return value of `validate_and_update` for displaying the updated item.
21
+ - Updated the `validate_and_update` method to return the updated item after performing the update.
22
+ - Enhanced the `TimeReport` class and added comprehensive RSpec tests.
23
+ - Enhanced the `filter_items` method to support valid date range filters.
24
+ - Added a `valid_date_format?` method to validate date formats.
25
+ - Updated the `formatted_filter` method to handle valid date range filters.
26
+ - Removed the `helpers.rb` file as it was no longer needed.
27
+ - Added comprehensive RSpec tests for the `TimeReport` class, covering initialization, filtering, and date format validation.
28
+ - Modified the `stop` method in `Timet::Application` to use the `update_item` method from `Database` instead of the deprecated `update` method.
29
+ - Updated the `stop` method to fetch the last item's ID and update the 'end' field directly.
30
+ - Updated test cases in `application_spec.rb` to reflect the changes in the `stop` method.
31
+ - Removed test cases for the deprecated `update` method in `database_spec.rb`.
32
+
33
+ **Bug fixes:**
34
+
35
+ - Fix bug in calculate_end_time method
36
+
37
+ **Additional Considerations:**
38
+
39
+ - The changes in this PR aim to improve code quality, maintainability, and test coverage.
40
+ - The removal of the `helpers.rb` file and unused methods helps to streamline the codebase and reduce technical debt.
41
+ - The updated `stop` method now uses the `update_item` method, ensuring consistency across the codebase.
42
+ - Comprehensive tests have been added for the `TimeReport` class to ensure robust functionality and prevent regressions.
43
+
3
44
  ## [0.8.2] - 2024-10-02
4
45
 
5
46
  **Improvements:**
47
+
6
48
  - Added optional field and new_value parameters to the edit command.
7
49
  - Updated the edit method logic to prompt for field and new_value if they are not provided.
8
50
  - Enhanced test coverage to include scenarios where field and new_value are provided directly and when they are not.
9
51
  - Updated the README to reflect the new features of the edit command, including both interactive and direct specification modes.
10
52
 
11
53
  **Additional Considerations:**
54
+
12
55
  - The changes ensure that the edit command is more versatile and user-friendly, catering to both interactive users and those who prefer scripting or automation.
13
56
 
14
57
  ## [0.8.1] - 2024-10-02
58
+
15
59
  **Bug fixes:**
16
- - Fixed a LoadError caused by the byebug gem being required after its removal.
60
+
61
+ - Fixed a LoadError caused by the byebug gem being required after its removal.
17
62
 
18
63
  ## [0.8.0] - 2024-10-01
19
64
 
20
65
  **Improvements:**
66
+
21
67
  - Introduced TimeHelper module to encapsulate time-related functionalities.
22
68
  - Replaced direct calls to Time.now.to_i with TimeHelper.current_timestamp for consistency and modularity.
23
69
  - Moved current_timestamp method to TimeHelper to centralize time-related logic.
@@ -50,6 +96,7 @@
50
96
  - Added a confirmation message when the CSV file is successfully exported.
51
97
 
52
98
  **Bug fixes:**
99
+
53
100
  - Updated timestamp_to_time method to return nil if the input timestamp is nil.
54
101
  - Removed unnecessary &.then syntax for clarity and consistency.
55
102
  - Corrected the test expectations to use the correct Unix timestamp.
@@ -61,6 +108,7 @@
61
108
  - Added validation to prevent updating start or end times with nil values.
62
109
 
63
110
  **Tasks:**
111
+
64
112
  - Added ENV['TZ'] = 'UTC' to spec_helper.rb to ensure that all RSpec tests run in the UTC time zone.
65
113
  - Updated tests to reflect the new structure and ensure items are returned for export.
66
114
  - Updated and added tests to cover the new export logic.
@@ -78,6 +126,7 @@
78
126
  - Updated database_spec.rb to reflect the correct status for in-progress items.
79
127
 
80
128
  **Additional Considerations:**
129
+
81
130
  - Ensured that all timestamps are handled in UTC to avoid timezone issues across different environments.
82
131
  - Updated the test to reflect the correct UTC time zone.
83
132
  - Ensured consistency in timestamp handling across methods.
@@ -85,6 +134,7 @@
85
134
  - Made the application easier to maintain and extend in the future.
86
135
 
87
136
  **Refactor and enhance time formatting methods**
137
+
88
138
  - Refactored `format_time_string` method in `TimeHelper` to improve readability and maintainability.
89
139
  - Added detailed documentation for the `format_time_string` method.
90
140
  - Simplified the logic for parsing and validating time components.
@@ -96,31 +146,30 @@
96
146
 
97
147
  ## [0.2.2] - 2024-09-27
98
148
 
99
- * **Improvements**:
100
- * Updated SQLite3 gem version to 2.1.0
149
+ - **Improvements**:
150
+ - Updated SQLite3 gem version to 2.1.0
101
151
 
102
152
  ## [0.2.1] - 2024-09-24
103
153
 
104
- * **Improved `resume` behavior:**
105
- * If no notes are provided, it will attempt to retrieve them from the last tracked task.
106
- * **Enhanced `export_sheet` functionality:**
107
- * A new `notes` column has been added to the exported CSV file.
108
- * **Minor bug fixes:**
109
- * Resolved issues related to resuming tasks with notes and deleting items.
110
-
154
+ - **Improved `resume` behavior:**
155
+ - If no notes are provided, it will attempt to retrieve them from the last tracked task.
156
+ - **Enhanced `export_sheet` functionality:**
157
+ - A new `notes` column has been added to the exported CSV file.
158
+ - **Minor bug fixes:**
159
+ - Resolved issues related to resuming tasks with notes and deleting items.
111
160
 
112
161
  ## [0.2.0] - 2024-09-24
113
162
 
114
- * **Improved code quality:**
115
- * Enforces consistent quoting style with `RuboCop` integration.
116
- * Removes unused gems (`mini_portile2`) from the `Gemfile`.
117
- * **Database enhancements:**
118
- * Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
119
- * **Command-line improvements:**
120
- * Allows adding notes to a new time entry using the `start` command with the `--notes` option (e.g., `timet start work --notes="meeting with client"`).
121
- * Improves formatting and clarity of some command descriptions.
122
- * **General code formatting:**
123
- * Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
163
+ - **Improved code quality:**
164
+ - Enforces consistent quoting style with `RuboCop` integration.
165
+ - Removes unused gems (`mini_portile2`) from the `Gemfile`.
166
+ - **Database enhancements:**
167
+ - Adds a new column named "notes" to the `items` table to store additional information about tracked time entries.
168
+ - **Command-line improvements:**
169
+ - Allows adding notes to a new time entry using the `start` command with the `--notes` option (e.g., `timet start work --notes="meeting with client"`).
170
+ - Improves formatting and clarity of some command descriptions.
171
+ - **General code formatting:**
172
+ - Uses single quotes (`'`) for strings and source paths in the `Gemfile`.
124
173
 
125
174
  ## [0.1.0] - 2024-08-01
126
175
 
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
+ [![Gem Version](https://badge.fury.io/rb/timet.svg)](https://badge.fury.io/rb/timet)
1
2
  ![timet workflow](https://github.com/frankvielma/timet/actions/workflows/ci.yml/badge.svg)
2
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/44d57b6c561b9be717f5/maintainability)](https://codeclimate.com/github/frankvielma/timet/maintainability)
3
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/44d57b6c561b9be717f5/test_coverage)](https://codeclimate.com/github/frankvielma/timet/test_coverage)
4
5
 
5
6
  # Timet
6
7
 
7
- Timet is a command line time tracking with reports. It's simple to track your hours for work with Timet, whether you're curious about how you allocate your time.
8
+ Timet refers to a command-line tool designed to track your activities by recording the time spent on each task, allowing you to monitor your work hours and productivity directly from your terminal without needing a graphical interface; essentially, it's a way to log your time spent on different projects or tasks using simple text commands
8
9
 
9
10
  Timet utilizes SQLite to store your time tracking data. This means your data is stored locally and securely, with no need for external databases or cloud storage. This makes Timet lightweight, fast, and perfect for users who value privacy and control over their data.
10
11
 
@@ -150,6 +151,24 @@ gem install timet
150
151
  | `timet delete [id]` | Delete a task by its ID. | `timet d [id]` |
151
152
  | `timet cancel` | Cancel active time tracking. | `timet c` |
152
153
  | `timet edit [id]` | Update a task's notes, tag, start or end fields. | `timet e [1]` |
154
+ | `timet su [date]` | Display a report of tracked time for a specific date. | `timet su 2024-01-03` |
155
+ | `timet su [start_date]..[end_date]` | Display a report of tracked time for a date range. | `timet su 2024-01-02..2024-01-03` |
156
+
157
+
158
+ ### Date Range in Summary
159
+
160
+ The `timet summary` command now supports specifying a date range for generating reports. This allows users to filter and summarize data within specific date intervals. The date format is in ISO 8601 format (YYYY-MM-DD).
161
+
162
+ #### Examples:
163
+ - **Single Date**: Display a report for a specific date.
164
+ ```sh
165
+ timet su 2024-01-03
166
+ ```
167
+
168
+ - **Date Range**: Display a report for a date range.
169
+ ```sh
170
+ timet su 2024-01-02..2024-01-03
171
+ ```
153
172
 
154
173
 
155
174
  ## Data
@@ -19,10 +19,11 @@ module Timet
19
19
  class Application < Thor
20
20
  include ValidationEditHelper
21
21
  include ApplicationHelper
22
+ include TimeHelper
22
23
 
23
24
  def initialize(*args)
24
25
  super
25
- @db = Timet::Database.new
26
+ @db = Database.new
26
27
  end
27
28
 
28
29
  FIELD_INDEX = {
@@ -34,20 +35,47 @@ module Timet
34
35
 
35
36
  VALID_STATUSES_FOR_INSERTION = %i[no_items complete].freeze
36
37
 
37
- desc "start [tag] --notes='...'", "start time tracking --notes='my notes...'"
38
+ desc "start [tag] --notes=''", "start time tracking --notes='my notes...'"
38
39
  option :notes, type: :string, desc: 'Add a note'
40
+ # Starts a new tracking session with the given tag and optional notes.
41
+ #
42
+ # @param tag [String] The tag associated with the tracking session. This is a required parameter.
43
+ # @param notes [String, nil] Optional notes to be associated with the tracking session. If not provided, it defaults to the value in `options[:notes]`.
44
+ #
45
+ # @return [void] This method does not return a value; it performs side effects such as inserting a tracking item and generating a summary.
46
+ #
47
+ # @example Start a tracking session with a tag and notes
48
+ # start('work', 'Starting work on project X')
49
+ #
50
+ # @example Start a tracking session with only a tag
51
+ # start('break')
52
+ #
53
+ # @note The method uses `TimeHelper.current_timestamp` to get the current timestamp for the start time.
54
+ # @note The method calls `summary` to generate a summary after inserting the tracking item.
39
55
  def start(tag, notes = nil)
40
56
  start_time = TimeHelper.current_timestamp
41
57
  notes = options[:notes] || notes
42
58
 
43
- insert_item_if_valid(start_time, tag, notes)
59
+ @db.insert_item(start_time, tag, notes) if VALID_STATUSES_FOR_INSERTION.include?(@db.last_item_status)
44
60
  summary
45
61
  end
46
62
 
47
63
  desc 'stop', 'stop time tracking'
64
+ # Stops the current tracking session if there is one in progress.
65
+ #
66
+ # @return [void] This method does not return a value; it performs side effects such as updating the tracking item and generating a summary.
67
+ #
68
+ # @example Stop the current tracking session
69
+ # stop
70
+ #
71
+ # @note The method checks if the last tracking item is in progress by calling `@db.last_item_status`.
72
+ # @note If the last item is in progress, it fetches the last item's ID using `@db.fetch_last_id` and updates it with the current timestamp.
73
+ # @note The method then fetches the last item using `@db.last_item` and generates a summary if the result is not nil.
48
74
  def stop
49
- stop = TimeHelper.current_timestamp
50
- @db.update(stop) if @db.last_item_status == :in_progress
75
+ if @db.last_item_status == :in_progress
76
+ last_id = @db.fetch_last_id
77
+ @db.update_item(last_id, 'end', TimeHelper.current_timestamp)
78
+ end
51
79
  result = @db.last_item
52
80
 
53
81
  return unless result
@@ -56,6 +84,16 @@ module Timet
56
84
  end
57
85
 
58
86
  desc 'resume (r)', 'resume last task'
87
+ # Resumes the last tracking session if it was completed.
88
+ #
89
+ # @return [void] This method does not return a value; it performs side effects such as resuming a tracking session or providing feedback.
90
+ #
91
+ # @example Resume the last tracking session
92
+ # resume
93
+ #
94
+ # @note The method checks the status of the last tracking item using `@db.last_item_status`.
95
+ # @note If the last item is in progress, it prints a message indicating that a task is currently being tracked.
96
+ # @note If the last item is complete, it fetches the last item using `@db.last_item`, retrieves the tag and notes, and calls the `start` method to resume the tracking session.
59
97
  def resume
60
98
  status = @db.last_item_status
61
99
 
@@ -73,22 +111,62 @@ module Timet
73
111
  end
74
112
 
75
113
  desc 'summary (su) [filter] [tag] --csv=csv_filename',
76
- "Display a summary of tracked time filter => [today (t), yesterday (y), week (w), month (m)] [tag]
77
- and export to csv_filename"
114
+ ' [filter] => [today (t), yesterday (y), week (w), month (m), [start_date]..[end_date]] [tag]'
78
115
  option :csv, type: :string, desc: 'Export to CSV file'
116
+ # Generates a summary of tracking items based on the provided filter and tag, and optionally exports the summary to a CSV file.
117
+ #
118
+ # @param filter [String, nil] The filter to apply when generating the summary. Possible values include 'today', 'yesterday', 'week', 'month', or a date range in the format '[start_date]..[end_date]'.
119
+ # @param tag [String, nil] The tag to filter the tracking items by.
120
+ #
121
+ # @return [void] This method does not return a value; it performs side effects such as displaying the summary and exporting to CSV if specified.
122
+ #
123
+ # @example Generate a summary for today
124
+ # summary('today')
125
+ #
126
+ # @example Generate a summary for a specific tag
127
+ # summary(nil, 'work')
128
+ #
129
+ # @example Generate a summary for a date range and export to CSV
130
+ # summary('2023-01-01..2023-01-31', nil, csv: 'summary.csv')
131
+ #
132
+ # @note The method initializes a `TimeReport` object with the database, filter, tag, and optional CSV filename.
133
+ # @note The method calls `display` on the `TimeReport` object to show the summary.
134
+ # @note If a CSV filename is provided and there are items to export, the method calls `export_sheet` to export the summary to a CSV file.
135
+ # @note If no items are found to export, it prints a message indicating that no items were found.
79
136
  def summary(filter = nil, tag = nil)
80
- csv_filename = options[:csv].split('.')[0] if options[:csv]
137
+ csv_filename = options[:csv]&.split('.')&.first
81
138
  summary = TimeReport.new(@db, filter, tag, csv_filename)
139
+
82
140
  summary.display
83
- if csv_filename && summary.items.any?
141
+ items = summary.items
142
+ if csv_filename && items.any?
84
143
  summary.export_sheet
85
- elsif summary.items.empty?
144
+ elsif items.empty?
86
145
  puts 'No items found to export'
87
146
  end
88
147
  end
89
148
 
90
149
  desc 'edit (e) [id] [field] [value]',
91
150
  'edit a task, [field] (notes, tag, start or end) and [value] are optional parameters'
151
+ # Edits a specific tracking item by its ID, allowing the user to modify fields such as notes, tag, start time, or end time.
152
+ #
153
+ # @param id [Integer] The ID of the tracking item to be edited.
154
+ # @param field [String, nil] The field to be edited. Possible values include 'notes', 'tag', 'start', or 'end'. If not provided, the user will be prompted to select a field.
155
+ # @param new_value [String, nil] The new value to be set for the specified field. If not provided, the user will be prompted to enter a new value.
156
+ #
157
+ # @return [void] This method does not return a value; it performs side effects such as updating the tracking item and displaying the updated item.
158
+ #
159
+ # @example Edit the notes of a tracking item with ID 1
160
+ # edit(1, 'notes', 'Updated notes')
161
+ #
162
+ # @example Edit a tracking item with ID 2, prompting for the field and new value
163
+ # edit(2)
164
+ #
165
+ # @note The method first attempts to find the tracking item by its ID using `@db.find_item(id)`.
166
+ # @note If the item is found, it displays the current item details using `display_item(item)`.
167
+ # @note If the field or new value is not provided, the user is prompted to select a field to edit and enter a new value.
168
+ # @note The method then validates and updates the item using `validate_and_update(item, field, new_value)`.
169
+ # @note Finally, it displays the updated item details using `display_item(updated_item)`.
92
170
  def edit(id, field = nil, new_value = nil)
93
171
  item = @db.find_item(id)
94
172
  return puts "No tracked time found for id: #{id}" unless item
@@ -99,12 +177,24 @@ module Timet
99
177
  new_value = prompt_for_new_value(item, field)
100
178
  end
101
179
 
102
- validate_and_update(item, field, new_value)
103
-
104
- summary.display
180
+ updated_item = validate_and_update(item, field, new_value)
181
+ display_item(updated_item)
105
182
  end
106
183
 
107
184
  desc 'delete (d) [id]', 'delete a task'
185
+ # Deletes a specific tracking item by its ID after confirming with the user.
186
+ #
187
+ # @param id [Integer] The ID of the tracking item to be deleted.
188
+ #
189
+ # @return [void] This method does not return a value; it performs side effects such as deleting the tracking item and displaying a confirmation message.
190
+ #
191
+ # @example Delete a tracking item with ID 1
192
+ # delete(1)
193
+ #
194
+ # @note The method first attempts to find the tracking item by its ID using `@db.find_item(id)`.
195
+ # @note If the item is found, it displays the item details using `TimeReport.new(@db).show_row(item)`.
196
+ # @note The method then prompts the user for confirmation using `TTY::Prompt.new.yes?('Are you sure you want to delete this entry?')`.
197
+ # @note If the user confirms, the method deletes the item and prints a confirmation message using `delete_item_and_print_message(id, "Deleted #{id}")`.
108
198
  def delete(id)
109
199
  item = @db.find_item(id)
110
200
  return puts "No tracked time found for id: #{id}" unless item
@@ -116,6 +206,17 @@ module Timet
116
206
  end
117
207
 
118
208
  desc 'cancel (c)', 'cancel active time tracking'
209
+ # Cancels the active time tracking session by deleting the last tracking item.
210
+ #
211
+ # @return [void] This method does not return a value; it performs side effects such as deleting the active tracking item and displaying a confirmation message.
212
+ #
213
+ # @example Cancel the active time tracking session
214
+ # cancel
215
+ #
216
+ # @note The method fetches the ID of the last tracking item using `@db.fetch_last_id`.
217
+ # @note It checks if the last item is in progress by comparing `@db.last_item_status` with `:complete`.
218
+ # @note If the last item is in progress, it deletes the item and prints a confirmation message using `delete_item_and_print_message(id, "Canceled active time tracking #{id}")`.
219
+ # @note If there is no active time tracking, it prints a message indicating that there is no active time tracking.
119
220
  def cancel
120
221
  id = @db.fetch_last_id
121
222
  return puts 'There is no active time tracking' if @db.last_item_status == :complete
@@ -123,18 +224,33 @@ module Timet
123
224
  delete_item_and_print_message(id, "Canceled active time tracking #{id}")
124
225
  end
125
226
 
227
+ # Determines whether the application should exit when a command fails.
228
+ #
229
+ # @return [Boolean] Returns `true`, indicating that the application should exit when a command fails.
230
+ #
231
+ # @example Check if the application should exit on failure
232
+ # MyClass.exit_on_failure? # => true
233
+ #
234
+ # @note This method is typically used in command-line applications to control the behavior when a command fails.
235
+ # @note Returning `true` means that the application will exit immediately if a command fails, which is useful for ensuring that errors are handled gracefully.
126
236
  def self.exit_on_failure?
127
237
  true
128
238
  end
129
239
 
130
240
  private
131
241
 
132
- def insert_item_if_valid(start_time, tag, notes)
133
- return unless VALID_STATUSES_FOR_INSERTION.include?(@db.last_item_status)
134
-
135
- @db.insert_item(start_time, tag, notes)
136
- end
137
-
242
+ # Deletes a tracking item from the database by its ID and prints a confirmation message.
243
+ #
244
+ # @param id [Integer] The ID of the tracking item to be deleted.
245
+ # @param message [String] The message to be printed after the item is deleted.
246
+ #
247
+ # @return [void] This method does not return a value; it performs side effects such as deleting the tracking item and printing a message.
248
+ #
249
+ # @example Delete a tracking item with ID 1 and print a confirmation message
250
+ # delete_item_and_print_message(1, 'Deleted item 1')
251
+ #
252
+ # @note The method deletes the tracking item from the database using `@db.delete_item(id)`.
253
+ # @note After deleting the item, the method prints the provided message using `puts message`.
138
254
  def delete_item_and_print_message(id, message)
139
255
  @db.delete_item(id)
140
256
  puts message
@@ -3,21 +3,64 @@
3
3
  module Timet
4
4
  # Provides helper methods for the Timet application.
5
5
  module ApplicationHelper
6
+ # Displays the details of a tracking item.
7
+ #
8
+ # @param item [Hash] The tracking item to be displayed.
9
+ #
10
+ # @return [void] This method does not return a value; it performs side effects such as displaying the item details.
11
+ #
12
+ # @example Display the details of a tracking item
13
+ # display_item(item)
14
+ #
15
+ # @note The method initializes a `TimeReport` object with the database and calls `show_row` to display the item details.
6
16
  def display_item(item)
7
17
  TimeReport.new(@db).show_row(item)
8
18
  end
9
19
 
20
+ # Prompts the user to enter a new value for a specific field of a tracking item.
21
+ #
22
+ # @param item [Hash] The tracking item to be edited.
23
+ # @param field [String] The field to be updated.
24
+ #
25
+ # @return [String] The new value entered by the user.
26
+ #
27
+ # @example Prompt for a new value for the 'notes' field
28
+ # prompt_for_new_value(item, 'notes')
29
+ #
30
+ # @note The method retrieves the current value of the field using `field_value`.
31
+ # @note The method uses `TTY::Prompt.new` to prompt the user for a new value, displaying the current value in the prompt.
10
32
  def prompt_for_new_value(item, field)
11
33
  current_value = field_value(item, field)
12
34
  prompt = TTY::Prompt.new(active_color: :green)
13
35
  prompt.ask("Update #{field} (#{current_value}):")
14
36
  end
15
37
 
38
+ # Prompts the user to select a field to edit from a list of available fields.
39
+ #
40
+ # @return [String] The selected field in lowercase.
41
+ #
42
+ # @example Prompt for a field to edit
43
+ # select_field_to_edit
44
+ #
45
+ # @note The method uses `TTY::Prompt.new` to display a list of available fields for the user to select from.
46
+ # @note The method returns the selected field in lowercase.
16
47
  def select_field_to_edit
17
48
  prompt = TTY::Prompt.new(active_color: :green)
18
49
  prompt.select('Edit Field?', Timet::Application::FIELD_INDEX.keys.map(&:capitalize), active_color: :cyan).downcase
19
50
  end
20
51
 
52
+ # Retrieves the value of a specific field from a tracking item.
53
+ #
54
+ # @param item [Hash] The tracking item.
55
+ # @param field [String] The field to retrieve the value for.
56
+ #
57
+ # @return [String, Time] The value of the specified field. If the field is 'start' or 'end', it returns the value as a Time object.
58
+ #
59
+ # @example Retrieve the value of the 'notes' field
60
+ # field_value(item, 'notes')
61
+ #
62
+ # @note The method retrieves the index of the field from `Timet::Application::FIELD_INDEX`.
63
+ # @note If the field is 'start' or 'end', the method converts the value to a Time object using `TimeHelper.timestamp_to_time`.
21
64
  def field_value(item, field)
22
65
  index = Timet::Application::FIELD_INDEX[field]
23
66
  value = item[index]