ircparser 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80f2730b5d589fcd3a7f2933f67650173af4aefb
4
- data.tar.gz: 68c6c1b781a5c9e8b0f4c22cb81c7f1222cc3d1f
3
+ metadata.gz: 5beae91923832297ad9f4005057e85283b072981
4
+ data.tar.gz: 788844a68185df07bc39ab2106e7606dee8e43e4
5
5
  SHA512:
6
- metadata.gz: 4d01aac7f7ec5f8b19cbc7a0c27adb956811935a33849d8814edac7b6cd62dc3cc909f8d4b54416edca1d72574edd713e7d7f808dc3b75f046e6b3a266c12473
7
- data.tar.gz: 8b111b9e848cc008ccc3e4525096a323fc67a12a611909c6c580569bffb26543f054e033d04839e71aa35beee6f9d3a5e9b16258c9847cc92a5f0aca9f08fa2f
6
+ metadata.gz: 7ed4efc1b2e78605eb68f8b0a8964995d69d861a124f8342d2a759ac037daa43904c1ab7ff50d3f5a39d2c482482f3a6cd653da8b1bedd4e094f9345e2b36bf5
7
+ data.tar.gz: d9c63829d0f9f462caedc2e285968b35096c3c8bb469c59dad73cb3536427da79e0e930d3d2fe722efaea77e27d30d8c6715b6d1290544fe4ed03096e895cc3c
@@ -16,9 +16,9 @@
16
16
  module IRCParser
17
17
 
18
18
  # Public: The version of IRCParser in use.
19
- VERSION = '0.4.1'
19
+ VERSION = '0.5.0'
20
20
  end
21
21
 
22
22
  require_relative 'ircparser/error'
23
23
  require_relative 'ircparser/message'
24
- require_relative 'ircparser/source'
24
+ require_relative 'ircparser/prefix'
@@ -36,17 +36,17 @@ module IRCParser
36
36
  # Public: An array of command parameters.
37
37
  attr_reader :parameters
38
38
 
39
- # Public: The source of this command or nil if unsourced.
40
- attr_reader :source
39
+ # Public: The prefix of this command or nil if unprefixd.
40
+ attr_reader :prefix
41
41
 
42
42
  # Public: A hash of IRCv3 message tags.
43
43
  attr_reader :tags
44
44
 
45
45
  # Public: Initialize a new message.
46
- def initialize command: String.new, parameters: Array.new, source: nil, tags: Hash.new
46
+ def initialize command: String.new, parameters: Array.new, prefix: nil, tags: Hash.new
47
47
  @command = command
48
48
  @parameters = parameters
49
- @source = source
49
+ @prefix = prefix
50
50
  @tags = tags
51
51
  end
52
52
 
@@ -70,9 +70,9 @@ module IRCParser
70
70
  current_token = __get_token buffer
71
71
  end
72
72
 
73
- # Have we encountered the source of this message?
73
+ # Have we encountered the prefix of this message?
74
74
  if current_token != nil && current_token[0] == ':'
75
- components[:source] = IRCParser::Source.new current_token[1..-1]
75
+ components[:prefix] = IRCParser::Prefix.new current_token[1..-1]
76
76
  current_token = __get_token buffer
77
77
  end
78
78
 
@@ -106,10 +106,10 @@ module IRCParser
106
106
  buffer += ' '
107
107
  end
108
108
 
109
- # Serialize the source.
110
- unless source.nil?
109
+ # Serialize the prefix.
110
+ unless prefix.nil?
111
111
  buffer += ':'
112
- buffer += source.to_s
112
+ buffer += prefix.to_s
113
113
  buffer += ' '
114
114
  end
115
115
 
