csstats 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +3 -3
- data/README.md +6 -5
- data/csstats.gemspec +8 -7
- data/lib/csstats/error.rb +1 -0
- data/lib/csstats/handler.rb +48 -33
- data/lib/csstats/version.rb +1 -1
- data/spec/csstats/handler_spec.rb +4 -3
- data/spec/csstats_spec.rb +5 -3
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62ca403d7af2f0c4e360b2aad4b7aa8b4c0d1adb
|
4
|
+
data.tar.gz: a105d30eabbae88b37c8e78b4517bf52da96dd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64915feabd7078daea341085c861ea05ef04d0324ec0ffbece9586975fa85d1ef529a28ce9b69e26edea59614e198701c1357c85cb348b13eb9f2688fcc42e5b
|
7
|
+
data.tar.gz: adfe45bb877909a1d9aa7bc27a65fac035485b1be9fc9d5393d143e1cd2894a07565a9ddbeb822553f2c0bdbc77957218a793600ec86852cdb629b77dd02e829
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,9 +3,9 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'rake'
|
4
4
|
|
5
5
|
group :test do
|
6
|
-
gem 'coveralls', '~> 0.
|
7
|
-
gem 'rspec', '~> 3.
|
8
|
-
gem 'simplecov', '~> 0.
|
6
|
+
gem 'coveralls', '~> 0.8.1', require: false
|
7
|
+
gem 'rspec', '~> 3.2.0'
|
8
|
+
gem 'simplecov', '~> 0.10.0', require: false
|
9
9
|
end
|
10
10
|
|
11
11
|
gemspec
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# CSstats
|
2
2
|
|
3
|
-
[![Gem Version](http://img.shields.io/gem/v/csstats.svg?style=flat)][rubygems]
|
4
|
-
[![Build Status](http://img.shields.io/travis/jpalumickas/csstats/master.svg?style=flat)][travis]
|
5
|
-
[![Dependency Status](http://img.shields.io/gemnasium/jpalumickas/csstats.svg?style=flat)][gemnasium]
|
6
|
-
[![Coverage Status](https://img.shields.io/coveralls/jpalumickas/csstats.svg?branch=master&style=flat)][coveralls]
|
7
|
-
[![Code Climate](https://img.shields.io/codeclimate/github/jpalumickas/csstats.svg?style=flat)][codeclimate]
|
3
|
+
[![Gem Version](http://img.shields.io/gem/v/csstats.svg?style=flat-square)][rubygems]
|
4
|
+
[![Build Status](http://img.shields.io/travis/jpalumickas/csstats/master.svg?style=flat-square)][travis]
|
5
|
+
[![Dependency Status](http://img.shields.io/gemnasium/jpalumickas/csstats.svg?style=flat-square)][gemnasium]
|
6
|
+
[![Coverage Status](https://img.shields.io/coveralls/jpalumickas/csstats.svg?branch=master&style=flat-square)][coveralls]
|
7
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/jpalumickas/csstats.svg?style=flat-square)][codeclimate]
|
8
8
|
|
9
9
|
Gem which handle `csstats.dat` file generated by CSX module
|
10
10
|
in AMX Mod X ([http://www.amxmodx.org/][amxx])
|
@@ -58,6 +58,7 @@ implementations:
|
|
58
58
|
* Ruby 1.9.3
|
59
59
|
* Ruby 2.0.0
|
60
60
|
* Ruby 2.1.0
|
61
|
+
* Ruby 2.2.0
|
61
62
|
|
62
63
|
## Copyright
|
63
64
|
Copyright (c) 2013 Justas Palumickas.
|
data/csstats.gemspec
CHANGED
@@ -10,16 +10,17 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = 'jpalumickas@gmail.com'
|
11
11
|
gem.homepage = 'https://github.com/jpalumickas/csstats/'
|
12
12
|
gem.summary = gem.description
|
13
|
-
gem.description =
|
14
|
-
|
13
|
+
gem.description = 'Gem which handle csstats.dat file generated by CSX' \
|
14
|
+
' module in AMX Mod X (http://www.amxmodx.org/)'
|
15
15
|
|
16
|
+
gem.license = 'MIT'
|
16
17
|
gem.required_ruby_version = '>= 1.9.2'
|
17
18
|
|
18
|
-
gem.files = `git ls-files`.split(
|
19
|
-
gem.executables = gem.files.grep(
|
20
|
-
gem.test_files = gem.files.grep(
|
19
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
20
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
21
22
|
gem.require_paths = ['lib']
|
22
23
|
|
23
|
-
gem.add_dependency 'hashie', '~> 3.
|
24
|
-
gem.add_development_dependency 'bundler', '~> 1.
|
24
|
+
gem.add_dependency 'hashie', '~> 3.4'
|
25
|
+
gem.add_development_dependency 'bundler', '~> 1.6'
|
25
26
|
end
|
data/lib/csstats/error.rb
CHANGED
data/lib/csstats/handler.rb
CHANGED
@@ -2,7 +2,7 @@ require 'hashie/mash'
|
|
2
2
|
|
3
3
|
module CSstats
|
4
4
|
class Handler
|
5
|
-
attr_reader :path, :players
|
5
|
+
attr_reader :path, :players, :maxplayers
|
6
6
|
|
7
7
|
# Public: Initialize file.
|
8
8
|
#
|
@@ -13,25 +13,15 @@ module CSstats
|
|
13
13
|
# Returns nothing.
|
14
14
|
def initialize(options = {})
|
15
15
|
@path = options[:path]
|
16
|
-
@
|
17
|
-
return if path.nil?
|
18
|
-
|
19
|
-
maxplayers = options[:maxplayers] || 0
|
16
|
+
@maxplayers = options[:maxplayers] || 0
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
@players = []
|
19
|
+
fail CSstats::FileNotExist unless File.exist?(path.to_s)
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
player = read_player(file)
|
21
|
+
@file = File.new(path, 'r')
|
22
|
+
_file_version = read_short_data(@file)
|
27
23
|
|
28
|
-
|
29
|
-
player['rank'] = i + 1
|
30
|
-
players[i] = player
|
31
|
-
end
|
32
|
-
|
33
|
-
i += 1
|
34
|
-
end
|
24
|
+
read_players!
|
35
25
|
end
|
36
26
|
|
37
27
|
# Public: Get the player information of specified id.
|
@@ -61,6 +51,20 @@ module CSstats
|
|
61
51
|
|
62
52
|
private
|
63
53
|
|
54
|
+
def read_players!
|
55
|
+
i = 0
|
56
|
+
while !@file.eof? && (maxplayers == 0 || i < maxplayers)
|
57
|
+
player = read_player(@file)
|
58
|
+
|
59
|
+
if player
|
60
|
+
player['rank'] = i + 1
|
61
|
+
players[i] = player
|
62
|
+
end
|
63
|
+
|
64
|
+
i += 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
64
68
|
# Internal: Count player efficiency.
|
65
69
|
#
|
66
70
|
# kills - The Integer of player kills in game.
|
@@ -88,27 +92,38 @@ module CSstats
|
|
88
92
|
# Returns The Mash of player information.
|
89
93
|
def read_player(handle)
|
90
94
|
length = read_short_data(handle)
|
91
|
-
return
|
95
|
+
return if length == 0
|
92
96
|
|
93
|
-
|
97
|
+
player_data = Hashie::Mash.new
|
94
98
|
|
95
|
-
|
99
|
+
player_data.nick = read_string_data(handle, length)
|
100
|
+
|
101
|
+
add_player_uniq(player_data, handle)
|
102
|
+
add_player_general_data(player_data, handle)
|
103
|
+
add_player_calculations(player_data)
|
104
|
+
|
105
|
+
player_data
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_player_uniq(player_data, handle)
|
96
109
|
length = read_short_data(handle)
|
97
|
-
|
110
|
+
player_data.uniq = read_string_data(handle, length)
|
111
|
+
end
|
98
112
|
|
99
|
-
|
100
|
-
|
101
|
-
|
113
|
+
def add_player_general_data(player_data, handle)
|
114
|
+
data_types = %w(teamkill damage deaths kills shots hits headshots
|
115
|
+
defusions defused plants explosions - head chest stomach
|
116
|
+
leftarm rightarm leftleg rightleg -)
|
102
117
|
|
103
|
-
|
118
|
+
data_types.each { |type| player_data[type] = read_int_data(handle) }
|
104
119
|
|
105
120
|
# Remove all 0x00000000
|
106
|
-
|
107
|
-
|
108
|
-
mash.acc = count_accuracy(mash.hits, mash.shots)
|
109
|
-
mash.eff = count_efficiency(mash.kills, mash.deaths)
|
121
|
+
player_data.tap { |x| x.delete('-') }
|
122
|
+
end
|
110
123
|
|
111
|
-
|
124
|
+
def add_player_calculations(player_data)
|
125
|
+
player_data.acc = count_accuracy(player_data.hits, player_data.shots)
|
126
|
+
player_data.eff = count_efficiency(player_data.kills, player_data.deaths)
|
112
127
|
end
|
113
128
|
|
114
129
|
# Internal: Get the 32bit integer from file.
|
@@ -118,7 +133,7 @@ module CSstats
|
|
118
133
|
# Returns the Integer.
|
119
134
|
def read_int_data(handle)
|
120
135
|
data = handle.read(4)
|
121
|
-
|
136
|
+
fail CSstats::Error, 'Cannot read int data.' unless data
|
122
137
|
|
123
138
|
data.unpack('V').first
|
124
139
|
end
|
@@ -130,7 +145,7 @@ module CSstats
|
|
130
145
|
# Returns the Integer.
|
131
146
|
def read_short_data(handle)
|
132
147
|
data = handle.read(2)
|
133
|
-
|
148
|
+
fail CSstats::Error, 'Cannot read short data.' unless data
|
134
149
|
|
135
150
|
data.unpack('v').first
|
136
151
|
end
|
@@ -143,7 +158,7 @@ module CSstats
|
|
143
158
|
# Returns the String.
|
144
159
|
def read_string_data(handle, length)
|
145
160
|
data = handle.read(length)
|
146
|
-
|
161
|
+
fail CSstats::Error, 'Cannot read string data.' unless data
|
147
162
|
|
148
163
|
data.strip
|
149
164
|
end
|
data/lib/csstats/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CSstats::Handler do
|
4
|
-
|
5
4
|
before do
|
6
5
|
@handler = CSstats::Handler.new(path: csstats_file, maxplayers: 15)
|
7
6
|
end
|
@@ -15,7 +14,6 @@ describe CSstats::Handler do
|
|
15
14
|
end
|
16
15
|
|
17
16
|
describe 'player with specified name' do
|
18
|
-
|
19
17
|
before do
|
20
18
|
@player = @handler.search_by_name('CHMARSON')
|
21
19
|
end
|
@@ -33,7 +31,7 @@ describe CSstats::Handler do
|
|
33
31
|
end
|
34
32
|
|
35
33
|
it 'should return correct player damage' do
|
36
|
-
expect(@player.damage).to eq
|
34
|
+
expect(@player.damage).to eq 101_543
|
37
35
|
end
|
38
36
|
|
39
37
|
it 'should return correct player deaths' do
|
@@ -108,5 +106,8 @@ describe CSstats::Handler do
|
|
108
106
|
expect(@player.eff).to eq 59.76
|
109
107
|
end
|
110
108
|
|
109
|
+
it 'should not return empty data' do
|
110
|
+
expect(@player['-']).to eq nil
|
111
|
+
end
|
111
112
|
end
|
112
113
|
end
|
data/spec/csstats_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CSstats do
|
4
|
-
|
5
4
|
describe '.new' do
|
6
5
|
it 'is a CSstats::Handler' do
|
7
|
-
expect(CSstats.new).to be_a CSstats::Handler
|
6
|
+
expect(CSstats.new(path: csstats_file)).to be_a CSstats::Handler
|
8
7
|
end
|
9
|
-
end
|
10
8
|
|
9
|
+
it 'is a CSstats::FileNotFound if file path empty' do
|
10
|
+
expect { CSstats.new }.to raise_error(CSstats::FileNotExist)
|
11
|
+
end
|
12
|
+
end
|
11
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Palumickas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -16,30 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.6'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
41
|
-
description:
|
42
|
-
X (http://www.amxmodx.org/)
|
40
|
+
version: '1.6'
|
41
|
+
description: Gem which handle csstats.dat file generated by CSX module in AMX Mod
|
42
|
+
X (http://www.amxmodx.org/)
|
43
43
|
email: jpalumickas@gmail.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
@@ -47,6 +47,7 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
49
|
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
50
51
|
- ".travis.yml"
|
51
52
|
- CONTRIBUTING.md
|
52
53
|
- Gemfile
|
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.4.5
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: ''
|