piece_of_wax 1.0.0.rc2 → 1.0.0.rc3

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: a74b9ba7e24019636d06f341969473045ebf87fabd886800556fb90993865061
4
- data.tar.gz: 0520f53b6c20f6cf5531dda22c64caa663a7d7d339b445d66d31fdac69e69dcf
3
+ metadata.gz: 400f7ba66635dd5870e0f49fc16119d8b8f83f8b747632a5db52493619728ea6
4
+ data.tar.gz: 51601a6e8cb56a882ff6e7c6245553ab15a1001be015445b43ca0ec6d7b1cd1a
5
5
  SHA512:
6
- metadata.gz: 9a657cfce298c01f7a52198035722c4b7c3792ff76c17c1ad9b8908a5e5b6fff0ecc3c0bbd1ec2828bb1cf36f088b1ad4ed7950d9c78bdb79986d4e785a532db
7
- data.tar.gz: 91d2933830d33038a972ceee8564929474b2c679e824802f40b6597219e91e257ad063874f9c60a39fe4b0d1e97c67294c1931e0ff0aa917b6d5868d3d688825
6
+ metadata.gz: 968071d93fba4ee1da61c7c03b2954e196eebd480760378d9282474b38ec51e5811d617bbab18ce5725d3d1bca78ecb3b6bb2dcda229ca603fcded2051a81708
7
+ data.tar.gz: 8caa065e2e9a93b3fcc618ab6b7692345ba4911cc558dd1aaca43a787842dfce6a57e02175e689f3a53d71d2958a8ac08287d4f2c4574a329eae1b86ee015b24
@@ -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(options[:time]) || DateTime.current_time
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.contents
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)}."
@@ -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
- { datetime: time, description: description }
22
- obj =
23
- if contents
24
- contents.insert(proper_index(time), data)
25
- else
26
- [data]
27
- end
28
- str = obj.to_json
29
- @file_io.overwrite_with(str)
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
- return contents.length
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.rc2
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.0
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.0
96
+ version: '3.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: timecop
99
99
  requirement: !ruby/object:Gem::Requirement