quake_parser 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quake_parser.rb +26 -3
- metadata +2 -3
- data/lib/main.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fca04c6680665bcc91ce11c5f2c445bdbfbacf145b917c6e2b33b441a22f657
|
4
|
+
data.tar.gz: 2ecc7fb221262d3c2a0b5ecdf80494a1d2fca3659fde5197dff6378ad3be6128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 747c4b500feacca2018ecbf58047152da13089ccef42cecfe21634095542b99d6c354b846c71fdc55c648162a738054ee686ba05f213af82d5f71124697a2c18
|
7
|
+
data.tar.gz: 94730de8798224dff4418417d0034d6147652320fd54fd39fb8a442657cb161b0fdd4a71d82e7484e1f4a5d3494e08f5df3c000aef1e8dd805b60ceff2b08c02
|
data/lib/quake_parser.rb
CHANGED
@@ -1,10 +1,33 @@
|
|
1
|
-
require_relative 'main'
|
2
1
|
require_relative 'parser'
|
3
2
|
require_relative 'game'
|
4
3
|
|
5
4
|
module QuakeParser
|
6
5
|
def self.run(file_path)
|
7
|
-
|
8
|
-
|
6
|
+
raise Errno::ENOENT, "File not found or unreadable: #{file_path}" unless File.exist?(file_path)
|
7
|
+
|
8
|
+
@parser = QuakeParser::Parser.new(File.read(file_path))
|
9
|
+
@parser.parse_file
|
10
|
+
{ games: get_games, ranking: get_ranking }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_games
|
14
|
+
games_data = []
|
15
|
+
@parser.games.each { |game| games_data << game.convert_data_to_hash if game }
|
16
|
+
games_data
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_ranking
|
20
|
+
scores = Hash.new(0)
|
21
|
+
|
22
|
+
@parser.games.each do |game|
|
23
|
+
next unless game
|
24
|
+
|
25
|
+
game.kills.each do |key, value|
|
26
|
+
scores[key] += value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ranking = scores.sort_by { |_key, value| -value }.to_h
|
31
|
+
ranking
|
9
32
|
end
|
10
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quake_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -46,7 +46,6 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- lib/game.rb
|
49
|
-
- lib/main.rb
|
50
49
|
- lib/parser.rb
|
51
50
|
- lib/quake_parser.rb
|
52
51
|
homepage: https://github.com/yasmincrisostomo/quake_parser
|
data/lib/main.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require_relative 'parser'
|
2
|
-
|
3
|
-
module QuakeParser
|
4
|
-
class Main
|
5
|
-
def initialize(file_path)
|
6
|
-
raise Errno::ENOENT, "File not found or unreadable: #{file_path}" unless File.exist?(file_path)
|
7
|
-
|
8
|
-
@parser = QuakeParser::Parser.new(File.read(file_path))
|
9
|
-
end
|
10
|
-
|
11
|
-
def execute
|
12
|
-
@parser.parse_file
|
13
|
-
print_games
|
14
|
-
print_ranking
|
15
|
-
end
|
16
|
-
|
17
|
-
def print_games
|
18
|
-
@parser.games.each { |game| puts game.convert_data_to_json if game }
|
19
|
-
end
|
20
|
-
|
21
|
-
def print_ranking
|
22
|
-
scores = Hash.new(0)
|
23
|
-
|
24
|
-
@parser.games.each do |game|
|
25
|
-
next unless game
|
26
|
-
|
27
|
-
game.kills.each do |key, value|
|
28
|
-
scores[key] += value
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
ranking = scores.sort_by { |_key, value| -value }.to_h
|
33
|
-
puts "global_ranking: #{JSON.pretty_generate(ranking)}\n"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|