quake_parser 0.1.3 → 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 -4
  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: b0debba2b9d2fc5393e6c5389be892702f875d4660237b04983b40a094ccb32e
4
- data.tar.gz: 35e618de009c2174e7484d23570c12476581b759343c1d5bca8f3beecb477089
3
+ metadata.gz: 1fca04c6680665bcc91ce11c5f2c445bdbfbacf145b917c6e2b33b441a22f657
4
+ data.tar.gz: 2ecc7fb221262d3c2a0b5ecdf80494a1d2fca3659fde5197dff6378ad3be6128
5
5
  SHA512:
6
- metadata.gz: 2d1c97948995afe19fa7c3abbde6c105e3cb04fface10891151081cf636bc09de0245eddb0a8a86129c8d41be15c21ccecda1d8f120d2b100618c2e75c78ce30
7
- data.tar.gz: 7468ad3d52329855024f88463aadd6f52852bccb17f64d5d155fd7a0a00702debf81952ce915de92b142b5f056d719b6044ed39d747e2ae26580d97e1499fe54
6
+ metadata.gz: 747c4b500feacca2018ecbf58047152da13089ccef42cecfe21634095542b99d6c354b846c71fdc55c648162a738054ee686ba05f213af82d5f71124697a2c18
7
+ data.tar.gz: 94730de8798224dff4418417d0034d6147652320fd54fd39fb8a442657cb161b0fdd4a71d82e7484e1f4a5d3494e08f5df3c000aef1e8dd805b60ceff2b08c02
data/lib/quake_parser.rb CHANGED
@@ -1,11 +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.parser_and_print
9
- { games: main.get_games, ranking: main.get_ranking }
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
10
32
  end
11
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.3
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 parser_and_print
12
- @parser.parse_file
13
- end
14
-
15
- def get_games
16
- games_data = []
17
- @parser.games.each { |game| games_data << game.convert_data_to_hash if game }
18
- games_data
19
- end
20
-
21
- def get_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
- ranking
34
- end
35
- end
36
- end