ircparser 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ircparser/source.rb +16 -10
- data/lib/ircparser.rb +1 -1
- data/test/test_source.rb +23 -21
- 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: f1217812391fbfc6ef203d02f1254b972c443616
|
4
|
+
data.tar.gz: 3f6e7b53c42321bb34c2a47cf2d0913189ce68c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f26235c8c3962bcb916d708e065aad027248343795fd449aea0bfcb19fea064403a34fd3da3a374dc12663af738e03d7ee68c3f0d5a62835a5cebc6696095bc
|
7
|
+
data.tar.gz: a4a9d6960f9ff92967009db8e3f1cdfdfb6cfd9557afaa20a682df46d871c4aab4301177e6221f2f989188dc6790b7c8e7f2ee7480bbde6dcf57dea2e0392fef
|
data/lib/ircparser/source.rb
CHANGED
@@ -19,10 +19,10 @@ module IRCParser
|
|
19
19
|
class Source
|
20
20
|
|
21
21
|
# Internal: A regular expression which matches a n!u@h mask.
|
22
|
-
MATCH_USER = /^(
|
22
|
+
MATCH_USER = /^(?<nick>[^\s!@]+?)(?:!(?<user>[^\s!@]+?))?(?:@(?<host>[^\s!@]+?))?$/
|
23
23
|
|
24
24
|
# Internal: A regular expression which matches a server name.
|
25
|
-
MATCH_SERVER = /^(
|
25
|
+
MATCH_SERVER = /^(?<host>\S+\.\S+)$/
|
26
26
|
|
27
27
|
# Public: The hostname of this source.
|
28
28
|
attr_reader :host
|
@@ -37,14 +37,14 @@ module IRCParser
|
|
37
37
|
#
|
38
38
|
# source - Either a n!u@h mask or a server name.
|
39
39
|
def initialize source
|
40
|
-
if
|
41
|
-
@type = :user
|
42
|
-
@nick = $~[1]
|
43
|
-
@user = $~[2]
|
44
|
-
@host = $~[3]
|
45
|
-
elsif MATCH_SERVER =~ source
|
40
|
+
if MATCH_SERVER =~ source
|
46
41
|
@type = :server
|
47
|
-
@host = $~[
|
42
|
+
@host = $~[:host]
|
43
|
+
elsif MATCH_USER =~ source
|
44
|
+
@type = :user
|
45
|
+
@nick = $~[:nick]
|
46
|
+
@user = $~[:user]
|
47
|
+
@host = $~[:host]
|
48
48
|
else
|
49
49
|
raise IRCParser::Error.new(source), 'source is not a user mask or server name'
|
50
50
|
end
|
@@ -67,7 +67,13 @@ module IRCParser
|
|
67
67
|
|
68
68
|
# Public: serialises this source to the serialised form.
|
69
69
|
def to_s
|
70
|
-
|
70
|
+
if is_user?
|
71
|
+
buffer = @nick
|
72
|
+
buffer += "!#{@user}" unless @user.nil?
|
73
|
+
buffer += "@#{@host}" unless @host.nil?
|
74
|
+
return buffer
|
75
|
+
end
|
76
|
+
return @host
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|
data/lib/ircparser.rb
CHANGED
data/test/test_source.rb
CHANGED
@@ -38,28 +38,30 @@ describe IRCParser::Source do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
@source.nick.must_equal 'nick'
|
48
|
-
@source.user.must_equal 'user'
|
49
|
-
@source.host.must_equal 'host'
|
50
|
-
end
|
51
|
-
it 'should be a user not a server' do
|
52
|
-
@source.is_server?.must_equal false
|
53
|
-
@source.is_user?.must_equal true
|
54
|
-
end
|
55
|
-
it 'should serialise back to the same text' do
|
56
|
-
@source.to_s.must_equal @text
|
57
|
-
end
|
58
|
-
end
|
41
|
+
USER_MASKS = {
|
42
|
+
'nick!user@host' => { nick: 'nick', user: 'user', host: 'host' },
|
43
|
+
'nick!user' => { nick: 'nick', user: 'user', host: nil },
|
44
|
+
'nick@host' => { nick: 'nick', user: nil, host: 'host' },
|
45
|
+
'nick' => { nick: 'nick', user: nil, host: nil }
|
46
|
+
}
|
59
47
|
|
60
|
-
|
61
|
-
|
62
|
-
|
48
|
+
USER_MASKS.each do |serialized, deserialized|
|
49
|
+
describe 'when checking a valid user source' do
|
50
|
+
before do
|
51
|
+
@source = IRCParser::Source.new serialized
|
52
|
+
end
|
53
|
+
it 'should consist of the correct components' do
|
54
|
+
@source.nick.must_equal deserialized[:nick]
|
55
|
+
@source.user.must_equal deserialized[:user]
|
56
|
+
@source.host.must_equal deserialized[:host]
|
57
|
+
end
|
58
|
+
it 'should be a user not a server' do
|
59
|
+
@source.is_server?.must_equal false
|
60
|
+
@source.is_user?.must_equal true
|
61
|
+
end
|
62
|
+
it 'should serialise back to the same text' do
|
63
|
+
@source.to_s.must_equal serialized
|
64
|
+
end
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ircparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter "SaberUK" Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|