working_times 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/working_times/cli.rb +36 -3
- data/lib/working_times/config.rb +1 -1
- data/lib/working_times/constants.rb +1 -1
- data/lib/working_times/record.rb +34 -17
- data/lib/working_times/state.rb +11 -7
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ebd6d054605888087a369c063ff4f6ffefcf927a51f13aaa5b1bde063f188d1
|
4
|
+
data.tar.gz: 65308945212ede538dbfbfb4a6fc7480e647f4bfbbe3ac370b7b0ba084f2e2b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df37380e64a52547a61d3e6cb1ebc7953291d1d691d4bb91c0eb565b52fc984e21f11470516928feef37c56b8e234f59c97cfa5cf7d99c9dce456853fb6cfe13
|
7
|
+
data.tar.gz: 0b68b81226acb8176ab7637b6282df415881dd0d65cab72e7a0c5d214669805e8330f81aa677060c5caeae1d9e303c770b4dda99258855b87d5b08df87eb3b34
|
data/lib/working_times/cli.rb
CHANGED
@@ -4,12 +4,20 @@ require 'thor'
|
|
4
4
|
|
5
5
|
module WorkingTimes
|
6
6
|
class CLI < Thor
|
7
|
+
include State
|
8
|
+
|
7
9
|
option :work_on, aliases: ['-w'], desc: 'Specify what group of work on'
|
8
10
|
desc 'start [COMMENT] <option>', 'Start working with comment.'
|
9
11
|
def start(comment = nil)
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
initialize_data_dir
|
13
|
+
if working?
|
14
|
+
puts "You are already on working at #{current_work}."
|
15
|
+
puts "To finish this, execute 'wt finish'."
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
Record.new(timestamp: Time.now, comment: comment, work_on: options[:work_on]).start
|
20
|
+
start_work(options[:work_on])
|
13
21
|
end
|
14
22
|
|
15
23
|
desc 'st [COMMENT] <option>', 'Short hand for *start*'
|
@@ -17,10 +25,35 @@ module WorkingTimes
|
|
17
25
|
|
18
26
|
desc 'finish [COMMENT]', 'Finish working on current group.'
|
19
27
|
def finish(comment = nil)
|
28
|
+
unless working?
|
29
|
+
puts 'You are not starting work. Execute "wt start" to start working.'
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
20
33
|
Record.new(timestamp: Time.now, comment: comment).finish
|
34
|
+
finish_work
|
21
35
|
end
|
22
36
|
|
23
37
|
desc 'fi [COMMENT]', 'Short hand for *finish*'
|
24
38
|
alias fi finish
|
39
|
+
|
40
|
+
desc 'rest DURATION', 'Record resting time. e.g. \'wt rest 1h30m\''
|
41
|
+
def rest(duration = nil)
|
42
|
+
if duration.nil?
|
43
|
+
puts <<~MSG
|
44
|
+
Please specify duration of resting.
|
45
|
+
e.g. wt rest 1h30m
|
46
|
+
e.g. wt rest '1 hour 30 minutes'
|
47
|
+
MSG
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
unless working?
|
52
|
+
puts 'You are not starting work. Execute "wt start" to start working.'
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
Record.new(timestamp: Time.now, duration: duration).rest
|
57
|
+
end
|
25
58
|
end
|
26
59
|
end
|
data/lib/working_times/config.rb
CHANGED
data/lib/working_times/record.rb
CHANGED
@@ -4,37 +4,54 @@ require 'active_support/time'
|
|
4
4
|
|
5
5
|
module WorkingTimes
|
6
6
|
class Record
|
7
|
-
|
7
|
+
include State
|
8
8
|
|
9
|
-
|
9
|
+
attr_reader :timestamp, :comment, :duration, :work_on
|
10
|
+
|
11
|
+
def initialize(timestamp:, comment: nil, duration: nil, work_on: nil)
|
10
12
|
@timestamp = timestamp
|
11
13
|
@comment = comment
|
12
|
-
@
|
14
|
+
@duration = duration
|
15
|
+
@work_on = work_on.nil? ? default_work : work_on
|
13
16
|
end
|
14
17
|
|
15
18
|
def start
|
16
|
-
|
17
|
-
puts "
|
18
|
-
puts "To finish this, execute 'wt finish'."
|
19
|
-
return
|
19
|
+
File.open("#{data_dir}/#{work_on}", 'a+') do |f|
|
20
|
+
f.puts "#{timestamp.rfc3339},,#{comment},start"
|
20
21
|
end
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
def finish
|
25
|
+
File.open("#{data_dir}/#{current_work}", 'a+') do |f|
|
26
|
+
f.puts ",#{timestamp.rfc3339},#{comment},finish"
|
24
27
|
end
|
25
|
-
State.start_work(work_on)
|
26
28
|
end
|
27
29
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def rest
|
31
|
+
parse_rest_finished_at
|
32
|
+
File.open("#{data_dir}/#{current_work}", 'a+') do |f|
|
33
|
+
f.puts "#{timestamp.rfc3339},#{@finished_at},#{comment},rest"
|
32
34
|
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
show_rest_msg
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def parse_rest_finished_at
|
42
|
+
@finished_at = timestamp
|
43
|
+
if /(?<hour>\d+)\s*h/ =~ duration
|
44
|
+
@finished_at += hour.to_i.hour
|
45
|
+
end
|
46
|
+
|
47
|
+
if /(?<minute>\d+)\s*m/ =~ duration
|
48
|
+
@finished_at += minute.to_i.minute
|
36
49
|
end
|
37
|
-
|
50
|
+
end
|
51
|
+
|
52
|
+
def show_rest_msg
|
53
|
+
Time::DATE_FORMATS[:rest_finished_at] = '%H:%m:%S'
|
54
|
+
puts "You can rest until #{@finished_at.to_s(:rest_finished_at)}."
|
38
55
|
end
|
39
56
|
end
|
40
57
|
end
|
data/lib/working_times/state.rb
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
module WorkingTimes
|
4
4
|
module State
|
5
|
-
|
5
|
+
private
|
6
|
+
|
7
|
+
include Config
|
6
8
|
|
7
9
|
# generate data directory when does not exist
|
8
10
|
# it is usually called by 'start' command
|
@@ -10,32 +12,34 @@ module WorkingTimes
|
|
10
12
|
return if exist_data_dir?
|
11
13
|
|
12
14
|
puts 'data directory .wt not found, generated.'
|
13
|
-
Dir.mkdir(
|
15
|
+
Dir.mkdir(data_dir)
|
14
16
|
end
|
15
17
|
|
16
18
|
def exist_data_dir?
|
17
|
-
File.exist?(
|
19
|
+
File.exist?(data_dir)
|
18
20
|
end
|
19
21
|
|
20
22
|
def working?
|
21
|
-
File.exist?("#{
|
23
|
+
File.exist?("#{data_dir}/.working")
|
22
24
|
end
|
23
25
|
|
26
|
+
# return what kind of working on
|
24
27
|
def current_work
|
25
|
-
File.readlines("#{
|
28
|
+
File.readlines("#{data_dir}/.working").last.chomp
|
26
29
|
end
|
27
30
|
|
28
31
|
# create ~/.wt/.working include what you working on
|
29
32
|
# and show 'started' message
|
30
33
|
def start_work(work_on)
|
31
|
-
|
34
|
+
work_on = work_on.nil? ? default_work : work_on
|
35
|
+
File.open("#{data_dir}/.working", 'w+') { |f| f.puts work_on }
|
32
36
|
puts START_MSG.sample
|
33
37
|
end
|
34
38
|
|
35
39
|
# delete 'working' flag
|
36
40
|
# and show 'finished' message
|
37
41
|
def finish_work
|
38
|
-
File.delete("#{
|
42
|
+
File.delete("#{data_dir}/.working")
|
39
43
|
puts FINISH_MSG.sample
|
40
44
|
end
|
41
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: working_times
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aoshi Fujioka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Store your working/worked time simply. This gem gives simple CLI tool.
|
84
98
|
email:
|
85
99
|
- blue20will@gmail.com
|