@@ -0,0 +1,54 @@
1
+ # IRCParser - Internet Relay Chat Message Parser
2
+ #
3
+ # Copyright (C) 2015-2017 Peter "SaberUK" Powell <petpow@saberuk.com>
4
+ #
5
+ # Permission to use, copy, modify, and/or distribute this software for any purpose with or without
6
+ # fee is hereby granted, provided that the above copyright notice and this permission notice appear
7
+ # in all copies.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
10
+ # SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
+ # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
+ # OF THIS SOFTWARE.
15
+
16
+ module IRCParser
17
+
18
+ # Public: Represents the prefix of an IRC message.
19
+ class Prefix
20
+
21
+ # Internal: A regular expression which matches a n!u@h mask.
22
+ MATCH_PREFIX = /^(?<nick>[^@!]+) (?:!(?<user>[^@]+))? (?:@(?<host>.+))?$/x
23
+
24
+ # Public: The hostname of this prefix or nil if no hostname was given.
25
+ attr_reader :host
26
+
27
+ # Public: The nickname of this user.
28
+ attr_reader :nick
29
+
30
+ # Public: The username of this prefix or nil if no username was given.
31
+ attr_reader :user
32
+
33
+ # Public: Initialise a new message prefix from a serialised prefix.
34
+ #
35
+ # prefix - Either a n!u@h mask or a server name.
36
+ def initialize prefix
37
+ if MATCH_PREFIX =~ prefix
38
+ @nick = $~[:nick]
39
+ @user = $~[:user]
40
+ @host = $~[:host]
41
+ else
42
+ raise IRCParser::Error.new(prefix), 'prefix is not a user mask or server name'
43
+ end
44
+ end
45
+
46
+ # Public: serialises this prefix to the network form.
47
+ def to_s
48
+ buffer = @nick
49
+ buffer += "!#{@user}" unless @user.nil?
50
+ buffer += "@#{@host}" unless @host.nil?
51
+ return buffer
52
+ end
53
+ end
54
+ end
@@ -19,7 +19,7 @@ require 'ircparser'
19
19
  require 'minitest/autorun'
20
20
 
21
21
  describe IRCParser::Message do
22
- describe 'when checking a valid message with tags and a source' do
22
+ describe 'when checking a valid message with tags and a prefix' do
23
23
  before do
24
24
  @text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 :irc.example.com COMMAND param1 param2 :param3 param3'
25
25
  @message = IRCParser::Message.parse @text
@@ -29,8 +29,8 @@ describe IRCParser::Message do
29
29
  parameters = [ 'param1', 'param2', 'param3 param3' ]
30
30
 
31
31
  @message.tags.must_equal tags
32
- @message.source.wont_be_nil
33
- @message.source.host.must_equal 'irc.example.com'
32
+ @message.prefix.wont_be_nil
33
+ @message.prefix.nick.must_equal 'irc.example.com'
34
34
  @message.command.must_equal 'COMMAND'
35
35
  @message.parameters.must_equal parameters
36
36
  end
@@ -39,7 +39,7 @@ describe IRCParser::Message do
39
39
  end
40
40
  end
41
41
 
42
- describe 'when checking a valid message with a source but no tags' do
42
+ describe 'when checking a valid message with a prefix but no tags' do
43
43
  before do
44
44
  @text = ':irc.example.com COMMAND param1 param2 :param3 param3'
45
45
  @message = IRCParser::Message.parse @text
@@ -48,8 +48,8 @@ describe IRCParser::Message do
48
48
  parameters = [ 'param1', 'param2', 'param3 param3' ]
49
49
 
50
50
  @message.tags.must_be_empty
51
- @message.source.wont_be_nil
52
- @message.source.host.must_equal 'irc.example.com'
51
+ @message.prefix.wont_be_nil
52
+ @message.prefix.nick.must_equal 'irc.example.com'
53
53
  @message.command.must_equal 'COMMAND'
54
54
  @message.parameters.must_equal parameters
55
55
  end
@@ -58,7 +58,7 @@ describe IRCParser::Message do
58
58
  end
59
59
  end
60
60
 
61
- describe 'when checking a valid message with tags but no source' do
61
+ describe 'when checking a valid message with tags but no prefix' do
62
62
  before do
63
63
  @text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 COMMAND param1 param2 :param3 param3'
64
64
  @message = IRCParser::Message.parse @text
@@ -68,7 +68,7 @@ describe IRCParser::Message do
68
68
  parameters = [ 'param1', 'param2', 'param3 param3' ]
69
69
 
70
70
  @message.tags.must_equal tags
71
- @message.source.must_be_nil
71
+ @message.prefix.must_be_nil
72
72
  @message.command.must_equal 'COMMAND'
73
73
  @message.parameters.must_equal parameters
74
74
  end
@@ -77,7 +77,7 @@ describe IRCParser::Message do
77
77
  end
78
78
  end
79
79
 
80
- describe 'when checking a valid message with tags but no source' do
80
+ describe 'when checking a valid message with tags but no prefix' do
81
81
  before do
82
82
  @text = '@tag1=value1;tag2;vendor1/tag3=value2;vendor2/tag4 COMMAND param1 param2 :param3 param3'
