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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3437feed67a2ba8b7429f735f17cd84b73dd65097a7b5d01534d7ead1bb4162
4
- data.tar.gz: 3f44ae49d4ace2f5eb87a314f2f8ff261e65d8b9fcf0e7a8643dfbb29c3c8ce5
3
+ metadata.gz: bf2ebf514b240df4079f68fc361938a032b551cd07c1c0b41301e5a6c898d5fe
4
+ data.tar.gz: 67c1a7c5b704423e3481114bd3c87dfeedec174fe171aa059bf13d06bf2e877a
5
5
  SHA512:
6
- metadata.gz: 1821d9727c628a9bbf2a3dc1a9e6e9f978a49f9f754ba563c1e1716ef7df5ca2b1f3db991bb8d98f837e85c1811d92efc2831852839e4dfabe0efb2cc897d5a5
7
- data.tar.gz: 5c84d85d3f34dfadc345f7eeb5db711d3b74e625a62329e1057b7430f58b64e43b1dcb53852892682d39d3ca0f6be5dfb23d0102e6fd4d0563a8cab9ba938129
6
+ metadata.gz: 58c14a99a994505bf4355de93e93974b2c0fe5c2bf99e47c5d21c399ace875f5b8fe3f77b68b0bc50a4587c2b1a9c59e68766c314fdc098e67bb5732a955bf7d
7
+ data.tar.gz: 00a5fb23dd17aa30273cee1a0f60f16ec0879af3164583b7ca5893d69246830d7469ba06429ff32683eddbd81bee50ae1bb1b14a7cb042bd9e56e0c36025b10d
data/lib/txt_timesheet.rb CHANGED
@@ -1,30 +1,27 @@
1
- class Txt_timesheet
1
+ # frozen_string_literal: true
2
2
 
3
- def convert (par)
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 padrão de 2 algarismos do padrão hh:mm
9
- if hours < 10
10
- hours = "0#{hours}"
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
- return time
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 "REPORT:"
27
- #### Percorre todos os arquivos na linha de comando
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 horários no formato hh:mm
39
- while ! content_file.eof?
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
- if time_regex.match(line)
42
- hours = time_regex.match(line)[:hours]
43
- minutes = time_regex.match(line)[:minutes]
44
- time.push(hours + ":" + minutes)
45
- i+=1
46
- end
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 quantas registros tem em cada arquivo
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 = a.split(":")
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 cada horário para minutos
61
+ ### Converte para minutos
65
62
  while i < i_parse_int
66
63
  hrs = inteiro[i]
67
- hrs = hrs * 60
68
- hrs = hrs + inteiro[i+1]
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
@@ -2,7 +2,7 @@ require_relative 'lib/txt_timesheet/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "txt_timesheet"
5
- spec.version = "1.1.2"
5
+ spec.version = "1.1.3"
6
6
  spec.authors = ["Elvis Serrão"]
7
7
  spec.email = ["elvis.serrao1@gmail.com"]
8
8
 
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.2
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-13 00:00:00.000000000 Z
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 .