ircp 1.1.2 → 1.1.3
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.
- data/lib/ircp/message.rb +18 -3
- data/lib/ircp/prefix.rb +3 -3
- data/lib/ircp/version.rb +1 -1
- data/spec/ircp/message_spec.rb +19 -2
- data/spec/ircp/prefix_spec.rb +2 -2
- metadata +4 -4
data/lib/ircp/message.rb
CHANGED
@@ -2,6 +2,8 @@ require 'ircp/prefix'
|
|
2
2
|
|
3
3
|
module Ircp
|
4
4
|
class Message
|
5
|
+
CRLF = "\r\n"
|
6
|
+
|
5
7
|
attr_accessor :raw, :prefix, :command, :params
|
6
8
|
|
7
9
|
def initialize(*args)
|
@@ -13,14 +15,27 @@ module Ircp
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def inspect
|
16
|
-
variables = instance_variables.map { |name| "#{name
|
18
|
+
variables = instance_variables.map { |name| "#{name}=#{instance_variable_get(name).inspect}" }
|
17
19
|
variables.unshift "#{self.class}"
|
18
20
|
"<#{variables.join ' '}>"
|
19
21
|
end
|
20
22
|
|
21
23
|
def to_irc
|
22
|
-
|
23
|
-
|
24
|
+
command = @command.to_s.upcase
|
25
|
+
|
26
|
+
tokens = []
|
27
|
+
tokens << ":#{@prefix}" if @prefix
|
28
|
+
tokens << command
|
29
|
+
|
30
|
+
unless @params.empty?
|
31
|
+
last = @params.pop.to_s
|
32
|
+
last.insert 0, ':' if !last.start_with?(':') && last.include?(' ')
|
33
|
+
@params << last
|
34
|
+
end
|
35
|
+
tokens += @params
|
36
|
+
|
37
|
+
msg = tokens.map { |token| token.to_s } .reject { |token| token.empty? }.join(' ')
|
38
|
+
msg << CRLF unless msg.end_with?(CRLF)
|
24
39
|
msg
|
25
40
|
end
|
26
41
|
alias_method :to_s, :to_irc
|
data/lib/ircp/prefix.rb
CHANGED
@@ -15,16 +15,16 @@ module Ircp
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def inspect
|
18
|
-
variables = instance_variables.map { |name| "#{name
|
18
|
+
variables = instance_variables.map { |name| "#{name}=#{instance_variable_get(name).inspect}" }
|
19
19
|
variables.unshift "#{self.class}"
|
20
20
|
"<#{variables.join ' '}>"
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_irc
|
24
24
|
if @servername
|
25
|
-
"
|
25
|
+
"#{servername}"
|
26
26
|
else
|
27
|
-
[['
|
27
|
+
[['', @nick], ['!', @user], ['@', @host]].map do |mark, value|
|
28
28
|
"#{mark}#{value}" unless value.to_s.empty?
|
29
29
|
end.compact.join('')
|
30
30
|
end
|
data/lib/ircp/version.rb
CHANGED
data/spec/ircp/message_spec.rb
CHANGED
@@ -25,7 +25,24 @@ describe Ircp::Message do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#to_s' do
|
28
|
-
|
29
|
-
|
28
|
+
context ":command => 'test', :params => ['foo', 'bar', 'buzz']" do
|
29
|
+
include_context 'initialize message', :command => 'TEST', :params => ['foo', 'bar', 'buzz']
|
30
|
+
it { subject.to_s.should eq "TEST foo bar buzz\r\n" }
|
31
|
+
end
|
32
|
+
|
33
|
+
context ":command => 'TEST', :params => ['foo', 'bar buzz']" do
|
34
|
+
include_context 'initialize message', :command => 'TEST', :params => ['foo', 'bar buzz']
|
35
|
+
it { subject.to_s.should eq "TEST foo :bar buzz\r\n" }
|
36
|
+
end
|
37
|
+
|
38
|
+
context ":prefix => {:servername => 'example.com'}, :command => 'TEST', :params => ['foo', 'bar buzz']" do
|
39
|
+
include_context 'initialize message', :prefix => {:servername => 'example.com'}, :command => 'TEST', :params => ['foo', 'bar buzz']
|
40
|
+
it { subject.to_s.should eq ":example.com TEST foo :bar buzz\r\n" }
|
41
|
+
end
|
42
|
+
|
43
|
+
context ":prefix => {:servername => 'example.com'}, :command => 'TEST', :params => ['foo', ':bar buzz']" do
|
44
|
+
include_context 'initialize message', :prefix => {:servername => 'example.com'}, :command => 'TEST', :params => ['foo', ':bar buzz']
|
45
|
+
it { subject.to_s.should eq ":example.com TEST foo :bar buzz\r\n" }
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
data/spec/ircp/prefix_spec.rb
CHANGED
@@ -21,13 +21,13 @@ describe Ircp::Prefix do
|
|
21
21
|
context 'with servername' do
|
22
22
|
before { @prefix = Ircp::Prefix.new(:servername => 'example.com') }
|
23
23
|
subject { @prefix }
|
24
|
-
its(:to_s) { should eq '
|
24
|
+
its(:to_s) { should eq 'example.com' }
|
25
25
|
end
|
26
26
|
|
27
27
|
context 'with nick, user and host' do
|
28
28
|
before { @prefix = Ircp::Prefix.new(:nick => 'foo', :user => 'bar', :host => 'example.com') }
|
29
29
|
subject { @prefix }
|
30
|
-
its(:to_s) { should eq '
|
30
|
+
its(:to_s) { should eq 'foo!bar@example.com' }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ircp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
segments:
|
101
101
|
- 0
|
102
|
-
hash:
|
102
|
+
hash: 3404966832797746809
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: 3404966832797746809
|
112
112
|
requirements: []
|
113
113
|
rubyforge_project:
|
114
114
|
rubygems_version: 1.8.21
|