ircparser 0.7.0 → 1.0.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
  SHA256:
3
- metadata.gz: c6b7566a57bb2e617b579c0ce2a174b66f96af0da0ed94efdeae3688f7a23cdb
4
- data.tar.gz: 90e612dea1ea55b93896ebfdfb4d44880b021191120d2c49119785883b2e6bbc
3
+ metadata.gz: f160e7c21dcbbbbdcfb6662e8d035fe78679eb93dc2f8ee1a89700e5818ffc65
4
+ data.tar.gz: 137cd1cec698ae345b02a89cd4bf508359726b3353a400307cdbf4c467e70042
5
5
  SHA512:
6
- metadata.gz: ec325e4e96dbd73405c3b4815be8028e0243855af8c7f3889a34ad1ab7a3325bd64c11e8fcd08b63eea7444ec08bfe1dea56a6534f7dfe6dd7640b78baa04079
7
- data.tar.gz: 53a1b4419baf3a2e56f51f5ff4e6bc586ac9b7217904704a80ae6a1bc603681b87a5f0d9e174ef2edc8dc73f54fcd05e35ffe2884d603b37bfe980912e3c27df
6
+ metadata.gz: b3622b7fbccc84758655416346579e6b2b5f998276312383c88282c7dfdb03e25fdadd5f43b3c0f6629eadef06ad4bf9900b0f6e1391841e10bb21c917a87daf
7
+ data.tar.gz: 7b7d58d02649e57d9ad0ece55831e71e238746662f371bf2fb6679954068e004a6078ff0c611348b05baca45944e2ad1c491381ae117b07e1717524e1352b50d
@@ -13,14 +13,9 @@
13
13
  # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
14
14
  # OF THIS SOFTWARE.
15
15
 
16
- module IRCParser
17
-
18
- # Public: The version of IRCParser in use.
19
- VERSION = '0.7.0'
20
- end
21
-
22
16
  require_relative 'ircparser/error'
23
17
  require_relative 'ircparser/message'
24
18
  require_relative 'ircparser/prefix'
25
19
  require_relative 'ircparser/stream'
26
20
  require_relative 'ircparser/wire/rfc'
21
+ require_relative 'ircparser/version'
@@ -50,7 +50,7 @@ module IRCParser
50
50
  return IRCParser::RFCWireFormat.objectify line
51
51
  end
52
52
 
53
- # Public: Serializes the message to a string.
53
+ # Public: Serializes the message to a string.
54
54
  def to_s
55
55
  return IRCParser::RFCWireFormat.stringify self
56
56
  end
@@ -0,0 +1,36 @@
1
+ # IRCParser - Internet Relay Chat Message Parser
2
+ #
3
+ # Copyright (C) 2015-2020 Sadie Powell <sadie@witchery.services>
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: The version number which is incremented when compatibility is broken.
19
+ VERSION_MAJOR = 1
20
+
21
+ # Public: The version number which is incremented when new features are added.
22
+ VERSION_MINOR = 0
23
+
24
+ # Public: The version number which is incremented when bugs are fixed.
25
+ VERSION_PATCH = 0
26
+
27
+ # Public: The version label which describes the status of the build.
28
+ VERSION_LABEL = nil
29
+
30
+ # Public: A string which contains the current version.
31
+ VERSION = if VERSION_LABEL.nil?
32
+ "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}".freeze
33
+ else
34
+ "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}-#{VERSION_LABEL}".freeze
35
+ end
36
+ end
@@ -18,6 +18,7 @@ module IRCParser
18
18
  # Internal: Implements objectification and stringification for the RFC wire format.
19
19
  module RFCWireFormat
20
20
 
21
+ # Internal: Tokenizer for the RFC wire format.
21
22
  class MessageTokenizer
22
23
 
23
24
  def initialize message
@@ -32,7 +33,7 @@ module IRCParser
32
33
  return nil if @position >= @message.length
33
34
  old_position = @position
34
35
  @position = @message.index(' ', old_position) || @message.length
35
- return nil unless @position - old_position > 0
36
+ return nil unless (@position - old_position).positive?
36
37
  token = @message.slice old_position...@position
37
38
  @position = @message.index(/\S+/, @position) || @message.length
38
39
  return token
@@ -60,7 +61,7 @@ module IRCParser
60
61
 
61
62
  # Ruby really needs some kind of basic type checking.
62
63
  unless str.is_a? String
63
- raise IRCParser::Error.new(str), "message is not a String"
64
+ raise IRCParser::Error.new(str), 'message is not a String'
64
65
  end
65
66
 
66
67
  # Split the message up into an array of tokens.
@@ -70,19 +71,19 @@ module IRCParser
70
71
 
71
72
  # Have we encountered IRCv3 message tags?
72
73
  components[:tags] = Hash.new
73
- if current_token != nil && current_token[0] == '@'
74
+ if !current_token.nil? && current_token[0] == '@'
74
75
  components[:tags] = self.__objectify_tags current_token
75
76
  current_token = tokenizer.read_middle
76
77
  end
77
78
 
78
79
  # Have we encountered the prefix of this message?
79
- if current_token != nil && current_token[0] == ':'
80
+ if !current_token.nil? && current_token[0] == ':'
80
81
  components[:prefix] = self.__objectify_prefix current_token
81
82
  current_token = tokenizer.read_middle
82
83
  end
83
84
 
84
85
  # The command parameter is mandatory.
85
- if current_token != nil
86
+ unless current_token.nil?
86
87
  components[:command] = current_token.upcase
