rmuh 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +6 -6
- data/Rakefile +3 -6
- data/examples/basic_parsing.rb +41 -0
- data/examples/basic_serverstats.rb +22 -0
- data/examples/serverstats_advanced.rb +26 -0
- data/examples/serverstats_cache.rb +35 -0
- data/lib/rmuh/serverstats/advanced.rb +2 -2
- data/lib/rmuh/serverstats/base.rb +2 -0
- data/lib/rmuh/version.rb +1 -1
- data/spec/examples_spec.rb +46 -0
- data/spec/rmuh_rpt_log_fetch_spec.rb +17 -15
- data/spec/rmuh_rpt_log_parsers_base_spec.rb +30 -7
- data/spec/rmuh_rpt_log_parsers_unitedoperationslog_spec.rb +66 -60
- data/spec/rmuh_rpt_log_parsers_unitedoperationsrpt_spec.rb +21 -20
- data/spec/rmuh_rpt_log_util_unitedoperations_spec.rb +51 -51
- data/spec/rmuh_rpt_log_util_unitedoperationslog_spec.rb +25 -21
- data/spec/rmuh_rpt_log_util_unitedoperationsrpt_spec.rb +68 -63
- data/spec/rmuh_rpt_spec.rb +8 -8
- data/spec/rmuh_serverstats_base_spec.rb +39 -23
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b63c73ace7a1211a2f87a68c08d9eb59214a5735
|
4
|
+
data.tar.gz: 6c8be181f4208f9d26c280af1b3247937fafcac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb90e1fa7a2be37278be469d1fca17011907eec6f3abdb00c738dca5b78f0d8e85871a5da8b7336c3be766e0c8c4671d21f2d0b3b558a007146788845ee7ed7b
|
7
|
+
data.tar.gz: 40aacc1f5594affb5790f186a77c4b4f11e6a46df9f5f0ff4853af359b348873f132845d323015aa0f04b0152deb72aa110454aba44c7d11799b81b3ac7baa4e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ INSTALLATION
|
|
29
29
|
This is packaged on the [RubyGems](https://rubygems.org/) site and can be
|
30
30
|
installed via the `gem` command:
|
31
31
|
|
32
|
-
```
|
32
|
+
```Bash
|
33
33
|
$ gem install rmuh
|
34
34
|
```
|
35
35
|
|
@@ -121,8 +121,8 @@ information directly from the server.
|
|
121
121
|
|
122
122
|
Here is a quick overview of how to use this functionality:
|
123
123
|
|
124
|
-
```
|
125
|
-
require 'rmuh/serverstats/base
|
124
|
+
```Ruby
|
125
|
+
require 'rmuh/serverstats/base'
|
126
126
|
UO_IP = '70.42.74.59'
|
127
127
|
s = RMuh::ServerStats::Base.new(host: UO_IP)
|
128
128
|
s.update_cache
|
@@ -135,14 +135,14 @@ the object.
|
|
135
135
|
|
136
136
|
If you want to avoid using the cache:
|
137
137
|
|
138
|
-
```
|
138
|
+
```Ruby
|
139
139
|
s = RMuh::ServerStats::Base.new(host: UO_IP, cache: false)
|
140
140
|
```
|
141
141
|
If you want to be able to pull each part of the returned data set using
|
142
142
|
dot-notation, you can use the `Advanced` class:
|
143
143
|
|
144
|
-
```
|
145
|
-
require 'rmuh/serverstats/base
|
144
|
+
```Ruby
|
145
|
+
require 'rmuh/serverstats/base'
|
146
146
|
s = RMuh::ServerStats::Advanced.new(host: UO_IP)
|
147
147
|
s.update_cache
|
148
148
|
puts s.players
|
data/Rakefile
CHANGED
@@ -4,12 +4,9 @@ require 'rubocop/rake_task'
|
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
|
-
Rubocop::RakeTask.new(:rubocop) do |
|
8
|
-
|
9
|
-
|
10
|
-
]
|
11
|
-
# task.formatters = ['files']
|
12
|
-
task.fail_on_error = true
|
7
|
+
Rubocop::RakeTask.new(:rubocop) do |t|
|
8
|
+
t.patterns = %w{ Rakefile Gemfile rmuh.gemspec lib/**/*.rb spec/*_spec.rb }
|
9
|
+
t.fail_on_error = true
|
13
10
|
end
|
14
11
|
|
15
12
|
task default: [:rubocop, :spec]
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# This example file shows you how to do the following:
|
5
|
+
# * fetch the size of a log
|
6
|
+
# * fetch the first KB of log file
|
7
|
+
# * parse the log with the base parser
|
8
|
+
# * use awesome_print to print out the returned object
|
9
|
+
#
|
10
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
11
|
+
|
12
|
+
require 'rmuh/rpt/log/fetch'
|
13
|
+
require 'rmuh/rpt/log/parsers/base'
|
14
|
+
require 'ap'
|
15
|
+
|
16
|
+
# set a constant for the URL
|
17
|
+
URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_LOG.txt'
|
18
|
+
|
19
|
+
# instantiate a new fetcher object, telling it to get the first
|
20
|
+
# 1024 bytes
|
21
|
+
f = RMuh::RPT::Log::Fetch.new(URL, byte_start: 0, byte_end: 1024)
|
22
|
+
|
23
|
+
# logfile will become a StringIO object that is the contents of the log
|
24
|
+
logfile = f.log
|
25
|
+
|
26
|
+
# print the log
|
27
|
+
puts "#### The full log\n#{logfile.readlines.join("\n")}\n#### End of log!"
|
28
|
+
|
29
|
+
# print the size of the log, f.size will return a Fixnum in bytes
|
30
|
+
puts "Log size: #{f.size} byte(s)"
|
31
|
+
|
32
|
+
# instantiate a new base parser, it takes no args
|
33
|
+
p = RMuh::RPT::Log::Parsers::Base.new
|
34
|
+
|
35
|
+
# this becomes an array of hashes, each item in the Array is a metadata
|
36
|
+
# Hash for that specific log line
|
37
|
+
parsed = p.parse(f.log)
|
38
|
+
|
39
|
+
puts '#### Metadata Hash'
|
40
|
+
ap parsed
|
41
|
+
puts '#### End of Hashes'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# This example shows you how to use the ServerStats class to pull real-time
|
5
|
+
# information about the server from the GameSpy protocol
|
6
|
+
#
|
7
|
+
# This includes map name, mission name, player list, game version, required
|
8
|
+
# mods, and a bunch of other information.
|
9
|
+
#
|
10
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
11
|
+
|
12
|
+
require 'rmuh/serverstats/base'
|
13
|
+
require 'ap'
|
14
|
+
|
15
|
+
# specify the UnitedOperations server
|
16
|
+
SRV = { host: 'srv1.unitedoperations.net', port: 2_302 }
|
17
|
+
|
18
|
+
# get an instance of ServerStats and print the stats
|
19
|
+
# by default this is a blocking operation. See serverstats_cache.rb for
|
20
|
+
# alternative options
|
21
|
+
s = RMuh::ServerStats::Base.new(host: SRV[:host], port: SRV[:port])
|
22
|
+
ap s.stats
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# This shows you how to use the ServerStats::Advanced class. The only
|
5
|
+
# difference between ::Base and ::Advanced is that Advanced gives you stats
|
6
|
+
# accessors using dot notation. You can see more about the ::Base class within
|
7
|
+
# the basic_serverstats.rb file
|
8
|
+
#
|
9
|
+
# It also has all the same caching characteristics as the ::Base class and you
|
10
|
+
# can learn more about those in the serverstats_cache.rb file.
|
11
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
12
|
+
|
13
|
+
require 'rmuh/serverstats/advanced'
|
14
|
+
require 'ap'
|
15
|
+
|
16
|
+
# specify the UnitedOperations server
|
17
|
+
SRV = { host: 'srv1.unitedoperations.net', port: 2_302 }
|
18
|
+
|
19
|
+
# build a new instance of ::Advanced
|
20
|
+
s = RMuh::ServerStats::Advanced.new(host: SRV[:host], port: SRV[:port])
|
21
|
+
|
22
|
+
# print the full stats out
|
23
|
+
ap s.stats
|
24
|
+
|
25
|
+
# print only the players Array
|
26
|
+
ap s.players
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
#
|
4
|
+
# By default the ServerStats::Base class caches the information from the
|
5
|
+
# server in memory. By default the class is a blocking operation on the first
|
6
|
+
# call to '.stats'. That's because if the cache is not populated it will
|
7
|
+
# poll the server.
|
8
|
+
#
|
9
|
+
# You can avoid this being blocking by setting 'auto_cache: false'. This means,
|
10
|
+
# however, that you will need to call the '.update_cache' method when you can
|
11
|
+
# afford a blocking operation
|
12
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
13
|
+
|
14
|
+
require 'rmuh/serverstats/base'
|
15
|
+
require 'ap'
|
16
|
+
|
17
|
+
# specify the UnitedOperations server
|
18
|
+
SRV = { host: 'srv1.unitedoperations.net', port: 2_302 }
|
19
|
+
|
20
|
+
s = RMuh::ServerStats::Base.new(
|
21
|
+
host: SRV[:host], port: SRV[:port], auto_cache: false
|
22
|
+
)
|
23
|
+
ap s.stats # this should be nil
|
24
|
+
|
25
|
+
# update the cache within the object from the server, then print the stats
|
26
|
+
s.update_cache
|
27
|
+
ap s.stats
|
28
|
+
|
29
|
+
# You can also turn off the cache completely, which means '.stats' will be a
|
30
|
+
# blocking call each time. You do this by passing 'cache: false'
|
31
|
+
s = RMuh::ServerStats::Base.new(
|
32
|
+
host: SRV[:host], port: SRV[:port], cache: false
|
33
|
+
)
|
34
|
+
|
35
|
+
ap s.stats
|
@@ -41,6 +41,7 @@ module RMuh
|
|
41
41
|
fail ArgumentError, ':host is required' unless opts.key?(:host)
|
42
42
|
opts[:port] ||= DEFAULT_PORT
|
43
43
|
opts[:cache] = true unless opts.key?(:cache)
|
44
|
+
opts[:auto_cache] = true unless opts.key?(:auto_cache)
|
44
45
|
nil
|
45
46
|
end
|
46
47
|
|
@@ -50,6 +51,7 @@ module RMuh
|
|
50
51
|
|
51
52
|
def remote_stats
|
52
53
|
if @cache
|
54
|
+
update_cache if @serverstats.nil? && @auto_cache
|
53
55
|
@serverstats
|
54
56
|
else
|
55
57
|
sync
|
data/lib/rmuh/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
# These are just specs to make sure the example files run with an exit
|
3
|
+
# code of zero.
|
4
|
+
#
|
5
|
+
require 'rspec'
|
6
|
+
require 'open3'
|
7
|
+
require 'helpers/spec_helper'
|
8
|
+
|
9
|
+
DIR = File.expand_path('../../examples', __FILE__)
|
10
|
+
|
11
|
+
describe 'exampple files' do
|
12
|
+
|
13
|
+
context "#{File.join(DIR, 'basic_parsing.rb')}" do
|
14
|
+
it 'should run and return a zero exit code' do
|
15
|
+
_, _, s = Open3.capture3("ruby #{File.join(DIR, 'basic_parsing.rb')}")
|
16
|
+
expect(s.success?).to be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "#{File.join(DIR, 'basic_serverstats.rb')}" do
|
21
|
+
it 'should run and return a zero exit code' do
|
22
|
+
_, _, s = Open3.capture3(
|
23
|
+
"ruby #{File.join(DIR, 'basic_serverstats.rb')}"
|
24
|
+
)
|
25
|
+
expect(s.success?).to be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "#{File.join(DIR, 'serverstats_advanced.rb')}" do
|
30
|
+
it 'should run and return a zero exit code' do
|
31
|
+
_, _, s = Open3.capture3(
|
32
|
+
"ruby #{File.join(DIR, 'serverstats_advanced.rb')}"
|
33
|
+
)
|
34
|
+
expect(s.success?).to be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "#{File.join(DIR, 'serverstats_cache.rb')}" do
|
39
|
+
it 'should run an return a zero exit code' do
|
40
|
+
_, _, s = Open3.capture3(
|
41
|
+
"ruby #{File.join(DIR, 'serverstats_cache.rb')}"
|
42
|
+
)
|
43
|
+
expect(s.success?).to be_true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -11,28 +11,30 @@ describe RMuh::RPT::Log::Fetch do
|
|
11
11
|
end
|
12
12
|
let(:fetch) { RMuh::RPT::Log::Fetch.new(url) }
|
13
13
|
context '#new' do
|
14
|
+
subject { fetch }
|
15
|
+
|
14
16
|
it 'should return an instance of RMuh::RPT::Log::Fetch' do
|
15
|
-
fetch.
|
17
|
+
expect(fetch).to be_an_instance_of RMuh::RPT::Log::Fetch
|
16
18
|
end
|
17
19
|
|
18
20
|
it 'should have a @log_url object which is an instance of String' do
|
19
|
-
fetch.log_url.
|
21
|
+
expect(fetch.log_url).to be_an_instance_of String
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'should set the "byte_start" config item if specified' do
|
23
25
|
rlfetch = RMuh::RPT::Log::Fetch.new(url, byte_start: 10)
|
24
|
-
rlfetch.byte_start.
|
26
|
+
expect(rlfetch.byte_start).to eql 10
|
25
27
|
end
|
26
28
|
|
27
29
|
it 'should set the "byte_end" config item if specified' do
|
28
30
|
rlfetch = RMuh::RPT::Log::Fetch.new(url, byte_end: 42)
|
29
|
-
rlfetch.byte_end.
|
31
|
+
expect(rlfetch.byte_end).to eql 42
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
35
|
context '#byte_start' do
|
34
36
|
it 'should allow setting the value to Integer' do
|
35
|
-
expect { fetch.byte_start = 10 }.
|
37
|
+
expect { fetch.byte_start = 10 }.to_not raise_error
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'should raise an error if the value is nil' do
|
@@ -49,17 +51,17 @@ describe RMuh::RPT::Log::Fetch do
|
|
49
51
|
|
50
52
|
it 'should update the @cfg.byte_start value' do
|
51
53
|
fetch.byte_start = 10
|
52
|
-
fetch.byte_start.
|
54
|
+
expect(fetch.byte_start).to eql 10
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
58
|
context '#byte_end' do
|
57
59
|
it 'should allow setting the value to Integer' do
|
58
|
-
expect { fetch.byte_end = 10 }.
|
60
|
+
expect { fetch.byte_end = 10 }.to_not raise_error
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'should allow setting the value is nil' do
|
62
|
-
expect { fetch.byte_end = nil }.
|
64
|
+
expect { fetch.byte_end = nil }.to_not raise_error
|
63
65
|
end
|
64
66
|
|
65
67
|
it 'should raise an error if arg:1 is a String' do
|
@@ -72,27 +74,27 @@ describe RMuh::RPT::Log::Fetch do
|
|
72
74
|
|
73
75
|
it 'should update the @cfg.byte_end value' do
|
74
76
|
fetch.byte_end = 42
|
75
|
-
fetch.byte_end.
|
77
|
+
expect(fetch.byte_end).to eql 42
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
81
|
context '#size' do
|
80
82
|
it 'should return a Integer object' do
|
81
|
-
fetch.size.
|
83
|
+
expect(fetch.size).to be_an_instance_of Fixnum
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'should return the size' do
|
85
|
-
fetch.size.
|
87
|
+
expect(fetch.size).to eql 10
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
89
91
|
context '#log' do
|
90
92
|
it 'should return a StringIO object' do
|
91
|
-
fetch.log.
|
93
|
+
expect(fetch.log).to be_an_instance_of StringIO
|
92
94
|
end
|
93
95
|
|
94
96
|
it 'should return the log' do
|
95
|
-
fetch.log.read.
|
97
|
+
expect(fetch.log.read).to eql "RSpec, yo\n"
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
@@ -101,12 +103,12 @@ describe RMuh::RPT::Log::Fetch do
|
|
101
103
|
let(:dos_newline) { /\r\n$/ }
|
102
104
|
|
103
105
|
it 'should match the Regexp object' do
|
104
|
-
expect(dos_newline.match(dos)).
|
106
|
+
expect(dos_newline.match(dos)).to_not be nil
|
105
107
|
end
|
106
108
|
|
107
109
|
it 'should strip out DOS new lines' do
|
108
110
|
match = /\r\n/.match(fetch.send(:dos2unix, dos))
|
109
|
-
match.
|
111
|
+
expect(match).to be_nil
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
@@ -12,7 +12,7 @@ describe RMuh::RPT::Log::Parsers::Base do
|
|
12
12
|
|
13
13
|
context 'text' do
|
14
14
|
it 'should be a StringIO object' do
|
15
|
-
text.
|
15
|
+
expect(text).to be_an_instance_of StringIO
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -24,7 +24,7 @@ describe RMuh::RPT::Log::Parsers::Base do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should return an instance of RMuh::RPT::Log::Parsers::Base' do
|
27
|
-
base.
|
27
|
+
expect(base).to be_an_instance_of RMuh::RPT::Log::Parsers::Base
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -37,21 +37,44 @@ describe RMuh::RPT::Log::Parsers::Base do
|
|
37
37
|
expect { base.parse }.to raise_error ArgumentError
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'should
|
41
|
-
expect { base.parse(
|
42
|
-
|
40
|
+
it 'should raise an error when passed nil' do
|
41
|
+
expect { base.parse(nil) }.to raise_error ArgumentError
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should raise an error when passed a String' do
|
45
|
+
expect { base.parse('') }.to raise_error ArgumentError
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should raise an error when passed a Fixnum' do
|
49
|
+
expect { base.parse(0) }.to raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should raise an error when passed a Float' do
|
53
|
+
expect { base.parse(0.0) }.to raise_error ArgumentError
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should raise an error when passed an Array' do
|
57
|
+
expect { base.parse([]) }.to raise_error ArgumentError
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should raise an error when passed a Hash' do
|
61
|
+
expect { base.parse({}) }.to raise_error ArgumentError
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should not raise an error when passed a StringIO object' do
|
65
|
+
expect { base.parse(StringIO.new) }.to_not raise_error
|
43
66
|
end
|
44
67
|
|
45
68
|
it 'should return an Array' do
|
46
69
|
expect(base.parse(text)).to be_an_instance_of Array
|
47
70
|
end
|
48
71
|
|
49
|
-
it 'the Array size
|
72
|
+
it 'should return an the Array with a size of 2' do
|
50
73
|
expect(base.parse(text).size).to be 2
|
51
74
|
end
|
52
75
|
|
53
76
|
it 'should be an Array of hashes' do
|
54
|
-
base.parse(text).each { |p| p.
|
77
|
+
base.parse(text).each { |p| expect(p).to be_an_instance_of Hash }
|
55
78
|
end
|
56
79
|
end
|
57
80
|
end
|