fonte 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,194 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe LogParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(text) }
9
+
10
+ describe "entry" do
11
+ let(:text) { 'L 12/26/2011 - 02:14:29: Loading map "c4m2_sugarmill_a"' }
12
+ it { should be }
13
+
14
+ describe "time" do
15
+ subject { parser.parse(text).date_time }
16
+ it { should be }
17
+ end
18
+
19
+ describe "command" do
20
+ subject { parser.parse(text).command }
21
+ it { should be }
22
+ end
23
+ end
24
+
25
+ describe "commands" do
26
+ describe "log started command" do
27
+ let(:text) { 'L 12/26/2011 - 02:14:29: Log file started (file "logs/L127_000_001_001_27015_201112260214_000.log") (game "/home/ubuntu/srcds/left4dead2/left4dead2") (version "4777")' }
28
+ it { should be }
29
+
30
+ let(:command) { parser.parse(text).command }
31
+
32
+ describe "log filename" do
33
+ subject { command.log_filename.value }
34
+ it { should == "logs/L127_000_001_001_27015_201112260214_000.log" }
35
+ end
36
+
37
+ describe "game path" do
38
+ subject { command.log_game_path.value }
39
+ it { should == "/home/ubuntu/srcds/left4dead2/left4dead2" }
40
+ end
41
+
42
+ describe "game version" do
43
+ subject { command.log_game_version.value }
44
+ it { should == "4777" }
45
+ end
46
+ end
47
+
48
+ describe "cvar start command" do
49
+ let(:command) { parser.parse(text).command }
50
+
51
+ context "when server starts with an upcase 'S'" do
52
+ let(:text) { 'L 12/26/2011 - 02:14:29: Server cvars start' }
53
+ it { should be }
54
+ end
55
+
56
+ context "when server starts with an downcase 'S'" do
57
+ let(:text) { 'L 12/26/2011 - 02:14:29: server cvars start' }
58
+ it { should be }
59
+ end
60
+ end
61
+
62
+ describe "cvar end command" do
63
+ let(:command) { parser.parse(text).command }
64
+
65
+ context "when server starts with an upcase 'S'" do
66
+ let(:text) { 'L 12/26/2011 - 02:14:29: Server cvars end' }
67
+ it { should be }
68
+ end
69
+
70
+ context "when server starts with an downcase 'S'" do
71
+ let(:text) { 'L 12/26/2011 - 02:14:29: server cvars end' }
72
+ it { should be }
73
+ end
74
+ end
75
+
76
+ describe "cvar set command" do
77
+ let(:command) { parser.parse(text).command }
78
+
79
+ context "when server starts with an upcase 'S'" do
80
+ let(:text) { 'L 12/26/2011 - 02:14:29: Server cvar "var" = "value"' }
81
+ it { should be }
82
+
83
+ describe "the variable" do
84
+ subject { command }
85
+
86
+ its(:value) { should == "value" }
87
+ its(:name) { should == "var" }
88
+ end
89
+ end
90
+
91
+ context "when server starts with an downcase 'S'" do
92
+ let(:text) { 'L 12/26/2011 - 02:14:29: server cvar "var" = "value"' }
93
+ it { should be }
94
+
95
+ describe "the variable" do
96
+ subject { command }
97
+
98
+ its(:value) { should == "value" }
99
+ its(:name) { should == "var" }
100
+ end
101
+ end
102
+
103
+ context "when server starts without the Server cvar entry " do
104
+ let(:text) { 'L 12/26/2011 - 02:14:29: "var" = "value"' }
105
+ it { should be }
106
+
107
+ describe "the variable" do
108
+ subject { command }
109
+
110
+ its(:value) { should == "value" }
111
+ its(:name) { should == "var" }
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "map loading command" do
117
+ let(:text) { 'L 12/26/2011 - 02:14:29: Loading map "c4m2_sugarmill_a"' }
118
+ it { should be }
119
+
120
+ let(:command) { parser.parse(text).command }
121
+
122
+ describe "map name" do
123
+ subject { command.map_name.value }
124
+ it { should == "c4m2_sugarmill_a" }
125
+ end
126
+ end
127
+
128
+ describe "map started command" do
129
+ let(:text) { 'L 12/26/2011 - 02:14:33: Started map "c4m2_sugarmill_a" (CRC "-431283537")' }
130
+ it { should be }
131
+
132
+ let(:command) { parser.parse(text).command }
133
+
134
+ describe "map name" do
135
+ subject { command.map_name.value }
136
+ it { should == "c4m2_sugarmill_a" }
137
+ end
138
+
139
+ describe "map CRC" do
140
+ subject { command.map_crc.value }
141
+ it { should == "-431283537" }
142
+ end
143
+ end
144
+
145
+ describe "map started command" do
146
+ let(:text) { 'L 12/26/2011 - 02:14:33: Started map "c4m2_sugarmill_a" (CRC "-431283537")' }
147
+ it { should be }
148
+
149
+ let(:command) { parser.parse(text).command }
150
+
151
+ describe "map name" do
152
+ subject { command.map_name.value }
153
+ it { should == "c4m2_sugarmill_a" }
154
+ end
155
+
156
+ describe "map CRC" do
157
+ subject { command.map_crc.value }
158
+ it { should == "-431283537" }
159
+ end
160
+ end
161
+
162
+ describe "sever name command" do
163
+ let(:text) { 'L 12/26/2011 - 02:14:33: Server name is "Manapot Server"' }
164
+ it { should be }
165
+
166
+ let(:command) { parser.parse(text).command }
167
+
168
+ describe "server name" do
169
+ subject { command.server_name.value }
170
+ it { should == "Manapot Server" }
171
+ end
172
+ end
173
+
174
+ describe "sever say command" do
175
+ let(:text) { 'L 12/26/2011 - 02:14:33: Server say "Hai"' }
176
+ it { should be }
177
+
178
+ let(:command) { parser.parse(text).command }
179
+
180
+ describe "server say" do
181
+ subject { command.server_say.value }
182
+ it { should == "Hai" }
183
+ end
184
+ end
185
+
186
+ describe "rcon command" do
187
+ let(:text) { 'L 12/26/2011 - 02:14:33: Rcon: "rcon challenge "password" command" from "192.168.10.1:17015"' }
188
+ subject { parser.parse(text).command }
189
+ it_should_behave_like "a rcon command", :password => "password", :origin => "//192.168.10.1:17015"
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe NumberParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(number).value }
9
+
10
+ describe "integer" do
11
+ context "decimal" do
12
+ context "positive" do
13
+ let(:number) { "42" }
14
+ it { should == 42 }
15
+ end
16
+
17
+ context "negative" do
18
+ let(:number) { "-3" }
19
+ it { should == -3 }
20
+ end
21
+ end
22
+
23
+ context "hexadecimal" do
24
+ context "positive" do
25
+ let(:number) { "0xff" }
26
+ it { should == 255 }
27
+ end
28
+
29
+ context "negative" do
30
+ let(:number) { "-0XFF" }
31
+ it { should == -255 }
32
+ end
33
+ end
34
+
35
+ context "binary" do
36
+ context "positive" do
37
+ let(:number) { "0b110" }
38
+ it { should == 6 }
39
+ end
40
+
41
+ context "negative" do
42
+ let(:number) { "-0B110" }
43
+ it { should == -6 }
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "floating point" do
49
+ describe "standard notation" do
50
+ context "positive" do
51
+ let(:number) { "10.3"}
52
+ it { should == 10.3 }
53
+ end
54
+
55
+ context "negative" do
56
+ let(:number) { "-43.21" }
57
+ it { should == -43.21 }
58
+ end
59
+
60
+ context "just decimal points" do
61
+ let(:number) { ".21" }
62
+ it { should == 0.21 }
63
+ end
64
+ end
65
+
66
+ describe "scientific notation" do
67
+ context "with positive expoent" do
68
+ let(:number) { "5e4" }
69
+ it { should == 50000.0 }
70
+ end
71
+
72
+ context "with negative expoent" do
73
+ let(:number) { "2.2E-4" }
74
+ it { should == 0.00022 }
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe PlayerParser do
6
+ let(:parser) { described_class.new }
7
+ let(:player) { "Reu<2><STEAM_1:1:24968171><Red>" }
8
+
9
+ subject { parser.parse(player) }
10
+
11
+ its(:"nickname.value") { should == "Reu" }
12
+ its(:"uid.value") { should == 2 }
13
+ its(:"steam_id.value") { should == "STEAM_1:1:24968171" }
14
+ its(:"team.value") { should == "Red" }
15
+
16
+ context "when the player is a bot" do
17
+ let(:player) { "Nick<42><Bot><Red>" }
18
+ its(:"steam_id.value") { should be_nil }
19
+ end
20
+
21
+ context "when the player is the console" do
22
+ let(:player) { "Console<0><Console><Console>" }
23
+ its(:"steam_id.value") { should be_nil }
24
+ its(:"team.value") { should be_nil }
25
+ end
26
+
27
+ context "when the team is not present" do
28
+ let(:player) { "Reu<2><STEAM_1:1:24968171><>" }
29
+ its(:"team.value") { should be_nil }
30
+ end
31
+
32
+ context "when the team is unissiged" do
33
+ let(:player) { "Reu<2><STEAM_1:1:24968171><Unassigned>" }
34
+ its(:"team.value") { should be_nil }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe RconParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(rcon_command) }
9
+
10
+ context "with a successfully rcon challenge" do
11
+ let(:rcon_command) { 'Rcon: "rcon challenge "password" command" from "192.168.10.1:17015"' }
12
+ it_should_behave_like "a rcon command", :password => "password", :origin => "//192.168.10.1:17015"
13
+ end
14
+
15
+ context "with a bad rcon challenge" do
16
+ let(:rcon_command) { 'Bad Rcon: "rcon challenge "password" command" from "192.168.10.1:17015"' }
17
+ it_should_behave_like "a rcon command", :password => "password", :origin => "//192.168.10.1:17015"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,144 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe SteamIDParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(steam_id) }
9
+
10
+ describe "node" do
11
+ subject { parser.parse(steam_id) }
12
+
13
+ context "of a validated user" do
14
+ let(:steam_id) { "STEAM_1:1:24968171" }
15
+ its(:value) { should == steam_id }
16
+
17
+ it { should be_real_player }
18
+ it { should_not be_bot }
19
+ it { should_not be_unknown }
20
+ it { should_not be_pending }
21
+ it { should_not be_console }
22
+ end
23
+
24
+ context "of a pending user" do
25
+ let(:steam_id) { "STEAM_ID_PENDING" }
26
+ its(:value) { should_not be }
27
+
28
+ it { should_not be_real_player }
29
+ it { should_not be_unknown }
30
+ it { should_not be_bot }
31
+ it { should be_pending }
32
+ it { should_not be_console }
33
+ end
34
+
35
+ context "of a bot" do
36
+ let(:steam_id) { "Bot" }
37
+ its(:value) { should_not be }
38
+
39
+ it { should_not be_real_player }
40
+ it { should_not be_unknown }
41
+ it { should be_bot }
42
+ it { should_not be_pending }
43
+ it { should_not be_console }
44
+ end
45
+
46
+ context "of a invalid user" do
47
+ let(:steam_id) { "UNKNOWN" }
48
+ its(:value) { should_not be }
49
+
50
+ it { should_not be_real_player }
51
+ it { should be_unknown }
52
+ it { should_not be_bot }
53
+ it { should_not be_pending }
54
+ it { should_not be_console }
55
+ end
56
+
57
+ context "of the console user" do
58
+ let(:steam_id) { "Console" }
59
+ its(:value) { should_not be }
60
+
61
+ it { should_not be_real_player }
62
+ it { should_not be_unknown }
63
+ it { should_not be_bot }
64
+ it { should_not be_pending }
65
+ it { should be_console }
66
+ end
67
+ end
68
+
69
+ describe "universe" do
70
+ subject { parser.parse(steam_id).universe }
71
+
72
+ context "STEAM_0" do
73
+ let(:steam_id) { "STEAM_0:1:24968171" }
74
+
75
+ it { should be_unspecified }
76
+ its(:value) { should == "Unspecified" }
77
+ end
78
+
79
+ context "STEAM_1" do
80
+ let(:steam_id) { "STEAM_1:1:24968171" }
81
+
82
+ it { should be_public }
83
+ its(:value) { should == "Public" }
84
+ end
85
+
86
+ context "STEAM_2" do
87
+ let(:steam_id) { "STEAM_2:1:24968171" }
88
+
89
+ it { should be_beta }
90
+ its(:value) { should == "Beta" }
91
+ end
92
+
93
+ context "STEAM_3" do
94
+ let(:steam_id) { "STEAM_3:1:24968171" }
95
+
96
+ it { should be_internal }
97
+ its(:value) { should == "Internal" }
98
+ end
99
+
100
+ context "STEAM_4" do
101
+ let(:steam_id) { "STEAM_4:1:24968171" }
102
+
103
+ it { should be_developer }
104
+ its(:value) { should == "Dev" }
105
+ end
106
+
107
+ context "STEAM_5" do
108
+ let(:steam_id) { "STEAM_5:1:24968171" }
109
+
110
+ it { should be_rc }
111
+ its(:value) { should == "RC" }
112
+ end
113
+ end
114
+
115
+ describe "id_part" do
116
+ subject { parser.parse(steam_id).id_part }
117
+
118
+ context "when 0" do
119
+ let(:steam_id) { "STEAM_0:0:24968171" }
120
+ its(:value) { should == 0 }
121
+ end
122
+
123
+ context "when 1" do
124
+ let(:steam_id) { "STEAM_0:1:24968171" }
125
+ its(:value) { should == 1 }
126
+ end
127
+
128
+ context "when not 0 nor 1" do
129
+ let(:steam_id) { "STEAM_0:3:24968171" }
130
+
131
+ subject { parser.parse(steam_id) }
132
+ it { should_not be }
133
+ end
134
+ end
135
+
136
+ describe "account_number" do
137
+ subject { parser.parse(steam_id).account_number }
138
+
139
+ let(:steam_id) { "STEAM_0:0:24968171" }
140
+ its(:value) { should == 24968171 }
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe TemporalParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(date_time) }
9
+
10
+ context "with a valid format" do
11
+ let(:date_time) { "12/26/2011 - 02:14:29" }
12
+ it { should be }
13
+
14
+ subject { parser.parse(date_time).value }
15
+
16
+ its(:day) { should == 26 }
17
+ its(:month) { should == 12 }
18
+ its(:year) { should == 2011 }
19
+ its(:hour) { should == 2 }
20
+ its(:min) { should == 14 }
21
+ its(:sec) { should == 29 }
22
+ end
23
+
24
+ context "with a invalid format" do
25
+ let(:date_time) { "12/26/2011 02:14:29" }
26
+ it { should_not be }
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ module Fonte
4
+ module Parsers
5
+ describe WordParser do
6
+ let(:parser) { described_class.new }
7
+
8
+ subject { parser.parse(word) }
9
+
10
+ context "with a string surrounded by double quotes" do
11
+ let(:word) { '"Double quotes yay"' }
12
+ it { should be }
13
+ its(:value) { should == "Double quotes yay" }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ require "fonte"
2
+
3
+ Dir["./spec/support/**/*.rb"].each { |f| require f }
@@ -0,0 +1,4 @@
1
+ shared_examples "a rcon command" do |options|
2
+ its(:"password.value") { should == options[:password] }
3
+ its(:"origin.value.to_s") { should == options[:origin] }
4
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fonte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Navarro
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2160380860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2160380860
25
+ - !ruby/object:Gem::Dependency
26
+ name: treetop
27
+ requirement: &2160380280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2160380280
36
+ description:
37
+ email:
38
+ - rnavarro1@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .travis.yml
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - fonte.gemspec
49
+ - lib/fonte.rb
50
+ - lib/fonte/nodes.rb
51
+ - lib/fonte/nodes/date_time_node.rb
52
+ - lib/fonte/nodes/integer_node.rb
53
+ - lib/fonte/nodes/ip_node.rb
54
+ - lib/fonte/nodes/rcon_command_node.rb
55
+ - lib/fonte/nodes/single_word_node.rb
56
+ - lib/fonte/nodes/steam_id_node.rb
57
+ - lib/fonte/nodes/steam_id_universe_node.rb
58
+ - lib/fonte/parsers.rb
59
+ - lib/fonte/parsers/address.treetop
60
+ - lib/fonte/parsers/log.treetop
61
+ - lib/fonte/parsers/number.treetop
62
+ - lib/fonte/parsers/player.treetop
63
+ - lib/fonte/parsers/rcon.treetop
64
+ - lib/fonte/parsers/steam_id.treetop
65
+ - lib/fonte/parsers/temporal.treetop
66
+ - lib/fonte/parsers/word.treetop
67
+ - lib/fonte/version.rb
68
+ - spec/parsers/address_parser_spec.rb
69
+ - spec/parsers/log_parser_spec.rb
70
+ - spec/parsers/number_parser_spec.rb
71
+ - spec/parsers/player_parser_spec.rb
72
+ - spec/parsers/rcon_parser_spec.rb
73
+ - spec/parsers/steam_id_parser_spec.rb
74
+ - spec/parsers/temporal_parser_spec.rb
75
+ - spec/parsers/word_parser_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/support/shared_examples/rcon_command.rb
78
+ homepage: https://github.com/reu/fonte
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: 3476406977491015761
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 3476406977491015761
102
+ requirements: []
103
+ rubyforge_project: fonte
104
+ rubygems_version: 1.8.10
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Valve Source Engine log parser
108
+ test_files:
109
+ - spec/parsers/address_parser_spec.rb
110
+ - spec/parsers/log_parser_spec.rb
111
+ - spec/parsers/number_parser_spec.rb
112
+ - spec/parsers/player_parser_spec.rb
113
+ - spec/parsers/rcon_parser_spec.rb
114
+ - spec/parsers/steam_id_parser_spec.rb
115
+ - spec/parsers/temporal_parser_spec.rb
116
+ - spec/parsers/word_parser_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/support/shared_examples/rcon_command.rb