txt_timesheet 1.1.10 → 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/console +0 -0
- data/lib/txt_timesheet.rb +63 -71
- data/lib/txt_timesheet/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bea57bf6456e3b884a2e51f8f0fd2c7e8970085a881dc2219235fca3c6d37579
|
4
|
+
data.tar.gz: b4eed4e605f0188a1317faee4cdc4d7c0d134f2429435b07429e9be2b65b7497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09034b3aa1a285f2f325cddd385bfc474a6d9c00686057330325aafb4a9709763e327c63850507e34e7892d49ff62adeb8237a8af0e2040261a03511cd062c71'
|
7
|
+
data.tar.gz: 06dd27b6578b45f9bffd6b5be6916c38d16216dca33a20733b3d995ef58684ec15db6869c9e2b6af47f0f730db9818647e70b3fda3b835c0a40187a1f00638ab
|
data/bin/console
CHANGED
File without changes
|
data/lib/txt_timesheet.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
require 'time'
|
3
3
|
# Treat past files as a parameter and calculate total hours worked
|
4
4
|
class TxtTimesheet
|
5
5
|
|
@@ -27,82 +27,74 @@ class TxtTimesheet
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def process_file(filename)
|
31
31
|
time_regex = /(?<hours>\d+)\:(?<minutes>\d+)/
|
32
|
-
|
32
|
+
sum_time = 0
|
33
|
+
index = 0
|
34
|
+
content_file = File.open(filename)
|
35
|
+
time = []
|
36
|
+
time_in_sec = []
|
37
|
+
|
38
|
+
### Read all lines from the input file to extract data
|
39
|
+
until content_file.eof?
|
40
|
+
line = content_file.gets.chomp
|
41
|
+
set_can_parse(line)
|
42
|
+
|
43
|
+
next unless can_parse?
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
index = 0
|
39
|
-
files = a
|
40
|
-
file = a.to_s
|
41
|
-
content_file = File.open(file)
|
42
|
-
input_count = 0
|
43
|
-
time = []
|
44
|
-
time_in_min = []
|
45
|
-
|
46
|
-
### Read all lines from the input file to extract data
|
47
|
-
until content_file.eof?
|
48
|
-
line = content_file.gets.chomp
|
49
|
-
set_can_parse(line)
|
50
|
-
|
51
|
-
next unless can_parse?
|
52
|
-
|
53
|
-
next unless time_regex.match(line)
|
54
|
-
|
55
|
-
hours = time_regex.match(line)[:hours]
|
56
|
-
minutes = time_regex.match(line)[:minutes]
|
57
|
-
time.push(hours + ':' + minutes)
|
58
|
-
index += 1
|
59
|
-
end
|
60
|
-
input_count = time.count - input_count # count records in each file
|
61
|
-
content_file.close
|
62
|
-
###
|
63
|
-
|
64
|
-
### iterates over string array and converts to integers
|
65
|
-
index = 0
|
66
|
-
integer = []
|
67
|
-
i_parse_int = input_count * 2
|
68
|
-
time.each do |entry_time|
|
69
|
-
entry_time = entry_time.split(':')
|
70
|
-
entry_time.each do |entry_time_to_integer|
|
71
|
-
integer.push(entry_time_to_integer.to_i)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
###
|
75
|
-
|
76
|
-
### Converts to minutes
|
77
|
-
while index < i_parse_int
|
78
|
-
time_to_min = integer[index]
|
79
|
-
time_to_min *= 60
|
80
|
-
time_to_min += integer[index + 1]
|
81
|
-
time_in_min.push(time_to_min)
|
82
|
-
index += 2
|
83
|
-
end
|
84
|
-
###
|
85
|
-
|
86
|
-
### Calculates worked time in minutes
|
87
|
-
index = 0
|
88
|
-
while index < input_count
|
89
|
-
sum_time = time_in_min[index + 1] - time_in_min[index] + sum_time
|
90
|
-
index += 2
|
91
|
-
end
|
92
|
-
###
|
93
|
-
|
94
|
-
time_file = convert(sum_time)
|
95
|
-
print "#{files}: #{time_file} hours\n"
|
96
|
-
###
|
97
|
-
|
98
|
-
total_time += sum_time # Acumulates the worked time of each file
|
45
|
+
next unless time_regex.match(line)
|
46
|
+
|
47
|
+
time << time_regex.match(line)
|
48
|
+
time_in_sec << Time.parse(time.last.to_s)
|
99
49
|
end
|
100
50
|
|
101
|
-
|
51
|
+
while index < time.count
|
102
52
|
|
103
|
-
|
53
|
+
sum_time = time_in_sec[index + 1] - time_in_sec[index] + sum_time
|
54
|
+
index +=2
|
55
|
+
end
|
104
56
|
###
|
57
|
+
total_sec = sum_time
|
58
|
+
|
59
|
+
# phrase = 'xixixococo'
|
60
|
+
|
61
|
+
{
|
62
|
+
file_name: filename,
|
63
|
+
file_time: total_sec,
|
64
|
+
# phrase: phrase
|
65
|
+
}
|
66
|
+
end
|
105
67
|
|
106
|
-
|
68
|
+
def process_results(results=[])
|
69
|
+
output = []
|
70
|
+
total = []
|
71
|
+
total_time = 0
|
72
|
+
output << 'REPORT:'
|
73
|
+
|
74
|
+
results.each do |result|
|
75
|
+
file_name = result[:file_name]
|
76
|
+
time_file = result[:file_time]
|
77
|
+
total_time += time_file
|
78
|
+
# phrase = result[:phrase]
|
79
|
+
time_file = Time.at(time_file).utc
|
80
|
+
output << "#{file_name}: #{time_file.strftime("%H:%M")} hours \n"
|
81
|
+
|
82
|
+
# total_time = result[:file_time]
|
83
|
+
end
|
84
|
+
total = total_time.divmod(3600)
|
85
|
+
total[1] /= 60
|
86
|
+
total[1] = total.last.to_i
|
87
|
+
output << "Total Hours: #{total.join(":")} hours\n"
|
88
|
+
|
89
|
+
output
|
90
|
+
end
|
91
|
+
|
92
|
+
def run
|
93
|
+
results = []
|
94
|
+
ARGV.each do |arg|
|
95
|
+
results << process_file(arg)
|
96
|
+
end
|
97
|
+
output = process_results(results)
|
98
|
+
puts output.join "\n"
|
107
99
|
end
|
108
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txt_timesheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elvis Serrão
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Receive n files as command line parameters, parse these files and than,
|
14
14
|
calculates how many hours has been worked .
|