working_times 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c1cb045c23cfbe87ea49943e7e2c28e6d0505a982655590a508727c33b65a76
4
+ data.tar.gz: bfccaa8f07492350728de361813de3619f8d38de7348509595c6529ece71d4fb
5
+ SHA512:
6
+ metadata.gz: 7db45a628f2468eb259baf11c3d3e5fd6d2f451b4b24cc5684bb61985a5d1014850a9cd027b86b14efbffae49d83e6dfec2e4d8f291280bf78b14085e7ca2d4d
7
+ data.tar.gz: 04db8a31ee9a9f2d6f5af20216008512ccb157bde289dbdfbb273a3e7c938b1ab10b4e847b20a6f6a6fa1a75766f129d6bf42d03d09339dc424a263eaac1071b
data/exe/wt ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'working_times'
4
+
5
+ WorkingTimes::CLI.start
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'active_support/time'
5
+
6
+ module WorkingTimes
7
+ class CLI < Thor
8
+ option :work_on, aliases: ['-w'], desc: 'Specify what group of work on'
9
+ desc 'start [COMMENT] <option>', 'Start working with comment.'
10
+ def start(comment = nil)
11
+ State.initialize_data_dir
12
+ work_on = options[:work_on].nil? ? Config.default_work : options[:work_on]
13
+ Record.new(timestamp: Time.now, comment: comment, work_on: work_on).start
14
+ end
15
+
16
+ desc 'st [COMMENT]', 'Short hand for *start*'
17
+ alias st start
18
+
19
+ desc 'finish [COMMENT]', 'Finish working on current group.'
20
+ def finish(comment = nil)
21
+ Record.new(timestamp: Time.now, comment: comment).finish
22
+ end
23
+
24
+ desc 'fi [COMMENT]', 'Short hand for *finish*'
25
+ alias fi finish
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkingTimes
4
+ module Config
5
+ module_function
6
+
7
+ # return where data directory is
8
+ def data_dir
9
+ File.expand_path(wtconf['DATADIR'])
10
+ end
11
+
12
+ # return default working project/task/etc...
13
+ def default_work
14
+ wtconf['DEFAULTWORK']
15
+ end
16
+
17
+ # parse ~/.wtconf
18
+ def wtconf
19
+ conf = default_conf
20
+ begin
21
+ File
22
+ .readlines(File.expand_path('~/.wtconf'))
23
+ .map(&:chomp)
24
+ .each do |row|
25
+ k, v = row.split('=')
26
+ conf[k] = v
27
+ end
28
+ rescue Errno::ENOENT
29
+ puts '~/.wtconf not found, generated.'
30
+ generate_wtconf
31
+ end
32
+ conf
33
+ end
34
+
35
+ # default configurations of .wtconf
36
+ def default_conf
37
+ { 'DATADIR' => File.expand_path('~/.wt'), 'DEFAULTWORK' => 'default' }
38
+ end
39
+
40
+ # generate configuration file to ~/.wtconf when does not exist
41
+ def generate_wtconf
42
+ File.open(File.expand_path('~/.wtconf'), 'w') { |f| f.puts(default_conf.map { |k, v| "#{k}=#{v}" }) }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkingTimes
4
+ class Record
5
+ attr_reader :timestamp, :comment, :work_on
6
+
7
+ def initialize(timestamp:, comment:, work_on: nil)
8
+ @timestamp = timestamp
9
+ @comment = comment
10
+ @work_on = work_on
11
+ end
12
+
13
+ def start
14
+ if State.working?
15
+ puts "You are already on working at #{current_work}."
16
+ puts "To finish this, execute 'wt finish'."
17
+ return
18
+ end
19
+
20
+ File.open("#{Config.data_dir}/#{work_on}", 'a+') do |f|
21
+ f.puts "start,#{comment},#{timestamp.rfc3339}"
22
+ end
23
+ State.start_work(work_on)
24
+ end
25
+
26
+ def finish
27
+ unless State.working?
28
+ puts 'You are not starting work. Execute "wt start" to start working.'
29
+ return
30
+ end
31
+
32
+ File.open("#{Config.data_dir}/#{State.current_work}", 'a+') do |f|
33
+ f.puts "finish,#{comment},#{timestamp.rfc3339}"
34
+ end
35
+ State.finish_work
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkingTimes
4
+ module State
5
+ module_function
6
+
7
+ # generate data directory when does not exist
8
+ # it is usually called by 'start' command
9
+ def initialize_data_dir
10
+ return if exist_data_dir?
11
+
12
+ puts 'data directory .wt not found, generated.'
13
+ Dir.mkdir(Config.data_dir)
14
+ end
15
+
16
+ def exist_data_dir?
17
+ File.exist?(Config.data_dir)
18
+ end
19
+
20
+ def working?
21
+ File.exist?("#{Config.data_dir}/.working")
22
+ end
23
+
24
+ def current_work
25
+ File.readlines("#{Config.data_dir}/.working").last.chomp
26
+ end
27
+
28
+ # create ~/.wt/.working include what you working on
29
+ def start_work(work_on)
30
+ File.open("#{Config.data_dir}/.working", 'w+') { |f| f.puts work_on }
31
+ end
32
+
33
+ # delete 'working' flag
34
+ def finish_work
35
+ File.delete("#{Config.data_dir}/.working")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module WorkingTimes
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'working_times/version'
2
+ require 'working_times/config'
3
+ require 'working_times/state'
4
+ require 'working_times/record'
5
+ require 'working_times/cli'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: working_times
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aoshi Fujioka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.20.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.20.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Store your working/worked time simply. This gem gives simple CLI tool.
84
+ email:
85
+ - blue20will@gmail.com
86
+ executables:
87
+ - wt
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - exe/wt
92
+ - lib/working_times.rb
93
+ - lib/working_times/cli.rb
94
+ - lib/working_times/config.rb
95
+ - lib/working_times/record.rb
96
+ - lib/working_times/state.rb
97
+ - lib/working_times/version.rb
98
+ homepage: https://github.com/arsley/working_times
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.0.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Store your working/worked time simply
121
+ test_files: []