txt_timesheet 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/txt_timesheet.rb +27 -32
- data/txt_timesheet.gemspec +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: bf2ebf514b240df4079f68fc361938a032b551cd07c1c0b41301e5a6c898d5fe
|
4
|
+
data.tar.gz: 67c1a7c5b704423e3481114bd3c87dfeedec174fe171aa059bf13d06bf2e877a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58c14a99a994505bf4355de93e93974b2c0fe5c2bf99e47c5d21c399ace875f5b8fe3f77b68b0bc50a4587c2b1a9c59e68766c314fdc098e67bb5732a955bf7d
|
7
|
+
data.tar.gz: 00a5fb23dd17aa30273cee1a0f60f16ec0879af3164583b7ca5893d69246830d7469ba06429ff32683eddbd81bee50ae1bb1b14a7cb042bd9e56e0c36025b10d
|
data/lib/txt_timesheet.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# Trata arquivos passados como parametro e calcula o total de horas trabalhadas
|
4
|
+
class TxtTimesheet
|
5
|
+
def convert(par)
|
4
6
|
### Converte o tempo trabalhado para o formato hh:mm
|
5
|
-
hours = par/60
|
7
|
+
hours = par / 60
|
6
8
|
hours = hours.to_i
|
7
9
|
minutes = par - hours * 60
|
8
|
-
## Adiciona o 0 para manter o
|
9
|
-
if hours < 10
|
10
|
-
|
11
|
-
end
|
12
|
-
if minutes < 10
|
13
|
-
minutes = "0#{minutes}"
|
14
|
-
end
|
10
|
+
## Adiciona o 0 para manter o formato hh:mm
|
11
|
+
hours = "0#{hours}" if hours < 10
|
12
|
+
minutes = "0#{minutes}" if minutes < 10
|
15
13
|
|
16
14
|
time = "#{hours}:#{minutes}"
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
time
|
20
17
|
end
|
21
18
|
|
22
19
|
def run
|
23
20
|
time_regex = /(?<hours>\d{2})\:(?<minutes>\d{2})/
|
24
21
|
total_time = 0
|
25
22
|
|
26
|
-
puts
|
27
|
-
|
23
|
+
puts 'REPORT:'
|
24
|
+
#### Percorre todos os arquivos na linha de comando
|
28
25
|
ARGV.each do |a|
|
29
26
|
sum_time = 0
|
30
27
|
i = 0
|
@@ -35,17 +32,17 @@ class Txt_timesheet
|
|
35
32
|
time = []
|
36
33
|
time_to_min = []
|
37
34
|
|
38
|
-
### Percorre todas as linhas do arquivo de entrada para extrair os
|
39
|
-
|
35
|
+
### Percorre todas as linhas do arquivo de entrada para extrair os dados
|
36
|
+
until content_file.eof?
|
40
37
|
line = content_file.gets.chomp
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
next unless time_regex.match(line)
|
39
|
+
|
40
|
+
hours = time_regex.match(line)[:hours]
|
41
|
+
minutes = time_regex.match(line)[:minutes]
|
42
|
+
time.push(hours + ':' + minutes)
|
43
|
+
i += 1
|
47
44
|
end
|
48
|
-
i_count = time.count - i_count # Conta
|
45
|
+
i_count = time.count - i_count # Conta registros em cada arquivo
|
49
46
|
content_file.close
|
50
47
|
###
|
51
48
|
|
@@ -54,28 +51,28 @@ class Txt_timesheet
|
|
54
51
|
inteiro = []
|
55
52
|
i_parse_int = i_count * 2
|
56
53
|
time.each do |a|
|
57
|
-
a =
|
54
|
+
a = a.split(':')
|
58
55
|
a.each do |b|
|
59
56
|
inteiro.push(b.to_i)
|
60
57
|
end
|
61
58
|
end
|
62
59
|
###
|
63
60
|
|
64
|
-
### Converte
|
61
|
+
### Converte para minutos
|
65
62
|
while i < i_parse_int
|
66
63
|
hrs = inteiro[i]
|
67
|
-
hrs
|
68
|
-
hrs
|
64
|
+
hrs *= 60
|
65
|
+
hrs += inteiro[i + 1]
|
69
66
|
time_to_min.push(hrs)
|
70
|
-
i+=2
|
67
|
+
i += 2
|
71
68
|
end
|
72
69
|
###
|
73
70
|
|
74
71
|
### Calcula o tempo trabalhado em minutos
|
75
72
|
i = 0
|
76
73
|
while i < i_count
|
77
|
-
sum_time = time_to_min[i+1] - time_to_min[i] + sum_time
|
78
|
-
i+=2
|
74
|
+
sum_time = time_to_min[i + 1] - time_to_min[i] + sum_time
|
75
|
+
i += 2
|
79
76
|
end
|
80
77
|
###
|
81
78
|
|
@@ -84,7 +81,6 @@ class Txt_timesheet
|
|
84
81
|
###
|
85
82
|
|
86
83
|
total_time += sum_time # Acumulates the worked time of each file
|
87
|
-
|
88
84
|
end
|
89
85
|
|
90
86
|
time_file = convert(total_time)
|
@@ -92,7 +88,6 @@ class Txt_timesheet
|
|
92
88
|
puts "Total Hours: #{time_file} hours\n"
|
93
89
|
###
|
94
90
|
|
95
|
-
|
96
91
|
####
|
97
92
|
end
|
98
93
|
end
|
data/txt_timesheet.gemspec
CHANGED
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elvis Serrão
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-14 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 .
|