83
83
  @message = IRCParser::Message.parse @text
@@ -87,7 +87,7 @@ describe IRCParser::Message do
87
87
  parameters = [ 'param1', 'param2', 'param3 param3' ]
88
88
 
89
89
  @message.tags.must_equal tags
90
- @message.source.must_be_nil
90
+ @message.prefix.must_be_nil
91
91
  @message.command.must_equal 'COMMAND'
92
92
  @message.parameters.must_equal parameters
93
93
  end
@@ -97,14 +97,14 @@ describe IRCParser::Message do
97
97
  end
98
98
 
99
99
 
100
- describe 'when checking a valid message with no tags, source or parameters' do
100
+ describe 'when checking a valid message with no tags, prefix or parameters' do
101
101
  before do
102
102
  @text = 'COMMAND'
103
103
  @message = IRCParser::Message.parse @text
104
104
  end
105
105
  it 'should consist of the correct components' do
106
106
  @message.tags.must_be_empty
107
- @message.source.must_be_nil
107
+ @message.prefix.must_be_nil
108
108
  @message.command.must_equal 'COMMAND'
109
109
  @message.parameters.must_be_empty
110
110
  end
@@ -0,0 +1,60 @@
1
+ # IRCParser - Internet Relay Chat Message Parser
2
+ #
3
+ # Copyright (C) 2015-2017 Peter "SaberUK" Powell <petpow@saberuk.com>
4
+ #
5
+ # Permission to use, copy, modify, and/or distribute this software for any purpose with or without
6
+ # fee is hereby granted, provided that the above copyright notice and this permission notice appear
7
+ # in all copies.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
10
+ # SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
+ # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13
+ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
+ # OF THIS SOFTWARE.
15
+
16
+ $LOAD_PATH.unshift "#{Dir.pwd}/lib"
17
+
18
+ require 'ircparser'
19
+ require 'minitest/autorun'
20
+
21
+ describe IRCParser::Prefix do
22
+ PREFIXES = {
23
+ 'nick!user@host' => { nick: 'nick', user: 'user', host: 'host' },
24
+ 'nick!user' => { nick: 'nick', user: 'user', host: nil },
25
+ 'nick@host' => { nick: 'nick', user: nil, host: 'host' },
26
+ 'nick' => { nick: 'nick', user: nil, host: nil },
27
+ 'irc.example.com' => { nick: 'irc.example.com', user: nil, host: nil },
28
+ }
29
+
30
+ PREFIXES.each do |serialized, deserialized|
31
+ describe 'when checking a valid prefix' do
32
+ before do
33
+ @prefix = IRCParser::Prefix.new serialized
34
+ end
35
+ it 'should consist of the correct components' do
36
+ %i(nick user host).each do |component|
37
+ if deserialized[component].nil?
38
+ @prefix.send(component).must_be_nil
39
+ else
40
+ @prefix.send(component).must_equal deserialized[component]
41
+ end
42
+ end
43
+ end
44
+ it 'should serialise back to the same text' do
45
+ @prefix.to_s.must_equal serialized
46
+ end
47
+ end
48
+ end
49
+
50
+ describe 'when checking an invalid user prefix' do
51
+ it 'should throw an IRCParser::Error when components are missing' do
52
+ proc { IRCParser::Prefix.new 'nick!@' }.must_raise IRCParser::Error
53
+ proc { IRCParser::Prefix.new '!user@' }.must_raise IRCParser::Error
54
+ proc { IRCParser::Prefix.new '!@host' }.must_raise IRCParser::Error
55
+ proc { IRCParser::Prefix.new 'nick!user@' }.must_raise IRCParser::Error
56
+ proc { IRCParser::Prefix.new 'nick!@host' }.must_raise IRCParser::Error
57
+ proc { IRCParser::Prefix.new '!user@host' }.must_raise IRCParser::Error
58
+ end
59
+ end
60
+ end
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.1
4
+ version: 0.5.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: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -67,9 +67,9 @@ files:
67
67
  - lib/ircparser.rb
68
68
  - lib/ircparser/error.rb
69
69
  - lib/ircparser/message.rb
70
- - lib/ircparser/source.rb
70
+ - lib/ircparser/prefix.rb
71
71
  - test/test_message.rb
72
- - test/test_source.rb
72
+ - test/test_prefix.rb
73
73
  homepage: https://github.com/SaberUK/ircparser
74
74
  licenses:
75
75
  - ISC
