csstats 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecb9899a0509a548c484782f274c9a2977b85e9f
4
- data.tar.gz: 35da68649b1d7dc15d54caaceed2b394b8482552
3
+ metadata.gz: d6872b7c03f06e7dd770c35a07cd90aaed879ecd
4
+ data.tar.gz: 3834dbf6a0af008ce011d01f182e72c8249fe1a5
5
5
  SHA512:
6
- metadata.gz: c092e09b2b2174c8fe65c487d9ae2e5896be3339b54f130fa0da9b81302376abc50dd18cc51a1392866daefd7d13f824b61956c8d93a0832d814607ca9f3eb2b
7
- data.tar.gz: ae13b4f5c2b321b47e8d91faa62f5826221d9e526b92f0e6ee064f8182a5a1860900f19a88e5c93deeda9a5f05462be63b3cdb3f810638a7ea2b9e4768619c42
6
+ metadata.gz: d2ef9f0ac0f3cfbd024eb17f3ae4bad43ca8cf81a715a39c8114744aea8f244a671a5896c231f83895fb42fe3b3c1829f4a8daa5215303f6b3192504c357d87b
7
+ data.tar.gz: 593d29515df36cef84ea29e4e3141b659982b24b6b90a513fb92cccf5254b5a620415a0156a5d1ec31ad17420cfaa15f9d19527581c644b74ba1e4e149046093
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  bin/test.rb
19
- .DS_Store
19
+ .DS_Store
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
2
  --fail-fast
3
- --order random
3
+ --order random
data/.travis.yml CHANGED
@@ -4,4 +4,4 @@ rvm:
4
4
  - rbx-19mode
5
5
  - 1.9.2
6
6
  - 1.9.3
7
- - 2.0.0
7
+ - 2.0.0
data/Gemfile CHANGED
@@ -8,4 +8,4 @@ group :test do
8
8
  gem 'simplecov', require: false
9
9
  end
10
10
 
11
- gemspec
11
+ gemspec
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
@@ -5,4 +5,4 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  task test: :spec
8
- task default: :spec
8
+ task default: :spec
data/csstats.gemspec CHANGED
@@ -21,4 +21,4 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'hashie', '~> 2.0'
22
22
 
23
23
  gem.version = CSstats::VERSION
24
- end
24
+ end
data/lib/csstats.rb CHANGED
@@ -7,9 +7,9 @@ module CSstats
7
7
  # Alias for CSstats::Handler.new
8
8
  #
9
9
  # Returns CSstats::Handler
10
- def new(options={})
10
+ def new(options = {})
11
11
  CSstats::Handler.new(options)
12
12
  end
13
13
 
14
14
  end
15
- end
15
+ end
data/lib/csstats/error.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSstats
2
2
  class Error < StandardError; end
3
- end
3
+ end
@@ -2,30 +2,29 @@ require 'hashie/mash'
2
2
 
3
3
  module CSstats
4
4
  class Handler
5
- attr_accessor :path, :players, :fileversion, :position
5
+ attr_reader :path, :players
6
6
 
7
- # Initialize file.
7
+ # Public: Initialize file.
8
8
  #
9
- # Options:
10
- # path - The String of csstats.dat file.
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
- @fileversion = 0x00
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, "r")
22
+ handle = File.new(@path, 'r')
24
23
 
25
- @fileversion = read_short_data(handle);
24
+ @file_version = read_short_data(handle)
26
25
 
27
26
  i = 0
28
- while (!handle.eof? && (maxplayers == 0 || i < maxplayers))
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 Hash (Mash) of player information.
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 (length == 0)
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
- return mash
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 integer.
88
+ # Returns the Integer.
90
89
  def read_int_data(handle)
91
90
  data = handle.read(4)
92
- raise CSstats::Error, "Cannot read int data." unless data
93
- return data.unpack("V").first
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 integer.
99
+ # Returns the Integer.
101
100
  def read_short_data(handle)
102
101
  data = handle.read(2)
103
- raise CSstats::Error, "Cannot read short data." unless data
104
- return data.unpack("v").first
102
+ raise CSstats::Error, 'Cannot read short data.' unless data
103
+ data.unpack('v').first
105
104
  end
106
105
 
107
- # Get the string from file.
106
+ # Internal: Get the String from file.
108
107
  #
109
108
  # handle - The File which was opened for reading data.
110
- # len - length of string to read.
109
+ # len - The Integer length of string to read.
111
110
  #
112
- # Returns the string.
111
+ # Returns the String.
113
112
  def read_string_data(handle, length)
114
113
  data = handle.read(length)
115
- raise CSstats::Error, "Cannot read string data." unless data
114
+ raise CSstats::Error, 'Cannot read string data.' unless data
116
115
  data = data.strip
117
- return data
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 Hash of player information.
123
+ # Returns the Mash of player information.
125
124
  def player(id)
126
- unless (@players[id-1].nil?)
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 Hash of player information.
141
+ # Returns the Mash of player information.
143
142
  def search_by_name(name)
144
143
  @players.each do |player|
145
- return player if (name == player.nick)
144
+ return player if name == player.nick
146
145
  end
147
146
  end
148
147
  end
@@ -1,3 +1,3 @@
1
1
  module CSstats
2
- VERSION = "1.0.1" unless defined?(CSstats::VERSION)
2
+ VERSION = '1.0.2' unless defined?(CSstats::VERSION)
3
3
  end
@@ -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 "should return corrent players count" do
9
+ it 'should return corrent players count' do
10
10
  expect(@handler.players_count).to eq 15
11
11
  end
12
12
 
13
- it "should return correct player data" do
14
- expect(@handler.player(2).nick).to eq "CHMARSON"
13
+ it 'should return correct player data' do
14
+ expect(@handler.player(2).nick).to eq 'CHMARSON'
15
15
  end
16
16
 
17
- it "should return searched player" do
18
- player = @handler.search_by_name("CHMARSON")
19
- expect(player.nick).to eq "CHMARSON"
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
@@ -2,10 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe CSstats do
4
4
 
5
- describe ".new" do
6
- it "is a CSstats::Handler" do
5
+ describe '.new' do
6
+ it 'is a CSstats::Handler' do
7
7
  expect(CSstats.new).to be_a CSstats::Handler
8
8
  end
9
9
  end
10
10
 
11
- end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,6 @@ RSpec.configure do |config|
17
17
  end
18
18
 
19
19
  def csstats_file
20
- fixtures = File.expand_path("../fixtures", __FILE__)
20
+ fixtures = File.expand_path('../fixtures', __FILE__)
21
21
  File.new(fixtures + '/csstats.dat').path
22
22
  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.1
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-03 00:00:00.000000000 Z
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler