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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea7930ce97b0d9bf4dfe1701ebd4e3d5ded07667df481b958aed921f2e36308f
4
- data.tar.gz: 203cf6b53153ef66075511d5c4dae8ad0c8e4c65021ac11340c3ba95d7c570d4
3
+ metadata.gz: 5ebd6d054605888087a369c063ff4f6ffefcf927a51f13aaa5b1bde063f188d1
4
+ data.tar.gz: 65308945212ede538dbfbfb4a6fc7480e647f4bfbbe3ac370b7b0ba084f2e2b1
5
5
  SHA512:
6
- metadata.gz: fb884f67fb32060175ab4f4822dca3b7978c0d64ada4621caf02e255abc954f3cc9d147365357fa0d1a3da6714c16f6118f86b9ca0b315ec04c535642586b526
7
- data.tar.gz: a1dd2d5c5f2ce754b75e2b2d6aeabf98b48fc90ef4d56244098d820011bd296543ea45ab9d159a08df65ebda04171f3b52bd0211e1f4263923dec5b412cd4238
6
+ metadata.gz: df37380e64a52547a61d3e6cb1ebc7953291d1d691d4bb91c0eb565b52fc984e21f11470516928feef37c56b8e234f59c97cfa5cf7d99c9dce456853fb6cfe13
7
+ data.tar.gz: 0b68b81226acb8176ab7637b6282df415881dd0d65cab72e7a0c5d214669805e8330f81aa677060c5caeae1d9e303c770b4dda99258855b87d5b08df87eb3b34
@@ -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
- State.initialize_data_dir
11
- work_on = options[:work_on].nil? ? Config.default_work : options[:work_on]
12
- Record.new(timestamp: Time.now, comment: comment, work_on: work_on).start
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  module WorkingTimes
4
4
  module Config
5
- module_function
5
+ private
6
6
 
7
7
  # return where data directory is
8
8
  def data_dir
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkingTimes
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
 
6
6
  START_MSG = [
7
7
  'Have a nice work!',
@@ -4,37 +4,54 @@ require 'active_support/time'
4
4
 
5
5
  module WorkingTimes
6
6
  class Record
7
- attr_reader :timestamp, :comment, :work_on
7
+ include State
8
8
 
9
- def initialize(timestamp:, comment:, work_on: nil)
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
- @work_on = work_on
14
+ @duration = duration
15
+ @work_on = work_on.nil? ? default_work : work_on
13
16
  end
14
17
 
15
18
  def start
16
- if State.working?
17
- puts "You are already on working at #{State.current_work}."
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
- File.open("#{Config.data_dir}/#{work_on}", 'a+') do |f|
23
- f.puts "start,#{comment},#{timestamp.rfc3339}"
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 finish
29
- unless State.working?
30
- puts 'You are not starting work. Execute "wt start" to start working.'
31
- return
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
- File.open("#{Config.data_dir}/#{State.current_work}", 'a+') do |f|
35
- f.puts "finish,#{comment},#{timestamp.rfc3339}"
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
- State.finish_work
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
@@ -2,7 +2,9 @@
2
2
 
3
3
  module WorkingTimes
4
4
  module State
5
- module_function
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(Config.data_dir)
15
+ Dir.mkdir(data_dir)
14
16
  end
15
17
 
16
18
  def exist_data_dir?
17
- File.exist?(Config.data_dir)
19
+ File.exist?(data_dir)
18
20
  end
19
21
 
20
22
  def working?
21
- File.exist?("#{Config.data_dir}/.working")
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("#{Config.data_dir}/.working").last.chomp
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
- File.open("#{Config.data_dir}/.working", 'w+') { |f| f.puts work_on }
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("#{Config.data_dir}/.working")
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.2.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-25 00:00:00.000000000 Z
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