@@ -1,79 +0,0 @@
1
- # IRCParser - Internet Relay Chat Message Parser
2
- #
3
- # Copyright (C) 2015-2017 Peter "SaberUK" Powell <petpow@saberuk.com>
4
- #
5
- # Permission to use, copy, modify, and/or distribute this software for any purpose with or without
6
- # fee is hereby granted, provided that the above copyright notice and this permission notice appear
7
- # in all copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
10
- # SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
- # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13
- # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
- # OF THIS SOFTWARE.
15
-
16
- module IRCParser
17
-
18
- # Public: Represents the source of an IRC message.
19
- class Source
20
-
21
- # Internal: A regular expression which matches a n!u@h mask.
22
- MATCH_USER = /^(?<nick>[^@!]+) (?:!(?<user>[^@]+))? (?:@(?<host>.+))?$/x
23
-
24
- # Internal: A regular expression which matches a server name.
25
- MATCH_SERVER = /^(?<host>\S+\.\S+)$/
26
-
27
- # Public: The hostname of this source.
28
- attr_reader :host
29
-
30
- # Public: The nickname of this user or nil if the source is a server.
31
- attr_reader :nick
32
-
33
- # Public: The username of this user or nil if the source is a server.
34
- attr_reader :user
35
-
36
- # Public: Initialise a new message source from a serialised source.
37
- #
38
- # source - Either a n!u@h mask or a server name.
39
- def initialize source
40
- if MATCH_SERVER =~ source
41
- @type = :server
42
- @host = $~[:host]
43
- elsif MATCH_USER =~ source
44
- @type = :user
45
- @nick = $~[:nick]
46
- @user = $~[:user]
47
- @host = $~[:host]
48
- else
49
- raise IRCParser::Error.new(source), 'source is not a user mask or server name'
50
- end
51
- end
52
-
53
- # Public: Whether this source represents a user.
54
- def is_user?
55
- return @type == :user
56
- end
57
-
58
- # Public: Whether this source represents a server.
59
- def is_server?
60
- return @type == :server
61
- end
62
-
63
- # Public: The name by which this source can be identified.
64
- def name
65
- return is_user? ? @nick : @host
66
- end
67
-
68
- # Public: serialises this source to the serialised form.
69
- def to_s
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
77
- end
78
- end
79
- end
@@ -1,78 +0,0 @@
1
- # IRCParser - Internet Relay Chat Message Parser
2
- #
3
- # Copyright (C) 2015-2017 Peter "SaberUK" Powell <petpow@saberuk.com>
4
- #
5
- # Permission to use, copy, modify, and/or distribute this software for any purpose with or without
6
- # fee is hereby granted, provided that the above copyright notice and this permission notice appear
7
- # in all copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
10
- # SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
- # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
13
- # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
- # OF THIS SOFTWARE.
15
-
16
- $LOAD_PATH.unshift "#{Dir.pwd}/lib"
17
-
18
- require 'ircparser'
19
- require 'minitest/autorun'
20
-
21
- describe IRCParser::Source do
22
- describe 'when checking a valid server source' do
23
- before do
24
- @text = 'irc.example.com'
25
- @source = IRCParser::Source.new @text
26
- end
27
- it 'should consist of the correct components' do
28
- @source.nick.must_be_nil
29
- @source.user.must_be_nil
30
- @source.host.must_equal 'irc.example.com'
31
- end
32
- it 'should be a server not a user' do
33
- @source.is_server?.must_equal true
34
- @source.is_user?.must_equal false
35
- end
36
- it 'should serialise back to the same text' do
37
- @source.to_s.must_equal @text
38
- end
39
- end
40
-
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
- }
47
-
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
65
- end
66
- end
67
-
68
- describe 'when checking an invalid user source' do
69
- it 'should throw an IRCParser::Error when components are missing' do
70
- proc { IRCParser::Source.new 'nick!@' }.must_raise IRCParser::Error
71
- proc { IRCParser::Source.new '!user@' }.must_raise IRCParser::Error
72
- proc { IRCParser::Source.new '!@host' }.must_raise IRCParser::Error
73
- proc { IRCParser::Source.new 'nick!user@' }.must_raise IRCParser::Error
74
- proc { IRCParser::Source.new 'nick!@host' }.must_raise IRCParser::Error
75
- proc { IRCParser::Source.new '!user@host' }.must_raise IRCParser::Error
76
- end
77
- end
78
- end