piece_of_wax 1.0.0.rc1 → 1.0.0.rc2
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/cli_options.rb +24 -0
- data/lib/piece_of_wax/date_time.rb +28 -0
- data/lib/piece_of_wax/date_time_decorator/error_message_display.rb +20 -0
- data/lib/piece_of_wax/date_time_decorator/read_display.rb +17 -0
- data/lib/piece_of_wax/file_io.rb +21 -0
- data/lib/piece_of_wax/output_line/activity.rb +18 -0
- data/lib/piece_of_wax/output_line/date.rb +15 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a74b9ba7e24019636d06f341969473045ebf87fabd886800556fb90993865061
|
4
|
+
data.tar.gz: 0520f53b6c20f6cf5531dda22c64caa663a7d7d339b445d66d31fdac69e69dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a657cfce298c01f7a52198035722c4b7c3792ff76c17c1ad9b8908a5e5b6fff0ecc3c0bbd1ec2828bb1cf36f088b1ad4ed7950d9c78bdb79986d4e785a532db
|
7
|
+
data.tar.gz: 91d2933830d33038a972ceee8564929474b2c679e824802f40b6597219e91e257ad063874f9c60a39fe4b0d1e97c67294c1931e0ff0aa917b6d5868d3d688825
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module PieceOfWax
|
5
|
+
class CLIOptions
|
6
|
+
include Singleton
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
options[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def set(opts)
|
14
|
+
fail 'CLIOptions is an immutable singleton; #set can only be called once per program execution' if options.any?
|
15
|
+
@options = opts
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def options
|
21
|
+
@options || {}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'piece_of_wax/cli_options'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
module PieceOfWax
|
5
|
+
class DateTime < ::Time
|
6
|
+
def self.safe_parse(arg)
|
7
|
+
# NOTE: calling to_s so method is safe for non-string args
|
8
|
+
str = arg.to_s
|
9
|
+
begin
|
10
|
+
parse(str)
|
11
|
+
rescue ArgumentError
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.current_date
|
17
|
+
# NOTE: Possible that current_date returns two different values over course of
|
18
|
+
# same piece_of_wax invocation (if run at midnight.) I consider this
|
19
|
+
# to be a major edge case with minimal consequences, so I'm not
|
20
|
+
# going to the trouble of memoizing at this point. - Ben S.
|
21
|
+
Time.now.to_date
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.current_time
|
25
|
+
Time.now
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PieceOfWax
|
2
|
+
module DateTimeDecorator
|
3
|
+
class ErrorMessageDisplay
|
4
|
+
def initialize(date_time)
|
5
|
+
@date_time = date_time
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
case @date_time.to_date
|
10
|
+
when @date_time.class.current_date
|
11
|
+
'today'
|
12
|
+
when @date_time.class.current_date.prev_day
|
13
|
+
'yesterday'
|
14
|
+
else
|
15
|
+
@date_time.strftime('%Y-%-m-%-d')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PieceOfWax
|
2
|
+
module DateTimeDecorator
|
3
|
+
class ReadDisplay
|
4
|
+
def initialize(date_time)
|
5
|
+
@date_time = date_time
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s
|
9
|
+
if CLIOptions.instance[:military]
|
10
|
+
@date_time.strftime('%H:%M')
|
11
|
+
else
|
12
|
+
@date_time.strftime('%I:%M %p')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PieceOfWax
|
2
|
+
class FileIO
|
3
|
+
def initialize(filename)
|
4
|
+
@filename = filename
|
5
|
+
end
|
6
|
+
|
7
|
+
def read
|
8
|
+
begin
|
9
|
+
File.read(@filename)
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def overwrite_with(str)
|
16
|
+
File.open(@filename, "w") do |f|
|
17
|
+
f.write(str)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'piece_of_wax/date_time'
|
2
|
+
require "piece_of_wax/date_time_decorator/read_display"
|
3
|
+
|
4
|
+
module PieceOfWax
|
5
|
+
module OutputLine
|
6
|
+
class Activity
|
7
|
+
def initialize(start_time_str, end_time_str, description)
|
8
|
+
@start_time = DateTimeDecorator::ReadDisplay.new(DateTime.safe_parse(start_time_str))
|
9
|
+
@end_time = DateTimeDecorator::ReadDisplay.new(DateTime.safe_parse(end_time_str))
|
10
|
+
@description = description
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{@start_time}-#{@end_time} - #{@description}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
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.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Stegeman
|
@@ -117,7 +117,14 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- bin/piece_of_wax
|
119
119
|
- lib/piece_of_wax.rb
|
120
|
+
- lib/piece_of_wax/cli_options.rb
|
121
|
+
- lib/piece_of_wax/date_time.rb
|
122
|
+
- lib/piece_of_wax/date_time_decorator/error_message_display.rb
|
123
|
+
- lib/piece_of_wax/date_time_decorator/read_display.rb
|
124
|
+
- lib/piece_of_wax/file_io.rb
|
120
125
|
- lib/piece_of_wax/logfile.rb
|
126
|
+
- lib/piece_of_wax/output_line/activity.rb
|
127
|
+
- lib/piece_of_wax/output_line/date.rb
|
121
128
|
homepage:
|
122
129
|
licenses:
|
123
130
|
- MIT
|