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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87f09fe2f8c39d5f6b97ccc979663bc6440c2ce5
4
- data.tar.gz: 2c1831eb6b7dffb26f89c6a516e8b60bb03e99d6
3
+ metadata.gz: f1217812391fbfc6ef203d02f1254b972c443616
4
+ data.tar.gz: 3f6e7b53c42321bb34c2a47cf2d0913189ce68c4
5
5
  SHA512:
6
- metadata.gz: 067017dc63e5b00e5b69377aad611ed71535ace6a476785318de659e186933b467b2948eafd3cf04029730976c63f1ebe3619e9e433fdd6f1ae21d4532b7ae77
7
- data.tar.gz: 34826d0a23573067c3f4a1d8a233f15566a124cfb5f941c66685914a74938f74f076af6c0b79256b94f21855f7ef8dde9c2aa8534a288c715c5f963195d4f4fd
6
+ metadata.gz: 8f26235c8c3962bcb916d708e065aad027248343795fd449aea0bfcb19fea064403a34fd3da3a374dc12663af738e03d7ee68c3f0d5a62835a5cebc6696095bc
7
+ data.tar.gz: a4a9d6960f9ff92967009db8e3f1cdfdfb6cfd9557afaa20a682df46d871c4aab4301177e6221f2f989188dc6790b7c8e7f2ee7480bbde6dcf57dea2e0392fef
@@ -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 = /^(\S+)!(\S+)@(\S+)$/
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 = /^(\S+\.\S+)$/
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 MATCH_USER =~ source
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 = $~[1]
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
- return is_user? ? "#{@nick}!#{@user}@#{@host}" : @host
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
@@ -16,7 +16,7 @@
16
16
  module IRCParser
17
17
 
18
18
  # Public: The version of IRCParser in use.
19
- VERSION = '0.1.1'
19
+ VERSION = '0.2.0'
20
20
  end
21
21
 
22
22
  require_relative 'ircparser/error'
data/test/test_source.rb CHANGED
@@ -38,28 +38,30 @@ describe IRCParser::Source do
38
38
  end
39
39
  end
40
40
 
41
- describe 'when checking a valid user source' do
42
- before do
43
- @text = 'nick!user@host'
44
- @source = IRCParser::Source.new @text
45
- end
46
- it 'should consist of the correct components' do
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
- describe 'when checking an invalid server source' do
61
- it 'should throw an IRCParser::Error' do
62
- proc { IRCParser::Source.new 'test' }.must_raise IRCParser::Error
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.1.1
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-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest