piece_of_wax 1.0.0.rc2 → 1.0.0.rc3
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 +16 -2
- data/lib/piece_of_wax/logfile.rb +16 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400f7ba66635dd5870e0f49fc16119d8b8f83f8b747632a5db52493619728ea6
|
4
|
+
data.tar.gz: 51601a6e8cb56a882ff6e7c6245553ab15a1001be015445b43ca0ec6d7b1cd1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 968071d93fba4ee1da61c7c03b2954e196eebd480760378d9282474b38ec51e5811d617bbab18ce5725d3d1bca78ecb3b6bb2dcda229ca603fcded2051a81708
|
7
|
+
data.tar.gz: 8caa065e2e9a93b3fcc618ab6b7692345ba4911cc558dd1aaca43a787842dfce6a57e02175e689f3a53d71d2958a8ac08287d4f2c4574a329eae1b86ee015b24
|
data/lib/piece_of_wax.rb
CHANGED
@@ -11,18 +11,32 @@ module PieceOfWax
|
|
11
11
|
option :time, aliases: :t, desc: 'time when activity was started'
|
12
12
|
def activity(str)
|
13
13
|
CLIOptions.instance.set(options)
|
14
|
-
time = DateTime.safe_parse(
|
14
|
+
time = DateTime.safe_parse(CLIOptions.instance[:time]) || DateTime.current_time
|
15
15
|
Logfile.new(DateTime.current_date).add_activity(time, str)
|
16
16
|
$stdout.puts "wrote #{str} to file"
|
17
17
|
end
|
18
18
|
|
19
|
+
desc 'edit "_activity_"', "edit activity"
|
20
|
+
option :n, default: '1', desc: 'the activity to edit, 1 being the most recently-logged'
|
21
|
+
def edit(str)
|
22
|
+
CLIOptions.instance.set(options)
|
23
|
+
index = (0 - CLIOptions.instance[:n].to_i)
|
24
|
+
logfile = Logfile.new(DateTime.current_date)
|
25
|
+
if logfile.contents[index]
|
26
|
+
logfile.edit_activity(index, str)
|
27
|
+
$stdout.puts "wrote #{str} to file"
|
28
|
+
else
|
29
|
+
$stderr.puts 'activity referenced by "n" option does not exist'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
19
33
|
desc "read [date]", "print activities on given [date] (yesterday by default)"
|
20
34
|
option :military, aliases: :m, desc: 'render time in military (24-hour) format'
|
21
35
|
def read(date_str = '')
|
22
36
|
CLIOptions.instance.set(options)
|
23
37
|
date = DateTime.safe_parse(date_str) || DateTime.current_date
|
24
38
|
logfile = Logfile.new(date)
|
25
|
-
if logfile.
|
39
|
+
if logfile.any_contents?
|
26
40
|
$stdout.puts logfile
|
27
41
|
else
|
28
42
|
$stderr.puts "Sorry, I couldn't find any logs for #{DateTimeDecorator::ErrorMessageDisplay.new(date)}."
|
data/lib/piece_of_wax/logfile.rb
CHANGED
@@ -12,21 +12,25 @@ module PieceOfWax
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def contents
|
15
|
-
return unless raw_content = @file_io.read
|
15
|
+
return [] unless raw_content = @file_io.read
|
16
16
|
JSON.parse(raw_content)
|
17
17
|
end
|
18
18
|
|
19
|
+
def any_contents?
|
20
|
+
contents.any?
|
21
|
+
end
|
22
|
+
|
19
23
|
def add_activity(time, description)
|
20
|
-
data =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@file_io.overwrite_with(
|
24
|
+
data = { datetime: time, description: description }
|
25
|
+
index = proper_index(time)
|
26
|
+
json_str = contents.insert(index, data).to_json
|
27
|
+
@file_io.overwrite_with(json_str)
|
28
|
+
end
|
29
|
+
|
30
|
+
def edit_activity(index, description)
|
31
|
+
updated_contents = contents.tap { |c| c[index]['description'] = description }
|
32
|
+
json_str = updated_contents.to_json
|
33
|
+
@file_io.overwrite_with(json_str)
|
30
34
|
end
|
31
35
|
|
32
36
|
def to_s
|
@@ -50,7 +54,7 @@ module PieceOfWax
|
|
50
54
|
contents.each_with_index do |line, i|
|
51
55
|
return i if Time.parse(line['datetime']) > time
|
52
56
|
end
|
53
|
-
|
57
|
+
contents.length
|
54
58
|
end
|
55
59
|
|
56
60
|
def first_entry
|
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.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Stegeman
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 3.7
|
89
|
+
version: '3.7'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 3.7
|
96
|
+
version: '3.7'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: timecop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|