piece_of_wax 1.0.0.rc5 → 1.0.0.rc6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/piece_of_wax.rb +52 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e3d7bf2ae9792450cc94d927669b1d48e8c4abdde8285c7580532065372780c
|
4
|
+
data.tar.gz: a2728bf010e7a3be407291ed6bd037a1c45fee19f2813e2f3d103ceae87f6649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0165421b35cf5701533a15aba5d62f324ad575686588b6858336fcc9e21171b98103019191ba67bf6c512ffa8fc39604a3bbac496f3d810ae455772faeca82a6
|
7
|
+
data.tar.gz: 64cf7f4ddb03e81c714892e0381bbc948883185bbf0124e36a7fcdfec8ee34b90a3f0168aa2bddf69a5dea35b0b9614cceb442bc6ea34a280bdba4d7e92a6e7b
|
data/lib/piece_of_wax.rb
CHANGED
@@ -16,7 +16,7 @@ module PieceOfWax
|
|
16
16
|
desc 'activity "_activity_"', "log activity"
|
17
17
|
option :time, aliases: :t, desc: "time when activity was started"
|
18
18
|
def activity(*str)
|
19
|
-
|
19
|
+
capture_options(options)
|
20
20
|
time = DateTimeHelper.safe_parse(CLIOptions.instance[:time]) || DateTimeHelper.current_time
|
21
21
|
description = str.join(" ")
|
22
22
|
Logfile.new(DateTimeHelper.current_date).add_activity(time, description)
|
@@ -26,7 +26,7 @@ module PieceOfWax
|
|
26
26
|
desc 'edit "_activity_"', "edit activity"
|
27
27
|
option :n, default: "1", desc: "the activity to edit, 1 being the most recently-logged"
|
28
28
|
def edit(*str)
|
29
|
-
|
29
|
+
capture_options(options)
|
30
30
|
description = str.join(" ")
|
31
31
|
index = (0 - CLIOptions.instance[:n].to_i)
|
32
32
|
logfile = Logfile.new(DateTimeHelper.current_date)
|
@@ -47,20 +47,65 @@ module PieceOfWax
|
|
47
47
|
desc: "last activity period is capped off at this time"
|
48
48
|
)
|
49
49
|
def read(date_str = "")
|
50
|
-
|
51
|
-
date =
|
52
|
-
logfile = Logfile.new(date)
|
53
|
-
if logfile
|
50
|
+
capture_options(options)
|
51
|
+
date = get_date(date_str)
|
52
|
+
logfile = Logfile.new(date) if date
|
53
|
+
if logfile&.any_contents?
|
54
54
|
$stdout.puts logfile
|
55
55
|
else
|
56
|
-
|
56
|
+
error_message(date_str, date)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
+
def capture_options(options)
|
63
|
+
CLIOptions.instance.set(options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_date(date_str)
|
67
|
+
if date_str == "previous"
|
68
|
+
previous_logfile_date
|
69
|
+
else
|
70
|
+
DateTimeHelper.safe_parse(date_str) || DateTimeHelper.current_date
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def error_message(date_str, date)
|
75
|
+
if date_str == "previous" && date.nil?
|
76
|
+
warn(
|
77
|
+
"Sorry, I couldn't find any logs prior to "\
|
78
|
+
"#{DateTimeDecorator::ErrorMessageDisplay.new(DateTimeHelper.current_date)}."
|
79
|
+
)
|
80
|
+
else
|
81
|
+
warn "Sorry, I couldn't find any logs for #{DateTimeDecorator::ErrorMessageDisplay.new(date)}."
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
62
85
|
def exit_on_failure?
|
63
86
|
true
|
64
87
|
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# @return [Logfile] most recent logfile (excluding current date)
|
91
|
+
#
|
92
|
+
# rubocop:disable Metrics/MethodLength
|
93
|
+
def previous_logfile_date
|
94
|
+
# rubocop:enable Metrics/MethodLength
|
95
|
+
logfile_dates =
|
96
|
+
Dir.entries(".").map do |filename|
|
97
|
+
date = filename.gsub(".txt", "")
|
98
|
+
DateTimeHelper.safe_parse(date)
|
99
|
+
end.compact
|
100
|
+
most_recent_date, second_most_recent_date =
|
101
|
+
logfile_dates.sort.reverse.first(2)
|
102
|
+
# if most recent logfile is from today, return the
|
103
|
+
# second most recent
|
104
|
+
if most_recent_date&.to_date == Date.today
|
105
|
+
second_most_recent_date
|
106
|
+
else
|
107
|
+
most_recent_date
|
108
|
+
end
|
109
|
+
end
|
65
110
|
end
|
66
111
|
end
|