working_times 0.3.2 → 0.5.1
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 +4 -4
- data/exe/wt +14 -0
- data/lib/working_times/cli.rb +8 -8
- data/lib/working_times/config.rb +0 -2
- data/lib/working_times/constants.rb +8 -3
- data/lib/working_times/record.rb +26 -20
- data/lib/working_times/state.rb +19 -2
- metadata +36 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b873d5ea276962e2e2b73cbb9cade749b8ebd8879415b3f9ecb6859a8a95b19
|
4
|
+
data.tar.gz: 26c9539dc6c44c96f235da3deca0185385227cd94fa3863fe7f92aa8639e5288
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2e1255c35746e8169308746cacfc8eadd2e59fc6ef79e0b3bbd62e2f48d9623b9dbb0bcc84b07c73036cffe8fd40e4d5fa5283707e71f0cf24f1146eafdd0a
|
7
|
+
data.tar.gz: c71470e2de46a3727f19e2a9d9c14385a57d32af8a1514f76acc17a341e3db886c4337b6c66467c9815b7bf7bd1d372244c74226bec215ccb6b17cfcfef9f1f3
|
data/exe/wt
CHANGED
@@ -2,4 +2,18 @@
|
|
2
2
|
|
3
3
|
require 'working_times'
|
4
4
|
|
5
|
+
# mock config
|
6
|
+
# do not remove ACTUAL configurations
|
7
|
+
module WorkingTimes::Config
|
8
|
+
private
|
9
|
+
|
10
|
+
def data_dir
|
11
|
+
File.expand_path('tmp/.wt')
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_work
|
15
|
+
'default'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
WorkingTimes::CLI.start
|
data/lib/working_times/cli.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'thor'
|
4
2
|
|
5
3
|
module WorkingTimes
|
@@ -8,15 +6,17 @@ module WorkingTimes
|
|
8
6
|
|
9
7
|
option :work_on, aliases: ['-w'], desc: 'Specify what group of work on'
|
10
8
|
desc 'start [COMMENT] <option>', 'Start working with comment.'
|
11
|
-
def start(comment =
|
12
|
-
initialize_data_dir
|
9
|
+
def start(comment = '')
|
13
10
|
if working?
|
14
11
|
puts "You are already on working at #{current_work}."
|
15
12
|
puts "To finish this, execute 'wt finish'."
|
16
13
|
return
|
17
14
|
end
|
18
15
|
|
19
|
-
|
16
|
+
initialize_data_dir
|
17
|
+
initialize_work_log(options[:work_on])
|
18
|
+
|
19
|
+
Record.new(timestamp: DateTime.now, comment: comment, work_on: options[:work_on]).start
|
20
20
|
start_work(options[:work_on])
|
21
21
|
end
|
22
22
|
|
@@ -24,13 +24,13 @@ module WorkingTimes
|
|
24
24
|
alias st start
|
25
25
|
|
26
26
|
desc 'finish [COMMENT]', 'Finish working on current group.'
|
27
|
-
def finish(comment =
|
27
|
+
def finish(comment = '')
|
28
28
|
unless working?
|
29
29
|
puts 'You are not starting work. Execute "wt start" to start working.'
|
30
30
|
return
|
31
31
|
end
|
32
32
|
|
33
|
-
Record.new(timestamp:
|
33
|
+
Record.new(timestamp: DateTime.now, comment: comment).finish
|
34
34
|
finish_work
|
35
35
|
end
|
36
36
|
|
@@ -53,7 +53,7 @@ module WorkingTimes
|
|
53
53
|
return
|
54
54
|
end
|
55
55
|
|
56
|
-
Record.new(timestamp:
|
56
|
+
Record.new(timestamp: DateTime.now, duration: duration).rest
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/working_times/config.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module WorkingTimes
|
4
|
-
VERSION = '0.
|
2
|
+
VERSION = '0.5.1'.freeze
|
5
3
|
|
6
4
|
START_MSG = [
|
7
5
|
'Have a nice work!',
|
@@ -12,4 +10,11 @@ module WorkingTimes
|
|
12
10
|
'Great job!',
|
13
11
|
'Time to beer!'
|
14
12
|
].freeze
|
13
|
+
|
14
|
+
SCHEMA = [
|
15
|
+
'started_at', # DateTime#rfc3339
|
16
|
+
'finished_at', # DateTime#rfc3339
|
17
|
+
'rest_sec', # Integer (inidicates second)
|
18
|
+
'comment' # String
|
19
|
+
].freeze
|
15
20
|
end
|
data/lib/working_times/record.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require 'active_support/time'
|
2
|
+
require 'csv'
|
4
3
|
|
5
4
|
module WorkingTimes
|
6
5
|
class Record
|
7
6
|
include State
|
8
7
|
|
8
|
+
OPTIONS = { headers: true, return_headers: true, write_headers: true }.freeze
|
9
|
+
|
9
10
|
attr_reader :timestamp, :comment, :duration, :work_on
|
10
11
|
|
11
12
|
def initialize(timestamp:, comment: nil, duration: nil, work_on: nil)
|
@@ -16,42 +17,47 @@ module WorkingTimes
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def start
|
19
|
-
|
20
|
-
|
20
|
+
CSV.open("#{data_dir}/#{work_on}", 'a+', OPTIONS) do |csv|
|
21
|
+
csv.puts([timestamp.rfc3339, '', 0, comment])
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def finish
|
25
|
-
|
26
|
-
|
26
|
+
updated_csv = ''
|
27
|
+
CSV.filter(File.open("#{data_dir}/#{current_work}"), updated_csv, OPTIONS) do |row|
|
28
|
+
next if row.header_row?
|
29
|
+
next unless row['finished_at'].empty?
|
30
|
+
|
31
|
+
row['finished_at'] = timestamp.rfc3339
|
32
|
+
row['comment'] = comment
|
27
33
|
end
|
34
|
+
File.write("#{data_dir}/#{current_work}", updated_csv)
|
28
35
|
end
|
29
36
|
|
30
37
|
def rest
|
31
|
-
|
32
|
-
File.open("#{data_dir}/#{current_work}", 'a+') do |f|
|
33
|
-
f.puts "#{timestamp.rfc3339},#{@finished_at.rfc3339},#{comment},rest"
|
34
|
-
end
|
38
|
+
parse_rest_sec
|
35
39
|
|
36
|
-
|
40
|
+
updated_csv = ''
|
41
|
+
CSV.filter(File.open("#{data_dir}/#{current_work}"), updated_csv, OPTIONS) do |row|
|
42
|
+
next if row.header_row?
|
43
|
+
next unless row['finished_at'].empty?
|
44
|
+
|
45
|
+
row['rest_sec'] = @rest_sec
|
46
|
+
end
|
47
|
+
File.write("#{data_dir}/#{current_work}", updated_csv)
|
37
48
|
end
|
38
49
|
|
39
50
|
private
|
40
51
|
|
41
|
-
def
|
42
|
-
@
|
52
|
+
def parse_rest_sec
|
53
|
+
@rest_sec = 0
|
43
54
|
if /(?<hour>\d+)\s*h/ =~ duration
|
44
|
-
@
|
55
|
+
@rest_sec += hour.to_i * 3600
|
45
56
|
end
|
46
57
|
|
47
58
|
if /(?<minute>\d+)\s*m/ =~ duration
|
48
|
-
@
|
59
|
+
@rest_sec += minute.to_i * 60
|
49
60
|
end
|
50
61
|
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)}."
|
55
|
-
end
|
56
62
|
end
|
57
63
|
end
|
data/lib/working_times/state.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module WorkingTimes
|
4
2
|
module State
|
5
3
|
private
|
@@ -15,6 +13,14 @@ module WorkingTimes
|
|
15
13
|
Dir.mkdir(data_dir)
|
16
14
|
end
|
17
15
|
|
16
|
+
# creates csv with header
|
17
|
+
def initialize_work_log(work_on)
|
18
|
+
work_on = work_on.nil? ? default_work : work_on
|
19
|
+
return if File.exist?("#{data_dir}/#{work_on}")
|
20
|
+
|
21
|
+
File.write("#{data_dir}/#{work_on}", SCHEMA.join(',') + "\n")
|
22
|
+
end
|
23
|
+
|
18
24
|
def exist_data_dir?
|
19
25
|
File.exist?(data_dir)
|
20
26
|
end
|
@@ -39,8 +45,19 @@ module WorkingTimes
|
|
39
45
|
# delete 'working' flag
|
40
46
|
# and show 'finished' message
|
41
47
|
def finish_work
|
48
|
+
puts "You were working about #{worked_time}."
|
42
49
|
File.delete("#{data_dir}/.working")
|
43
50
|
puts FINISH_MSG.sample
|
44
51
|
end
|
52
|
+
|
53
|
+
def worked_time
|
54
|
+
last_record = CSV.read("#{data_dir}/#{current_work}").last
|
55
|
+
started_at = Time.parse(last_record[0])
|
56
|
+
finished_at = Time.parse(last_record[1])
|
57
|
+
duration = (finished_at - started_at).to_i
|
58
|
+
hour = duration / 3600
|
59
|
+
min = (duration - 3600 * hour) / 60
|
60
|
+
"#{hour.to_s.rjust(2, '0')} hour #{min.to_s.rjust(2, '0')} min"
|
61
|
+
end
|
45
62
|
end
|
46
63
|
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.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aoshi Fujioka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1
|
47
|
+
version: '2.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1
|
54
|
+
version: '2.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 12.3.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 12.3.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: Store your working/worked time simply. This gem gives simple CLI tool.
|
98
126
|
email:
|
99
127
|
- blue20will@gmail.com
|