csstats 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/csstats.gemspec +1 -1
- data/lib/csstats.rb +2 -2
- data/lib/csstats/error.rb +1 -1
- data/lib/csstats/handler.rb +36 -37
- data/lib/csstats/version.rb +1 -1
- data/spec/csstats/handler_spec.rb +7 -7
- data/spec/csstats_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6872b7c03f06e7dd770c35a07cd90aaed879ecd
|
4
|
+
data.tar.gz: 3834dbf6a0af008ce011d01f182e72c8249fe1a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2ef9f0ac0f3cfbd024eb17f3ae4bad43ca8cf81a715a39c8114744aea8f244a671a5896c231f83895fb42fe3b3c1829f4a8daa5215303f6b3192504c357d87b
|
7
|
+
data.tar.gz: 593d29515df36cef84ea29e4e3141b659982b24b6b90a513fb92cccf5254b5a620415a0156a5d1ec31ad17420cfaa15f9d19527581c644b74ba1e4e149046093
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -44,7 +44,9 @@ You can find player by specified name.
|
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
stats = CSstats.new(path: 'csstats.dat')
|
47
|
-
stats.search_by_name('nick')
|
47
|
+
player_stats = stats.search_by_name('nick')
|
48
|
+
|
49
|
+
puts player_stats.kills
|
48
50
|
```
|
49
51
|
|
50
52
|
## Supported Ruby Versions
|
@@ -67,4 +69,4 @@ See [LICENSE][] for details.
|
|
67
69
|
[codeclimate]: https://codeclimate.com/github/jpalumickas/csstats
|
68
70
|
|
69
71
|
[amxx]: http://www.amxmodx.org/
|
70
|
-
[license]: LICENSE.md
|
72
|
+
[license]: LICENSE.md
|
data/Rakefile
CHANGED
data/csstats.gemspec
CHANGED
data/lib/csstats.rb
CHANGED
data/lib/csstats/error.rb
CHANGED
data/lib/csstats/handler.rb
CHANGED
@@ -2,30 +2,29 @@ require 'hashie/mash'
|
|
2
2
|
|
3
3
|
module CSstats
|
4
4
|
class Handler
|
5
|
-
|
5
|
+
attr_reader :path, :players
|
6
6
|
|
7
|
-
# Initialize file.
|
7
|
+
# Public: Initialize file.
|
8
8
|
#
|
9
|
-
#
|
10
|
-
# path
|
11
|
-
# maxplayers - The Integer of how many players to return.
|
9
|
+
# options - The Hash options:
|
10
|
+
# :path - The String of csstats.dat file path (required).
|
11
|
+
# :maxplayers - The Integer of how many players to return (optional).
|
12
12
|
#
|
13
13
|
# Returns nothing.
|
14
|
-
def initialize(options={})
|
14
|
+
def initialize(options = {})
|
15
15
|
@path = options[:path]
|
16
16
|
@players = []
|
17
|
-
|
18
|
-
@position = 1
|
17
|
+
|
19
18
|
maxplayers = options[:maxplayers] || 0
|
20
19
|
|
21
20
|
return if @path.nil?
|
22
21
|
|
23
|
-
handle = File.new(@path,
|
22
|
+
handle = File.new(@path, 'r')
|
24
23
|
|
25
|
-
@
|
24
|
+
@file_version = read_short_data(handle)
|
26
25
|
|
27
26
|
i = 0
|
28
|
-
while
|
27
|
+
while !handle.eof? && (maxplayers == 0 || i < maxplayers)
|
29
28
|
player = read_player(handle)
|
30
29
|
if player
|
31
30
|
player['rank'] = i + 1
|
@@ -35,15 +34,15 @@ module CSstats
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
# Read player information from file.
|
37
|
+
# Internal: Read player information from file.
|
39
38
|
#
|
40
39
|
# handle - The File which was opened for reading data.
|
41
40
|
#
|
42
|
-
# Returns The
|
41
|
+
# Returns The Mash of player information.
|
43
42
|
def read_player(handle)
|
44
|
-
length = read_short_data(handle)
|
43
|
+
length = read_short_data(handle)
|
45
44
|
|
46
|
-
return nil if
|
45
|
+
return nil if length == 0
|
47
46
|
|
48
47
|
mash = Hashie::Mash.new
|
49
48
|
|
@@ -74,57 +73,57 @@ module CSstats
|
|
74
73
|
mash.leftleg = read_int_data(handle)
|
75
74
|
mash.rightleg = read_int_data(handle)
|
76
75
|
|
77
|
-
mash.acc = mash.hits / mash.shots * 100
|
78
|
-
mash.eff = mash.kills / (mash.kills + mash.deaths) * 100
|
76
|
+
mash.acc = mash.hits.to_f / mash.shots.to_f * 100
|
77
|
+
mash.eff = mash.kills.to_f / (mash.kills.to_f + mash.deaths.to_f) * 100
|
79
78
|
|
80
79
|
read_int_data(handle) # 0x00000000
|
81
80
|
|
82
|
-
|
81
|
+
mash
|
83
82
|
end
|
84
83
|
|
85
|
-
# Get the 32bit integer from file.
|
84
|
+
# Internal: Get the 32bit integer from file.
|
86
85
|
#
|
87
86
|
# handle - The File which was opened for reading data.
|
88
87
|
#
|
89
|
-
# Returns the
|
88
|
+
# Returns the Integer.
|
90
89
|
def read_int_data(handle)
|
91
90
|
data = handle.read(4)
|
92
|
-
raise CSstats::Error,
|
93
|
-
|
91
|
+
raise CSstats::Error, 'Cannot read int data.' unless data
|
92
|
+
data.unpack('V').first
|
94
93
|
end
|
95
94
|
|
96
|
-
# Get the 16bit integer from file.
|
95
|
+
# Internal: Get the 16bit integer from file.
|
97
96
|
#
|
98
97
|
# handle - The File which was opened for reading data.
|
99
98
|
#
|
100
|
-
# Returns the
|
99
|
+
# Returns the Integer.
|
101
100
|
def read_short_data(handle)
|
102
101
|
data = handle.read(2)
|
103
|
-
raise CSstats::Error,
|
104
|
-
|
102
|
+
raise CSstats::Error, 'Cannot read short data.' unless data
|
103
|
+
data.unpack('v').first
|
105
104
|
end
|
106
105
|
|
107
|
-
# Get the
|
106
|
+
# Internal: Get the String from file.
|
108
107
|
#
|
109
108
|
# handle - The File which was opened for reading data.
|
110
|
-
# len
|
109
|
+
# len - The Integer length of string to read.
|
111
110
|
#
|
112
|
-
# Returns the
|
111
|
+
# Returns the String.
|
113
112
|
def read_string_data(handle, length)
|
114
113
|
data = handle.read(length)
|
115
|
-
raise CSstats::Error,
|
114
|
+
raise CSstats::Error, 'Cannot read string data.' unless data
|
116
115
|
data = data.strip
|
117
|
-
|
116
|
+
data
|
118
117
|
end
|
119
118
|
|
120
|
-
# Get the player information of specified id.
|
119
|
+
# Internal: Get the player information of specified id.
|
121
120
|
#
|
122
121
|
# id - The Integer of player id.
|
123
122
|
#
|
124
|
-
# Returns the
|
123
|
+
# Returns the Mash of player information.
|
125
124
|
def player(id)
|
126
|
-
unless
|
127
|
-
@players[id-1]
|
125
|
+
unless @players[id - 1].nil?
|
126
|
+
@players[id - 1]
|
128
127
|
end
|
129
128
|
end
|
130
129
|
|
@@ -139,10 +138,10 @@ module CSstats
|
|
139
138
|
#
|
140
139
|
# name - The String of player name.
|
141
140
|
#
|
142
|
-
# Returns the
|
141
|
+
# Returns the Mash of player information.
|
143
142
|
def search_by_name(name)
|
144
143
|
@players.each do |player|
|
145
|
-
return player if
|
144
|
+
return player if name == player.nick
|
146
145
|
end
|
147
146
|
end
|
148
147
|
end
|
data/lib/csstats/version.rb
CHANGED
@@ -6,17 +6,17 @@ describe CSstats::Handler do
|
|
6
6
|
@handler = CSstats::Handler.new(path: csstats_file, maxplayers: 15)
|
7
7
|
end
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'should return corrent players count' do
|
10
10
|
expect(@handler.players_count).to eq 15
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
14
|
-
expect(@handler.player(2).nick).to eq
|
13
|
+
it 'should return correct player data' do
|
14
|
+
expect(@handler.player(2).nick).to eq 'CHMARSON'
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
player = @handler.search_by_name(
|
19
|
-
expect(player.nick).to eq
|
17
|
+
it 'should return searched player' do
|
18
|
+
player = @handler.search_by_name('CHMARSON')
|
19
|
+
expect(player.nick).to eq 'CHMARSON'
|
20
20
|
end
|
21
21
|
|
22
|
-
end
|
22
|
+
end
|
data/spec/csstats_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Palumickas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|