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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/quake_parser.rb +26 -3
  3. metadata +2 -3
  4. data/lib/main.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4e2bb10a2ec81e337ae119c6c67b26d5f2f729fa28dbe57b6ff194c91d21d20
4
- data.tar.gz: 8d60157d949882454a33e4ebd15957072fe2c94291b4f8bc510a764201f31fa8
3
+ metadata.gz: 1fca04c6680665bcc91ce11c5f2c445bdbfbacf145b917c6e2b33b441a22f657
4
+ data.tar.gz: 2ecc7fb221262d3c2a0b5ecdf80494a1d2fca3659fde5197dff6378ad3be6128
5
5
  SHA512:
6
- metadata.gz: bff772913f2af1f5c620237a5cc7eda014bf3742486dcaefd5b15dd9e8df64c0201f9ab324db2746a26a2cb081f4a35d9be17abd3f54f27b8a3cca01cd01075c
7
- data.tar.gz: f764392cc28ef328c80ab8672965e4111653bb4992ff9c60e71de7c41e547fa1cc7268bbcbfd6425194232a5e1d9b648126e8d9aa10572f86c886d16ac918d12
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
- main = QuakeParser::Main.new(file_path)
8
- main.execute
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.2
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-04 00:00:00.000000000 Z
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