piece_of_wax 1.0.0.rc4 → 1.0.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/piece_of_wax +2 -1
- data/lib/piece_of_wax.rb +25 -14
- data/lib/piece_of_wax/cli_options.rb +10 -3
- data/lib/piece_of_wax/date_time_decorator/error_message_display.rb +13 -5
- data/lib/piece_of_wax/date_time_decorator/read_display.rb +8 -2
- data/lib/piece_of_wax/{date_time.rb → date_time_helper.rb} +9 -4
- data/lib/piece_of_wax/file_io.rb +8 -5
- data/lib/piece_of_wax/logfile.rb +17 -9
- data/lib/piece_of_wax/output_line/activity.rb +9 -3
- data/lib/piece_of_wax/output_line/date.rb +9 -3
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fdf0186e07e8c9137374525a9befb04f41b30be7dbfe81e65c2d89775a171b2
|
4
|
+
data.tar.gz: 475ee015973ef306855f15574fe82334c95ccbd9dd0a4925224d96a0595ca2ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e18a182873c378b85d385abec297c2041a640432a377e9e91d458f15abe2c2f4b63e03b235bbc343acc61806351f85687d9d762c783f7e2f594005a0669b8646
|
7
|
+
data.tar.gz: 6441d89f22d93c54865c1e94f0398db26a4b6856f356699e77b8c599f92ba81dd22e897fd5443c74d307748915baa51f74fb35502376ef051742d00054151141
|
data/bin/piece_of_wax
CHANGED
data/lib/piece_of_wax.rb
CHANGED
@@ -1,48 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "json"
|
2
4
|
require "piece_of_wax/cli_options"
|
3
|
-
require "piece_of_wax/
|
5
|
+
require "piece_of_wax/date_time_helper"
|
4
6
|
require "piece_of_wax/date_time_decorator/error_message_display"
|
5
7
|
require "piece_of_wax/logfile"
|
6
8
|
require "thor"
|
7
9
|
|
8
10
|
module PieceOfWax
|
11
|
+
#
|
12
|
+
# Implements command line interface. Each public method corresponds to a `piece_of_wax`
|
13
|
+
# subcommand.
|
14
|
+
#
|
9
15
|
class CLI < Thor
|
10
16
|
desc 'activity "_activity_"', "log activity"
|
11
|
-
option :time, aliases: :t, desc:
|
17
|
+
option :time, aliases: :t, desc: "time when activity was started"
|
12
18
|
def activity(*str)
|
13
19
|
CLIOptions.instance.set(options)
|
14
|
-
time =
|
15
|
-
description = str.join(
|
16
|
-
Logfile.new(
|
20
|
+
time = DateTimeHelper.safe_parse(CLIOptions.instance[:time]) || DateTimeHelper.current_time
|
21
|
+
description = str.join(" ")
|
22
|
+
Logfile.new(DateTimeHelper.current_date).add_activity(time, description)
|
17
23
|
$stdout.puts "wrote #{description} to file"
|
18
24
|
end
|
19
25
|
|
20
26
|
desc 'edit "_activity_"', "edit activity"
|
21
|
-
option :n, default:
|
27
|
+
option :n, default: "1", desc: "the activity to edit, 1 being the most recently-logged"
|
22
28
|
def edit(*str)
|
23
29
|
CLIOptions.instance.set(options)
|
24
|
-
description = str.join(
|
30
|
+
description = str.join(" ")
|
25
31
|
index = (0 - CLIOptions.instance[:n].to_i)
|
26
|
-
logfile = Logfile.new(
|
32
|
+
logfile = Logfile.new(DateTimeHelper.current_date)
|
27
33
|
if logfile.contents[index]
|
28
34
|
logfile.edit_activity(index, description)
|
29
35
|
$stdout.puts "wrote #{description} to file"
|
30
36
|
else
|
31
|
-
|
37
|
+
warn 'activity referenced by "n" option does not exist'
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
35
41
|
desc "read [date]", "print activities on given [date] (today by default)"
|
36
|
-
option :military, aliases: :m, desc:
|
37
|
-
option
|
38
|
-
|
42
|
+
option :military, aliases: :m, desc: "render time in military (24-hour) format"
|
43
|
+
option(
|
44
|
+
:'quitting-time',
|
45
|
+
default: "17:45:00 -0500",
|
46
|
+
aliases: :q,
|
47
|
+
desc: "last activity period is capped off at this time"
|
48
|
+
)
|
49
|
+
def read(date_str = "")
|
39
50
|
CLIOptions.instance.set(options)
|
40
|
-
date =
|
51
|
+
date = DateTimeHelper.safe_parse(date_str) || DateTimeHelper.current_date
|
41
52
|
logfile = Logfile.new(date)
|
42
53
|
if logfile.any_contents?
|
43
54
|
$stdout.puts logfile
|
44
55
|
else
|
45
|
-
|
56
|
+
warn "Sorry, I couldn't find any logs for #{DateTimeDecorator::ErrorMessageDisplay.new(date)}."
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
@@ -1,7 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "singleton"
|
3
5
|
|
4
6
|
module PieceOfWax
|
7
|
+
#
|
8
|
+
# Singleton class that stores options/flags passed from the command line. Purpose
|
9
|
+
# of the class is to make these options globally available.
|
10
|
+
#
|
5
11
|
class CLIOptions
|
6
12
|
include Singleton
|
7
13
|
extend Forwardable
|
@@ -11,7 +17,8 @@ module PieceOfWax
|
|
11
17
|
end
|
12
18
|
|
13
19
|
def set(opts)
|
14
|
-
|
20
|
+
raise "CLIOptions is an immutable singleton; #set can only be called once per program execution" if options.any?
|
21
|
+
|
15
22
|
@options = opts
|
16
23
|
end
|
17
24
|
|
@@ -1,5 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "piece_of_wax/date_time"
|
4
|
+
|
1
5
|
module PieceOfWax
|
2
6
|
module DateTimeDecorator
|
7
|
+
#
|
8
|
+
# Decorator class designed to wrap DateTime instances. Implements form of to_s used
|
9
|
+
# to render error messages.
|
10
|
+
#
|
3
11
|
class ErrorMessageDisplay
|
4
12
|
def initialize(date_time)
|
5
13
|
@date_time = date_time
|
@@ -7,12 +15,12 @@ module PieceOfWax
|
|
7
15
|
|
8
16
|
def to_s
|
9
17
|
case @date_time.to_date
|
10
|
-
when
|
11
|
-
|
12
|
-
when
|
13
|
-
|
18
|
+
when DateTimeHelper.current_date
|
19
|
+
"today"
|
20
|
+
when DateTimeHelper.current_date.prev_day
|
21
|
+
"yesterday"
|
14
22
|
else
|
15
|
-
@date_time.strftime(
|
23
|
+
@date_time.strftime("%Y-%-m-%-d")
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
@@ -1,5 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PieceOfWax
|
2
4
|
module DateTimeDecorator
|
5
|
+
#
|
6
|
+
# Decorator class designed to wrap DateTime instances. Implements form of to_s used
|
7
|
+
# to render times in output of `read` subcommand.
|
8
|
+
#
|
3
9
|
class ReadDisplay
|
4
10
|
def initialize(date_time)
|
5
11
|
@date_time = date_time
|
@@ -7,9 +13,9 @@ module PieceOfWax
|
|
7
13
|
|
8
14
|
def to_s
|
9
15
|
if CLIOptions.instance[:military]
|
10
|
-
@date_time.strftime(
|
16
|
+
@date_time.strftime("%H:%M")
|
11
17
|
else
|
12
|
-
@date_time.strftime(
|
18
|
+
@date_time.strftime("%I:%M %p")
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
@@ -1,13 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "piece_of_wax/cli_options"
|
4
|
+
require "time"
|
3
5
|
|
4
6
|
module PieceOfWax
|
5
|
-
|
7
|
+
#
|
8
|
+
# Implements helper methods related to Date/Time
|
9
|
+
#
|
10
|
+
module DateTimeHelper
|
6
11
|
def self.safe_parse(arg)
|
7
12
|
# NOTE: calling to_s so method is safe for non-string args
|
8
13
|
str = arg.to_s
|
9
14
|
begin
|
10
|
-
parse(str)
|
15
|
+
Time.parse(str)
|
11
16
|
rescue ArgumentError
|
12
17
|
nil
|
13
18
|
end
|
data/lib/piece_of_wax/file_io.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module PieceOfWax
|
4
|
+
#
|
5
|
+
# A FileIO instance represents a file. Abstracts reading from and writing to the file system.
|
6
|
+
#
|
2
7
|
class FileIO
|
3
8
|
def initialize(filename)
|
4
9
|
@filename = filename
|
5
10
|
end
|
6
11
|
|
7
12
|
def read
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
nil
|
12
|
-
end
|
13
|
+
File.read(@filename)
|
14
|
+
rescue Errno::ENOENT
|
15
|
+
nil
|
13
16
|
end
|
14
17
|
|
15
18
|
def overwrite_with(str)
|
data/lib/piece_of_wax/logfile.rb
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "erb"
|
4
|
+
require "json"
|
5
|
+
require "piece_of_wax/file_io"
|
6
|
+
require "piece_of_wax/output_line/activity"
|
7
|
+
require "piece_of_wax/output_line/date"
|
6
8
|
|
7
9
|
module PieceOfWax
|
10
|
+
#
|
11
|
+
# A Logfile instance represents a specific type of file used by piece_of_wax to
|
12
|
+
# store logged time (a "time log.") A time log stores information for a single day,
|
13
|
+
# which is why a date must be passed to the Logfile constructor.
|
14
|
+
#
|
8
15
|
class Logfile
|
9
16
|
def initialize(date)
|
10
|
-
filename = "%s.txt"
|
17
|
+
filename = format("%s.txt", date.strftime("%y%m%d"))
|
11
18
|
@file_io = FileIO.new(filename)
|
12
19
|
end
|
13
20
|
|
14
21
|
def contents
|
15
|
-
return [] unless raw_content = @file_io.read
|
22
|
+
return [] unless (raw_content = @file_io.read)
|
23
|
+
|
16
24
|
JSON.parse(raw_content)
|
17
25
|
end
|
18
26
|
|
@@ -28,7 +36,7 @@ module PieceOfWax
|
|
28
36
|
end
|
29
37
|
|
30
38
|
def edit_activity(index, description)
|
31
|
-
updated_contents = contents.tap { |c| c[index][
|
39
|
+
updated_contents = contents.tap { |c| c[index]["description"] = description }
|
32
40
|
json_str = updated_contents.to_json
|
33
41
|
@file_io.overwrite_with(json_str)
|
34
42
|
end
|
@@ -52,7 +60,7 @@ module PieceOfWax
|
|
52
60
|
|
53
61
|
def proper_index(time)
|
54
62
|
contents.each_with_index do |line, i|
|
55
|
-
return i if Time.parse(line[
|
63
|
+
return i if Time.parse(line["datetime"]) > time
|
56
64
|
end
|
57
65
|
contents.length
|
58
66
|
end
|
@@ -1,12 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "piece_of_wax/date_time_helper"
|
2
4
|
require "piece_of_wax/date_time_decorator/read_display"
|
3
5
|
|
4
6
|
module PieceOfWax
|
5
7
|
module OutputLine
|
8
|
+
#
|
9
|
+
# An Activity instance represents a single logged activity, rendered as a line of
|
10
|
+
# `read` subcommand output.
|
11
|
+
#
|
6
12
|
class Activity
|
7
13
|
def initialize(start_time_str, end_time_str, description)
|
8
|
-
@start_time = DateTimeDecorator::ReadDisplay.new(
|
9
|
-
@end_time = DateTimeDecorator::ReadDisplay.new(
|
14
|
+
@start_time = DateTimeDecorator::ReadDisplay.new(DateTimeHelper.safe_parse(start_time_str))
|
15
|
+
@end_time = DateTimeDecorator::ReadDisplay.new(DateTimeHelper.safe_parse(end_time_str))
|
10
16
|
@description = description
|
11
17
|
end
|
12
18
|
|
@@ -1,14 +1,20 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "piece_of_wax/date_time_helper"
|
2
4
|
|
3
5
|
module PieceOfWax
|
4
6
|
module OutputLine
|
7
|
+
#
|
8
|
+
# A Date instance represents the date of a time log (see Logfile,) rendered as a line of
|
9
|
+
# `read` subcommand output.
|
10
|
+
#
|
5
11
|
class Date
|
6
12
|
def initialize(datetime_str)
|
7
|
-
@date =
|
13
|
+
@date = DateTimeHelper.safe_parse(datetime_str)
|
8
14
|
end
|
9
15
|
|
10
16
|
def to_s
|
11
|
-
@date.strftime(
|
17
|
+
@date.strftime("%-m/%-d/%y")
|
12
18
|
end
|
13
19
|
end
|
14
20
|
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.
|
4
|
+
version: 1.0.0.rc5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Stegeman
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: overcommit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.55.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.55.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pry
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,19 +109,19 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3.7'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rubocop
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
117
|
+
version: 0.88.0
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
124
|
+
version: 0.88.0
|
111
125
|
description: ''
|
112
126
|
email: bstegeman17@gmail.com
|
113
127
|
executables:
|
@@ -118,9 +132,9 @@ files:
|
|
118
132
|
- bin/piece_of_wax
|
119
133
|
- lib/piece_of_wax.rb
|
120
134
|
- lib/piece_of_wax/cli_options.rb
|
121
|
-
- lib/piece_of_wax/date_time.rb
|
122
135
|
- lib/piece_of_wax/date_time_decorator/error_message_display.rb
|
123
136
|
- lib/piece_of_wax/date_time_decorator/read_display.rb
|
137
|
+
- lib/piece_of_wax/date_time_helper.rb
|
124
138
|
- lib/piece_of_wax/file_io.rb
|
125
139
|
- lib/piece_of_wax/logfile.rb
|
126
140
|
- lib/piece_of_wax/output_line/activity.rb
|