kartrace 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/.DS_Store +0 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/README.md +9 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/kartrace.gemspec +28 -0
- data/lib/.DS_Store +0 -0
- data/lib/kartrace.rb +10 -0
- data/lib/kartrace/aftermath.rb +10 -0
- data/lib/kartrace/lap.rb +11 -0
- data/lib/kartrace/race.rb +46 -0
- data/lib/kartrace/racer.rb +25 -0
- data/lib/kartrace/services/assign.rb +27 -0
- data/lib/kartrace/services/command.rb +25 -0
- data/lib/kartrace/version.rb +3 -0
- data/race.log +23 -0
- metadata +123 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ff0d4e67bf9e2222552caf907a24a08dad05b09afcb5100ba32005de1847e56e
|
|
4
|
+
data.tar.gz: 8dd742fe075aa00d5ede5ffe4f831e298ecb6ff7d1b0ad6383f147e5d895aac2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 266e1764aae2c9152a4572c6e1ded2b86448f7d5bfbdb066392eb4dff48098ac057b704c4c4913d5b79f515d588399603ee9de40da9a93c25324d0507984baac
|
|
7
|
+
data.tar.gz: f6790580b17cbbc0461e034894ab365a7a2c97b122d02693882f07e09efe2b8f03b62b358a7b1555df8872a4db916f459fffe8779dbc053c2adcd0f0eeceec7a
|
data/.DS_Store
ADDED
|
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
kartrace (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
byebug (11.0.1)
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
diff-lcs (1.3)
|
|
12
|
+
method_source (0.9.2)
|
|
13
|
+
pry (0.12.2)
|
|
14
|
+
coderay (~> 1.1.0)
|
|
15
|
+
method_source (~> 0.9.0)
|
|
16
|
+
pry-byebug (3.7.0)
|
|
17
|
+
byebug (~> 11.0)
|
|
18
|
+
pry (~> 0.10)
|
|
19
|
+
rake (10.5.0)
|
|
20
|
+
rspec (3.8.0)
|
|
21
|
+
rspec-core (~> 3.8.0)
|
|
22
|
+
rspec-expectations (~> 3.8.0)
|
|
23
|
+
rspec-mocks (~> 3.8.0)
|
|
24
|
+
rspec-core (3.8.2)
|
|
25
|
+
rspec-support (~> 3.8.0)
|
|
26
|
+
rspec-expectations (3.8.4)
|
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
28
|
+
rspec-support (~> 3.8.0)
|
|
29
|
+
rspec-mocks (3.8.1)
|
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
31
|
+
rspec-support (~> 3.8.0)
|
|
32
|
+
rspec-support (3.8.2)
|
|
33
|
+
|
|
34
|
+
PLATFORMS
|
|
35
|
+
ruby
|
|
36
|
+
|
|
37
|
+
DEPENDENCIES
|
|
38
|
+
bundler (~> 2.0)
|
|
39
|
+
kartrace!
|
|
40
|
+
pry-byebug
|
|
41
|
+
rake (~> 10.0)
|
|
42
|
+
rspec (~> 3.0)
|
|
43
|
+
|
|
44
|
+
BUNDLED WITH
|
|
45
|
+
2.0.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Matheus Barbosa
|
|
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
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "kartrace"
|
|
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 "pry"
|
|
14
|
+
Pry.start
|
data/bin/setup
ADDED
data/kartrace.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "kartrace/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "kartrace"
|
|
8
|
+
spec.version = Kartrace::VERSION
|
|
9
|
+
spec.authors = ["Matheus Barbosa"]
|
|
10
|
+
spec.email = ["matheusb096@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Gem to parse race log"
|
|
13
|
+
spec.description = "Gympass interview test that requires a service that reads and parse a race log and show some results"
|
|
14
|
+
spec.homepage = ""
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
+
spec.add_development_dependency 'pry-byebug'
|
|
28
|
+
end
|
data/lib/.DS_Store
ADDED
|
Binary file
|
data/lib/kartrace.rb
ADDED
data/lib/kartrace/lap.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module KartRace
|
|
2
|
+
class Race
|
|
3
|
+
prepend Services::Command
|
|
4
|
+
|
|
5
|
+
attr_reader :race, :file, :result
|
|
6
|
+
|
|
7
|
+
def initialize(file: nil, race: nil)
|
|
8
|
+
@file = file
|
|
9
|
+
@race = race
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def call
|
|
13
|
+
parse_race
|
|
14
|
+
poleposition
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def best_lap
|
|
18
|
+
race.flat_map(&:laps).min_by(&:time)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def average_race_speed
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def poleposition
|
|
25
|
+
winner = race.find { |r| r.laps.map(&:number).max_by && r.laps.map(&:number).min }
|
|
26
|
+
winner.racer
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def parse_race
|
|
32
|
+
race = File.readlines(file)
|
|
33
|
+
.map { |line| KartRace::Services::Assign.call(line) }
|
|
34
|
+
.inject({}) do |hash, i|
|
|
35
|
+
racer = i[:racer]
|
|
36
|
+
hash[racer] ||= Array.new
|
|
37
|
+
hash[racer] << Lap.new(time: i[:time],
|
|
38
|
+
number: i[:lap_number],
|
|
39
|
+
lap_time: i[:lap_time])
|
|
40
|
+
hash
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
@race = race.map { |racer, laps| Aftermath.new(racer: racer, laps: laps) }.compact
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module KartRace
|
|
2
|
+
class Racer
|
|
3
|
+
attr_reader :name, :number, :average_speed
|
|
4
|
+
|
|
5
|
+
def initialize(number: nil, name: nil, average_speed: nil)
|
|
6
|
+
@number = number
|
|
7
|
+
@name = name
|
|
8
|
+
@average_speed = average_speed
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ==(other)
|
|
12
|
+
self.name == other.name && self.number == other.number
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
alias_method :eql?, :==
|
|
16
|
+
|
|
17
|
+
def hash
|
|
18
|
+
[name, number].hash
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def brasilian?
|
|
22
|
+
%w(F.MASSA R.BARRICHELLO).include? name
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#frozen_string_literal: true
|
|
2
|
+
module KartRace
|
|
3
|
+
module Services
|
|
4
|
+
class Assign
|
|
5
|
+
prepend KartRace::Services::Command
|
|
6
|
+
|
|
7
|
+
RACERLINE = /^(\d{2}:\d{2}:\d{2}\.\d{3})\s+(\d{3}) – ([A-Z]\.[A-Z]+)\s+(\d+)\s+(\d+:\d+\.\d{3})\s+(\d+,\d+)/.freeze
|
|
8
|
+
|
|
9
|
+
attr_reader :line
|
|
10
|
+
|
|
11
|
+
def initialize(line)
|
|
12
|
+
@line = line
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def call
|
|
16
|
+
return unless line.match(RACERLINE)
|
|
17
|
+
{
|
|
18
|
+
time: $1,
|
|
19
|
+
lap_number: $4,
|
|
20
|
+
lap_time: $5,
|
|
21
|
+
average_speed: $6,
|
|
22
|
+
racer: Racer.new(number: $2, name: $3)
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module KartRace
|
|
2
|
+
module Services
|
|
3
|
+
module Command
|
|
4
|
+
|
|
5
|
+
attr_reader :result
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
def call(*args, &block)
|
|
9
|
+
new(*args, &block).call
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.prepended(base)
|
|
14
|
+
base.extend ClassMethods
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def process
|
|
18
|
+
fail NotImplementedError unless defined?(super)
|
|
19
|
+
@result = super
|
|
20
|
+
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/race.log
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
23:49:08.277 038 – F.MASSA 1 1:02.852 44,275
|
|
2
|
+
23:49:10.858 033 – R.BARRICHELLO 1 1:04.352 43,243
|
|
3
|
+
23:49:11.075 002 – K.RAIKKONEN 1 1:04.108 43,408
|
|
4
|
+
23:49:12.667 023 – M.WEBBER 1 1:04.414 43,202
|
|
5
|
+
23:49:30.976 015 – F.ALONSO 1 1:18.456 35,47
|
|
6
|
+
23:50:11.447 038 – F.MASSA 2 1:03.170 44,053
|
|
7
|
+
23:50:14.860 033 – R.BARRICHELLO 2 1:04.002 43,48
|
|
8
|
+
23:50:15.057 002 – K.RAIKKONEN 2 1:03.982 43,493
|
|
9
|
+
23:50:17.472 023 – M.WEBBER 2 1:04.805 42,941
|
|
10
|
+
23:50:37.987 015 – F.ALONSO 2 1:07.011 41,528
|
|
11
|
+
23:51:14.216 038 – F.MASSA 3 1:02.769 44,334
|
|
12
|
+
23:51:18.576 033 – R.BARRICHELLO 3 1:03.716 43,675
|
|
13
|
+
23:51:19.044 002 – K.RAIKKONEN 3 1:03.987 43,49
|
|
14
|
+
23:51:21.759 023 – M.WEBBER 3 1:04.287 43,287
|
|
15
|
+
23:51:46.691 015 – F.ALONSO 3 1:08.704 40,504
|
|
16
|
+
23:52:01.796 011 – S.VETTEL 1 3:31.315 13,169
|
|
17
|
+
23:52:17.003 038 – F.MASS 4 1:02.787 44,321
|
|
18
|
+
23:52:22.586 033 – R.BARRICHELLO 4 1:04.010 43,474
|
|
19
|
+
23:52:22.120 002 – K.RAIKKONEN 4 1:03.076 44,118
|
|
20
|
+
23:52:25.975 023 – M.WEBBER 4 1:04.216 43,335
|
|
21
|
+
23:53:06.741 015 – F.ALONSO 4 1:20.050 34,763
|
|
22
|
+
23:53:39.660 011 – S.VETTEL 2 1:37.864 28,435
|
|
23
|
+
23:54:57.757 011 – S.VETTEL 3 1:18.097 35,633
|
metadata
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kartrace
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Matheus Barbosa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry-byebug
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
description: Gympass interview test that requires a service that reads and parse a
|
|
70
|
+
race log and show some results
|
|
71
|
+
email:
|
|
72
|
+
- matheusb096@gmail.com
|
|
73
|
+
executables: []
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".DS_Store"
|
|
78
|
+
- ".gitignore"
|
|
79
|
+
- ".rspec"
|
|
80
|
+
- ".travis.yml"
|
|
81
|
+
- Gemfile
|
|
82
|
+
- Gemfile.lock
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/setup
|
|
88
|
+
- kartrace.gemspec
|
|
89
|
+
- lib/.DS_Store
|
|
90
|
+
- lib/kartrace.rb
|
|
91
|
+
- lib/kartrace/aftermath.rb
|
|
92
|
+
- lib/kartrace/lap.rb
|
|
93
|
+
- lib/kartrace/race.rb
|
|
94
|
+
- lib/kartrace/racer.rb
|
|
95
|
+
- lib/kartrace/services/assign.rb
|
|
96
|
+
- lib/kartrace/services/command.rb
|
|
97
|
+
- lib/kartrace/version.rb
|
|
98
|
+
- race.log
|
|
99
|
+
homepage: ''
|
|
100
|
+
licenses:
|
|
101
|
+
- MIT
|
|
102
|
+
metadata: {}
|
|
103
|
+
post_install_message:
|
|
104
|
+
rdoc_options: []
|
|
105
|
+
require_paths:
|
|
106
|
+
- lib
|
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '0'
|
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
requirements: []
|
|
118
|
+
rubyforge_project:
|
|
119
|
+
rubygems_version: 2.7.6
|
|
120
|
+
signing_key:
|
|
121
|
+
specification_version: 4
|
|
122
|
+
summary: Gem to parse race log
|
|
123
|
+
test_files: []
|