totaltime 0.1.0
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 +7 -0
- data/bin/totaltime +4 -0
- data/lib/cli.rb +47 -0
- data/lib/duration.rb +55 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: acf23c01655f379fe51093992d378a967260f09881405890b1023b09c34927b2
|
|
4
|
+
data.tar.gz: 04e504f40070f878e805b7009d71875d629f30f59fe69d7f78af84e6286a869a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 68172ccb21b3d2b2841f9c33fa2e8505b834a17de878ed2c0c9f35c44dd753c76f19541ca01848301290a24298861af715c05891bbccb763ae7564906d83b2e3
|
|
7
|
+
data.tar.gz: 95b434a5ad0825e9be04e7f5b353c873e0e39030e3da4aa196b35cf878ac38aadf014f6c8248c0413129d71f6427e039f575e0a6a1cc517f8287c15085502f95
|
data/bin/totaltime
ADDED
data/lib/cli.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "optparse"
|
|
2
|
+
require "tempfile"
|
|
3
|
+
require "readline"
|
|
4
|
+
require "colorize"
|
|
5
|
+
|
|
6
|
+
require "duration.rb"
|
|
7
|
+
|
|
8
|
+
class CLI
|
|
9
|
+
def self.run
|
|
10
|
+
OptionParser.new do |parser|
|
|
11
|
+
parser.banner = "Usage: timesheet [options]"
|
|
12
|
+
|
|
13
|
+
parser.on("-h", "--help", "Show this help message") do ||
|
|
14
|
+
puts parser
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
end.parse!
|
|
18
|
+
|
|
19
|
+
puts "Press [Enter] on an empty line to confirm".light_black
|
|
20
|
+
totalDuration = Duration.new
|
|
21
|
+
|
|
22
|
+
lineUp = "\033[1A"
|
|
23
|
+
lineClear = "\033[K"
|
|
24
|
+
|
|
25
|
+
prompt = "> ".light_black
|
|
26
|
+
promptOverride = lineUp + "\r" + lineClear + prompt
|
|
27
|
+
|
|
28
|
+
while line = Readline.readline(prompt, true)
|
|
29
|
+
if line.empty?
|
|
30
|
+
print lineUp
|
|
31
|
+
break
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
duration = Duration.try_convert(line)
|
|
35
|
+
|
|
36
|
+
if duration != nil
|
|
37
|
+
totalDuration += duration
|
|
38
|
+
puts promptOverride + duration.to_s.green
|
|
39
|
+
elsif
|
|
40
|
+
invalidText = (line + " [Invalid]").red
|
|
41
|
+
puts promptOverride + invalidText
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
puts "Total time: ".light_black + totalDuration.to_s.cyan
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/duration.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
class Duration
|
|
2
|
+
attr_accessor :hours, :minutes
|
|
3
|
+
|
|
4
|
+
def initialize(hours=0, minutes=0)
|
|
5
|
+
unless hours.is_a?(Integer) && minutes.is_a?(Integer)
|
|
6
|
+
raise TypeError.new("Duration expects integer parameters.")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
@hours=hours
|
|
10
|
+
@minutes=minutes
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def valid?
|
|
14
|
+
@hours >= 0 && @minutes >= 0 && @minutes <= 59
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def +(duration)
|
|
18
|
+
newMinutes = (@minutes + duration.minutes) % 60
|
|
19
|
+
newHours = @hours + duration.hours + (@minutes + duration.minutes) / 60
|
|
20
|
+
Duration.new(newHours, newMinutes)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.try_convert(str)
|
|
24
|
+
floatValue = Float(str, exception: false)
|
|
25
|
+
if floatValue
|
|
26
|
+
parsedMinutes = floatValue * 60
|
|
27
|
+
parsedHours = (parsedMinutes / 60).floor
|
|
28
|
+
parsedMinutes = parsedMinutes % 60
|
|
29
|
+
|
|
30
|
+
newDuration = Duration.new(parsedHours, parsedMinutes.round)
|
|
31
|
+
return newDuration if newDuration.valid?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
parts=str.split(":")
|
|
35
|
+
|
|
36
|
+
return unless parts.length == 2
|
|
37
|
+
|
|
38
|
+
parsedHours = Integer(parts[0], exception: false)
|
|
39
|
+
parsedMinutes = Integer(parts[1], exception: false)
|
|
40
|
+
|
|
41
|
+
parsedHours = (parsedMinutes / 60) if parsedHours == nil && parsedMinutes != nil
|
|
42
|
+
return unless parsedHours != nil && parsedMinutes != nil
|
|
43
|
+
|
|
44
|
+
parsedMinutes = parsedMinutes % 60
|
|
45
|
+
|
|
46
|
+
newDuration = Duration.new(parsedHours, parsedMinutes)
|
|
47
|
+
if newDuration.valid? then newDuration else nil end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def to_s
|
|
51
|
+
formattedHours = @hours.to_s.rjust(2, "0")
|
|
52
|
+
formattedMinutes = @minutes.to_s.rjust(2, "0")
|
|
53
|
+
return "#{formattedHours}:#{formattedMinutes}"
|
|
54
|
+
end
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: totaltime
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- NikxDa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A beautiful timesheet calculator for the command line
|
|
14
|
+
email: ''
|
|
15
|
+
executables:
|
|
16
|
+
- totaltime
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/totaltime
|
|
21
|
+
- lib/cli.rb
|
|
22
|
+
- lib/duration.rb
|
|
23
|
+
homepage: https://rubygems.org/gems/totaltime
|
|
24
|
+
licenses:
|
|
25
|
+
- MIT
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '0'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubygems_version: 3.0.3
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: CLI timesheet calculator
|
|
46
|
+
test_files: []
|