piece_of_wax 1.0.0.rc5 → 1.0.0.rc6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/piece_of_wax.rb +52 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fdf0186e07e8c9137374525a9befb04f41b30be7dbfe81e65c2d89775a171b2
4
- data.tar.gz: 475ee015973ef306855f15574fe82334c95ccbd9dd0a4925224d96a0595ca2ee
3
+ metadata.gz: 7e3d7bf2ae9792450cc94d927669b1d48e8c4abdde8285c7580532065372780c
4
+ data.tar.gz: a2728bf010e7a3be407291ed6bd037a1c45fee19f2813e2f3d103ceae87f6649
5
5
  SHA512:
6
- metadata.gz: e18a182873c378b85d385abec297c2041a640432a377e9e91d458f15abe2c2f4b63e03b235bbc343acc61806351f85687d9d762c783f7e2f594005a0669b8646
7
- data.tar.gz: 6441d89f22d93c54865c1e94f0398db26a4b6856f356699e77b8c599f92ba81dd22e897fd5443c74d307748915baa51f74fb35502376ef051742d00054151141
6
+ metadata.gz: 0165421b35cf5701533a15aba5d62f324ad575686588b6858336fcc9e21171b98103019191ba67bf6c512ffa8fc39604a3bbac496f3d810ae455772faeca82a6
7
+ data.tar.gz: 64cf7f4ddb03e81c714892e0381bbc948883185bbf0124e36a7fcdfec8ee34b90a3f0168aa2bddf69a5dea35b0b9614cceb442bc6ea34a280bdba4d7e92a6e7b
@@ -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
- CLIOptions.instance.set(options)
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
- CLIOptions.instance.set(options)
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
- CLIOptions.instance.set(options)
51
- date = DateTimeHelper.safe_parse(date_str) || DateTimeHelper.current_date
52
- logfile = Logfile.new(date)
53
- if logfile.any_contents?
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
- warn "Sorry, I couldn't find any logs for #{DateTimeDecorator::ErrorMessageDisplay.new(date)}."
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piece_of_wax
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc5
4
+ version: 1.0.0.rc6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Stegeman