txt_timesheet 1.1.7 → 1.1.8

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: 1b888853a5d85fa26280f88f5712a79c29bd31c68aeb61ab4aa3a6ed457d2da5
4
- data.tar.gz: 350f5f8e89bd98e6f958fec7b9245b80d629a012970ba2731e9394fc19455de8
3
+ metadata.gz: d4e57aac820c74b568ed62205923a8e00fc3429169903ff9ded7de7a4efbe547
4
+ data.tar.gz: ec3f89bd48806cac96cc4c8ace73b2df23a43d305abcbc6af91bde46dcdfbc59
5
5
  SHA512:
6
- metadata.gz: 1b9e2d2d3a6db8b1a7c6d462872e67de29e4ab4f66592f0ba8d5f74dee75b1e99a0a20cd06145e82a229b3a2c0171af63469250d39ff404eac67d684ff313b2f
7
- data.tar.gz: f3d7d4a57c645f1f81200c10c57a2270da69e3dc4b775bfec4bc39c21cace0d486d61b034f9a19a1b50f7a62905bd1f6d81d0e977bc74a842c790f3785004d69
6
+ metadata.gz: 2cb6f486356d4b40f6545cc408b069a88028cbcab33bf77660b5c52b0371dd127388016fd0ea8ff20f8ef1cdb239e5c84277d6882005fc75d3797cbb0076e3d8
7
+ data.tar.gz: bd7dd852d120dc1b78782c158f80c8b089679964163e91a003539c5442d3aa1711a323814a0b4897010964d62cd6d7b9cf97d6a3fda9eec0768267e31e9731d5
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+
2
+ .idea/
3
+ *.gem
4
+ assets/
5
+ *.txt
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.0.pre.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in txt_timesheet.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ txt_timesheet (1.1.3)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (12.3.2)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.0)
16
+ rspec-support (~> 3.9.0)
17
+ rspec-expectations (3.9.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.0)
24
+
25
+ PLATFORMS
26
+ x64-mingw32
27
+
28
+ DEPENDENCIES
29
+ rake (~> 12.0)
30
+ rspec (~> 3.0)
31
+ txt_timesheet!
32
+
33
+ BUNDLED WITH
34
+ 2.1.0.pre.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Elvis Serrão
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+
2
+
3
+ Txt-timesheet [![Gem Version](https://badge.fury.io/rb/txt_timesheet.svg)](https://badge.fury.io/rb/txt_timesheet)
4
+ ====================
5
+
6
+ Timesheet calculator for .txt files.
7
+
8
+ Installation
9
+ ------------
10
+ gem install txt_timesheet
11
+
12
+ How it works
13
+ ------------
14
+
15
+ Given 3 files like these
16
+
17
+ `file1.txt`:
18
+
19
+
20
+ ## Timesheet
21
+
22
+ morning: 09:13
23
+ brb lunch: 12:03
24
+ back: 13:56
25
+ leaving: 20:53
26
+
27
+ ## What Happened?
28
+
29
+
30
+ `file2.txt`:
31
+
32
+ ## Timesheet
33
+
34
+ morning: 09:59
35
+ brb lunch: 12:07
36
+ back: 13:40
37
+ brb: 18:41
38
+ back: 20:53
39
+ leaving: 22:53
40
+
41
+ ## Daily report
42
+
43
+ Leaving:
44
+
45
+ `file3.txt`:
46
+
47
+ ## Timesheet
48
+
49
+ morning: 09:45
50
+ brb lunch: 12:28
51
+ back: 13:31
52
+ brb: 18:07
53
+ back: 23:11
54
+ leaving: 23:11
55
+
56
+ ## Daily report
57
+
58
+ Leaving:
59
+ - syncs with Flávia, and with Iago and Arthur
60
+ - started working on CRM side to create user with password in authenticator
61
+
62
+
63
+ Your output should be like this:
64
+
65
+ $ timesheet file1.txt file2.txt file3.txt
66
+
67
+ REPORT:
68
+ file1.txt: 09:47 hours
69
+ file2.txt: 09:09 hours
70
+ file3.txt: 07:19 hours
71
+ Total Hours: 26:15 hours
72
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "txt_timesheet"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "txt_timesheet"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/timesheet CHANGED
@@ -1,9 +1,8 @@
1
-
2
- #!/usr/bin/env ruby
3
-
4
- $LOAD_PATH.unshift("#{__dir__}/../lib")
5
-
6
- require 'txt_timesheet'
7
-
8
- cli = TxtTimesheet.new
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require 'txt_timesheet'
6
+
7
+ cli = TxtTimesheet.new
9
8
  cli.run
@@ -1,3 +1,3 @@
1
- module TxtTimesheet
2
- VERSION = "1.1.7"
3
- end
1
+ module TxtTimesheet
2
+ VERSION = "1.1.8"
3
+ end
data/lib/txt_timesheet.rb CHANGED
@@ -1,84 +1,88 @@
1
- # frozen_string_literal: true
2
-
3
- require 'txt_timesheet/convert'
4
-
5
- # Treat past files as a parameter and calculate total hours worked
6
- class TxtTimesheet
7
-
8
- include Timesheet
9
-
10
- def run
11
- time_regex = /(?<hours>\d+)\:(?<minutes>\d+)/
12
- total_time = 0
13
-
14
- puts 'REPORT:'
15
- #### Receive all files indicated on the command line
16
- ARGV.each do |a|
17
- sum_time = 0
18
- index = 0
19
- files = a
20
- file = a.to_s
21
- content_file = File.open(file)
22
- input_count = 0
23
- time = []
24
- time_in_min = []
25
-
26
- ### Read all lines from the input file to extract data
27
- until content_file.eof?
28
- line = content_file.gets.chomp
29
- next unless time_regex.match(line)
30
-
31
- hours = time_regex.match(line)[:hours]
32
- minutes = time_regex.match(line)[:minutes]
33
- time.push(hours + ':' + minutes)
34
- index += 1
35
- end
36
- input_count = time.count - input_count # count records in each file
37
- content_file.close
38
- ###
39
-
40
- ### iterates over string array and converts to integers
41
- index = 0
42
- integer = []
43
- i_parse_int = input_count * 2
44
- time.each do |entry_time|
45
- entry_time = entry_time.split(':')
46
- entry_time.each do |entry_time_to_integer|
47
- integer.push(entry_time_to_integer.to_i)
48
- end
49
- end
50
- ###
51
-
52
- ### Converts to minutes
53
- while index < i_parse_int
54
- time_to_min = integer[index]
55
- time_to_min *= 60
56
- time_to_min += integer[index + 1]
57
- time_in_min.push(time_to_min)
58
- index += 2
59
- end
60
- ###
61
-
62
- ### Calculates worked time in minutes
63
- index = 0
64
- while index < input_count
65
- sum_time = time_in_min[index + 1] - time_in_min[index] + sum_time
66
- index += 2
67
- end
68
- ###
69
-
70
- time_file = convert(sum_time)
71
- print "#{files}: #{time_file} hours\n"
72
- ###
73
-
74
- total_time += sum_time # Acumulates the worked time of each file
75
- end
76
-
77
- time_file = convert(total_time)
78
-
79
- puts "Total Hours: #{time_file} hours\n"
80
- ###
81
-
82
- ####
83
- end
84
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Treat past files as a parameter and calculate total hours worked
4
+ class TxtTimesheet
5
+
6
+ def convert(time_in_minutes)
7
+ ### Convert working time to hh:mm format
8
+ hours = time_in_minutes / 60
9
+ minutes = time_in_minutes - hours * 60
10
+ ## Add 0 to keep hh: mm format
11
+ "%02d:%02d" % [hours, minutes]
12
+ end
13
+
14
+ def run
15
+ time_regex = /(?<hours>\d+)\:(?<minutes>\d+)/
16
+ total_time = 0
17
+
18
+ puts 'REPORT:'
19
+ #### Receive all files indicated on the command line
20
+ ARGV.each do |a|
21
+ sum_time = 0
22
+ index = 0
23
+ files = a
24
+ file = a.to_s
25
+ content_file = File.open(file)
26
+ input_count = 0
27
+ time = []
28
+ time_in_min = []
29
+
30
+ ### Read all lines from the input file to extract data
31
+ until content_file.eof?
32
+ line = content_file.gets.chomp
33
+ next unless time_regex.match(line)
34
+
35
+ hours = time_regex.match(line)[:hours]
36
+ minutes = time_regex.match(line)[:minutes]
37
+ time.push(hours + ':' + minutes)
38
+ index += 1
39
+ end
40
+ input_count = time.count - input_count # count records in each file
41
+ content_file.close
42
+ ###
43
+
44
+ ### iterates over string array and converts to integers
45
+ index = 0
46
+ integer = []
47
+ i_parse_int = input_count * 2
48
+ time.each do |entry_time|
49
+ entry_time = entry_time.split(':')
50
+ entry_time.each do |entry_time_to_integer|
51
+ integer.push(entry_time_to_integer.to_i)
52
+ end
53
+ end
54
+ ###
55
+
56
+ ### Converts to minutes
57
+ while index < i_parse_int
58
+ time_to_min = integer[index]
59
+ time_to_min *= 60
60
+ time_to_min += integer[index + 1]
61
+ time_in_min.push(time_to_min)
62
+ index += 2
63
+ end
64
+ ###
65
+
66
+ ### Calculates worked time in minutes
67
+ index = 0
68
+ while index < input_count
69
+ sum_time = time_in_min[index + 1] - time_in_min[index] + sum_time
70
+ index += 2
71
+ end
72
+ ###
73
+
74
+ time_file = convert(sum_time)
75
+ print "#{files}: #{time_file} hours\n"
76
+ ###
77
+
78
+ total_time += sum_time # Acumulates the worked time of each file
79
+ end
80
+
81
+ time_file = convert(total_time)
82
+
83
+ puts "Total Hours: #{time_file} hours\n"
84
+ ###
85
+
86
+ ####
87
+ end
88
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/txt_timesheet/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "txt_timesheet"
5
+ spec.version = TxtTimesheet::VERSION
6
+ spec.authors = ["Elvis Serrão"]
7
+ spec.email = ["elvis.serrao1@gmail.com"]
8
+
9
+ spec.summary = %q{Calculate Timesheet.}
10
+ spec.description = %q{Receive n files as command line parameters, parse these files and than, calculates how many hours has been worked .}
11
+ spec.homepage = "https://elvisserrao.github.io/"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata = {
16
+ 'homepage_uri' => 'https://elvisserrao.github.io/',
17
+ 'source_code_uri' => 'https://github.com/elvisserrao/txt-timesheet'
18
+ }
19
+
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ 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.7
4
+ version: 1.1.8
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-10-19 00:00:00.000000000 Z
11
+ date: 2019-12-02 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 .
@@ -21,12 +21,19 @@ executables:
21
21
  extensions: []
22
22
  extra_rdoc_files: []
23
23
  files:
24
+ - ".gitignore"
25
+ - ".travis.yml"
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
24
31
  - bin/console
25
32
  - bin/setup
26
33
  - bin/timesheet
27
34
  - lib/txt_timesheet.rb
28
- - lib/txt_timesheet/convert.rb
29
35
  - lib/txt_timesheet/version.rb
36
+ - txt_timesheet.gemspec
30
37
  homepage: https://elvisserrao.github.io/
31
38
  licenses:
32
39
  - MIT
@@ -1,11 +0,0 @@
1
-
2
- module Timesheet
3
-
4
- def convert(time_in_minutes)
5
- ### Convert working time to hh:mm format
6
- hours = time_in_minutes / 60
7
- minutes = time_in_minutes - hours * 60
8
- ## Add 0 to keep hh: mm format
9
- "%02d:%02d" % [hours, minutes]
10
- end
11
- end