antw-dyno 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/dyno/parsers/gtr2_parser.rb +1 -1
- data/lib/dyno/parsers/race07_parser.rb +21 -10
- data/lib/dyno/parsers/rfactor_parser.rb +3 -4
- data/spec/parsers/race07_parser_spec.rb +49 -21
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -3,7 +3,7 @@ module Dyno::Parsers
|
|
3
3
|
# Parses a Race 07 results file which are almost identical to Race 07 files.
|
4
4
|
#
|
5
5
|
class GTR2Parser < Race07Parser
|
6
|
-
def self.parse_file( filename )
|
6
|
+
def self.parse_file( filename, mode = :race )
|
7
7
|
# GTR2 files start with a line which isn't valid INI; remove it.
|
8
8
|
parse( IniParse.parse(
|
9
9
|
File.read( filename ).sub!(/^.*\n/, '')
|
@@ -7,10 +7,14 @@ module Dyno::Parsers
|
|
7
7
|
##
|
8
8
|
# Takes a file path and parses it.
|
9
9
|
#
|
10
|
-
# @param [String] filename
|
10
|
+
# @param [String] filename
|
11
|
+
# The path to the results file.
|
12
|
+
# @param [Symbol] mode
|
13
|
+
# The order in which competitors should be ordered. Race mode uses the
|
14
|
+
# normal means, while :lap will order by their fastest lap.
|
11
15
|
#
|
12
|
-
def self.parse_file( filename )
|
13
|
-
parse( IniParse.open( filename ) )
|
16
|
+
def self.parse_file( filename, mode = :race )
|
17
|
+
parse( IniParse.open( filename ), mode )
|
14
18
|
end
|
15
19
|
|
16
20
|
##
|
@@ -20,8 +24,8 @@ module Dyno::Parsers
|
|
20
24
|
# @param [IniParse::Document] results The results.
|
21
25
|
# @return [Dyno::Event]
|
22
26
|
#
|
23
|
-
def self.parse( results )
|
24
|
-
new( results ).parse
|
27
|
+
def self.parse( results, mode = :race )
|
28
|
+
new( results, mode ).parse
|
25
29
|
end
|
26
30
|
|
27
31
|
##
|
@@ -42,8 +46,8 @@ module Dyno::Parsers
|
|
42
46
|
#
|
43
47
|
# @param [IniParse::Document] results The results.
|
44
48
|
#
|
45
|
-
def initialize( results )
|
46
|
-
@raw = results
|
49
|
+
def initialize( results, mode = :race )
|
50
|
+
@raw, @mode = results, mode
|
47
51
|
end
|
48
52
|
|
49
53
|
##
|
@@ -105,9 +109,16 @@ module Dyno::Parsers
|
|
105
109
|
end
|
106
110
|
end
|
107
111
|
|
108
|
-
|
109
|
-
|
110
|
-
|
112
|
+
if @mode == :race
|
113
|
+
# Sort finished competitors by their race time, lowest (P1) first.
|
114
|
+
finished_competitors = finished_competitors.sort_by do |c|
|
115
|
+
[ - c.laps, c.race_time ]
|
116
|
+
end
|
117
|
+
else
|
118
|
+
# Sort finished competitors by their best lap time.
|
119
|
+
finished_competitors = finished_competitors.sort_by do |c|
|
120
|
+
c.best_lap
|
121
|
+
end
|
111
122
|
end
|
112
123
|
|
113
124
|
# ... and DNF'ed competitors by how many laps they've done.
|
@@ -8,9 +8,8 @@ module Dyno::Parsers
|
|
8
8
|
#
|
9
9
|
# @param [String] filename The path to the results file.
|
10
10
|
#
|
11
|
-
def self.parse_file( filename )
|
12
|
-
xmlparser = LibXML::XML::Parser.
|
13
|
-
xmlparser.file = filename
|
11
|
+
def self.parse_file( filename, mode = nil )
|
12
|
+
xmlparser = LibXML::XML::Parser.file( filename )
|
14
13
|
parse( xmlparser.parse )
|
15
14
|
end
|
16
15
|
|
@@ -21,7 +20,7 @@ module Dyno::Parsers
|
|
21
20
|
# @param [LibXML::XML::Document] results The results.
|
22
21
|
# @return [Dyno::Event]
|
23
22
|
#
|
24
|
-
def self.parse( results )
|
23
|
+
def self.parse( results, mode = nil )
|
25
24
|
new( results ).parse
|
26
25
|
end
|
27
26
|
|
@@ -119,27 +119,6 @@ describe Dyno::Parsers::Race07Parser do
|
|
119
119
|
]
|
120
120
|
end
|
121
121
|
|
122
|
-
it 'should correctly sort drivers by their finishing time, and assign their position' do
|
123
|
-
event = Dyno::Parsers::Race07Parser.parse_file(
|
124
|
-
'spec/fixtures/race07/full.ini'
|
125
|
-
)
|
126
|
-
|
127
|
-
event.competitors[0].name.should == 'Gabriel Lloyd'
|
128
|
-
event.competitors[0].position.should == 1
|
129
|
-
|
130
|
-
event.competitors[1].name.should == 'Jerry Lalich'
|
131
|
-
event.competitors[1].position.should == 2
|
132
|
-
|
133
|
-
event.competitors[2].name.should == 'Mark Voss'
|
134
|
-
event.competitors[2].position.should == 3
|
135
|
-
|
136
|
-
event.competitors[3].name.should == 'Corey Ball'
|
137
|
-
event.competitors[3].position.should == 4
|
138
|
-
|
139
|
-
event.competitors[4].name.should == 'Reino Lintula'
|
140
|
-
event.competitors[4].position.should == 5
|
141
|
-
end
|
142
|
-
|
143
122
|
it 'should set a competitor as "did not finish" when necessary' do
|
144
123
|
Dyno::Parsers::Race07Parser.parse_file(
|
145
124
|
'spec/fixtures/race07/single_driver_dnf.ini'
|
@@ -151,5 +130,54 @@ describe Dyno::Parsers::Race07Parser do
|
|
151
130
|
'spec/fixtures/race07/single_driver_dsq.ini'
|
152
131
|
).competitors[0].should be_dsq
|
153
132
|
end
|
133
|
+
|
134
|
+
describe 'when in race mode' do
|
135
|
+
it 'should sort drivers by their finishing time, and assign '\
|
136
|
+
'their position' do
|
137
|
+
event = Dyno::Parsers::Race07Parser.parse_file(
|
138
|
+
'spec/fixtures/race07/full.ini'
|
139
|
+
)
|
140
|
+
|
141
|
+
event.competitors[0].name.should == 'Gabriel Lloyd'
|
142
|
+
event.competitors[0].position.should == 1
|
143
|
+
|
144
|
+
event.competitors[1].name.should == 'Jerry Lalich'
|
145
|
+
event.competitors[1].position.should == 2
|
146
|
+
|
147
|
+
event.competitors[2].name.should == 'Mark Voss'
|
148
|
+
event.competitors[2].position.should == 3
|
149
|
+
|
150
|
+
event.competitors[3].name.should == 'Corey Ball'
|
151
|
+
event.competitors[3].position.should == 4
|
152
|
+
|
153
|
+
event.competitors[4].name.should == 'Reino Lintula'
|
154
|
+
event.competitors[4].position.should == 5
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe 'when in lap mode' do
|
159
|
+
it 'should sort drivers by their fastest lap, and assign their ' \
|
160
|
+
'position' do
|
161
|
+
event = Dyno::Parsers::Race07Parser.parse_file(
|
162
|
+
'spec/fixtures/race07/full.ini', :lap
|
163
|
+
)
|
164
|
+
|
165
|
+
event.competitors[0].name.should == 'Jerry Lalich'
|
166
|
+
event.competitors[0].position.should == 1
|
167
|
+
|
168
|
+
event.competitors[1].name.should == 'Gabriel Lloyd'
|
169
|
+
event.competitors[1].position.should == 2
|
170
|
+
|
171
|
+
event.competitors[2].name.should == 'Mark Voss'
|
172
|
+
event.competitors[2].position.should == 3
|
173
|
+
|
174
|
+
event.competitors[3].name.should == 'Corey Ball'
|
175
|
+
event.competitors[3].position.should == 4
|
176
|
+
|
177
|
+
event.competitors[4].name.should == 'Reino Lintula'
|
178
|
+
event.competitors[4].position.should == 5
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
154
182
|
end
|
155
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antw-dyno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|