87
88
  current_token = tokenizer.read_trailing
88
89
  else
@@ -91,12 +92,12 @@ module IRCParser
91
92
 
92
93
  # Try to parse all of the remaining parameters.
93
94
  components[:parameters] = Array.new
94
- while current_token != nil
95
+ while !current_token.nil?
95
96
  components[:parameters] << current_token
96
97
  current_token = tokenizer.read_trailing
97
98
  end
98
99
 
99
- return IRCParser::Message.new components
100
+ return IRCParser::Message.new **components
100
101
  end
101
102
 
102
103
  # Internal: Stringifies a message from an IRCParser::Message to the RFC wire format.
@@ -106,7 +107,7 @@ module IRCParser
106
107
 
107
108
  # Ruby really needs some kind of basic type checking.
108
109
  unless obj.is_a? IRCParser::Message
109
- raise IRCParser::Error.new(obj), "message is not an IRCParser::Message"
110
+ raise IRCParser::Error.new(obj), 'message is not an IRCParser::Message'
110
111
  end
111
112
 
112
113
  # Stringify the tags.
@@ -134,13 +135,11 @@ module IRCParser
134
135
  return buffer
135
136
  end
136
137
 
137
- private
138
-
139
138
  # Internal: A regular expression which matches a n!u@h mask.
140
- MATCH_PREFIX = /^:(?<nick>[^@!]+) (?:!(?<user>[^@]+))? (?:@(?<host>.+))?$/x
139
+ MATCH_PREFIX = /^:(?<nick>[^@!]+) (?:!(?<user>[^@]+))? (?:@(?<host>.+))?$/x.freeze
141
140
 
142
141
  # Internal: A regular expression which matches a tag.
143
- MATCH_TAG = /^(?<name>[^\s=]+?)(?:=(?<value>[^\s;]+))?$/
142
+ MATCH_TAG = /^(?<name>[^\s=]+?)(?:=(?<value>[^\s;]+))?$/.freeze
144
143
 
145
144
  # Internal: The characters which need to be escaped in tag values.
146
145
  TAG_ESCAPES = {
@@ -149,7 +148,7 @@ module IRCParser
149
148
  '\s' => "\s",
150
149
  '\r' => "\r",
151
150
  '\n' => "\n",
152
- }
151
+ }.freeze
153
152
 
154
153
  # Internal: Objectifies the prefix from the RFC wire format to an IRCParser::Prefix.
155
154
  #
@@ -170,7 +169,7 @@ module IRCParser
170
169
  if tag =~ MATCH_TAG
171
170
  value = String.new
172
171
  value_index = 0
173
- while $~['value'] != nil && value_index < $~['value'].size
172
+ while !$~['value'].nil? && value_index < $~['value'].size
174
173
  if $~['value'][value_index] == '\\'
175
174
  escape = $~['value'].slice(value_index, 2)
176
175
  if TAG_ESCAPES.include? escape
@@ -233,10 +232,10 @@ module IRCParser
233
232
  unless value.nil? || value.empty?
234
233
  buffer += '='
235
234
  value.each_char do |chr|
236
- if TAG_ESCAPES.has_value? chr
237
- buffer += TAG_ESCAPES.key chr
235
+ buffer += if TAG_ESCAPES.value? chr
236
+ TAG_ESCAPES.key chr
238
237
  else
239
- buffer += chr
238
+ chr
240
239
  end
241
240
  end
242
241
  end
@@ -96,13 +96,12 @@ describe IRCParser::Message do
96
96
  end
97
97
  end
98
98
 
99
-
100
99
  describe 'when checking a valid message with no tags, prefix or parameters' do
101
100
  before do
102
101
  @text = 'COMMAND'
103
102
  @message = IRCParser::Message.parse @text
104
103
  end
105
- it 'should consist of the correct components' do
104
+ it 'should consist of the correct components' do
106
105
  _(@message.tags).must_be_empty
107
106
  _(@message.prefix).must_be_nil
108
107
  _(@message.command).must_equal 'COMMAND'
@@ -242,4 +241,4 @@ describe IRCParser::Message do
242
241
  }).must_raise IRCParser::Error
243
242
  end
244
243
  end
245
- end
244
+ end
@@ -45,7 +45,7 @@ describe IRCParser::Prefix do
45
45
  user: nil,
46
46
  host: nil
47
47
  },
48
- }
48
+ }.freeze
49
49
 
50
50
  PREFIXES.each do |serialized, deserialized|
51
51
  describe 'when checking a valid prefix' do
@@ -75,7 +75,7 @@ describe IRCParser::Prefix do
75
75
  'nick!user@',
76
76
  'nick!@host',
77
77
  '!user@host',
78
- ]
78
+ ].freeze
79
79
 
80
80
  MALFORMED.each do |prefix|
81
81
  describe 'when checking an invalid user prefix' do
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.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadie Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-05 00:00:00.000000000 Z
11
+ date: 2020-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -63,6 +63,7 @@ files:
63
63
  - lib/ircparser/message.rb
64
64
  - lib/ircparser/prefix.rb
65
65
  - lib/ircparser/stream.rb
66
+ - lib/ircparser/version.rb
66
67
  - lib/ircparser/wire/rfc.rb
67
68
  - test/test_message.rb
68
69
  - test/test_prefix.rb
@@ -78,7 +79,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
79
  requirements:
79
80
  - - ">="
80
81
  - !ruby/object:Gem::Version
81
- version: 2.0.0
82
+ version: 2.5.0
82
83
  required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  requirements:
84
85
  - - ">="