irc_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +105 -0
  3. data/Rakefile +155 -0
  4. data/extra/benchmark.rb +41 -0
  5. data/irc_parser.gemspec +98 -0
  6. data/lib/irc_parser.rb +25 -0
  7. data/lib/irc_parser/factory.erb +53 -0
  8. data/lib/irc_parser/helper.rb +71 -0
  9. data/lib/irc_parser/messages.rb +96 -0
  10. data/lib/irc_parser/messages/commands.rb +274 -0
  11. data/lib/irc_parser/messages/errors.rb +51 -0
  12. data/lib/irc_parser/messages/replies.rb +212 -0
  13. data/lib/irc_parser/parser.rb +557 -0
  14. data/lib/irc_parser/parser.rl +89 -0
  15. data/spec/fixtures/from_weechat.rb +24 -0
  16. data/spec/fixtures/inbound.log +3959 -0
  17. data/spec/irc_parser/helper_spec.rb +32 -0
  18. data/spec/irc_parser/irc_parser_spec.rb +12 -0
  19. data/spec/irc_parser/messages_spec.rb +195 -0
  20. data/spec/irc_parser/parser_spec.rb +9 -0
  21. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_1_password_message_spec.rb +28 -0
  22. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_2_nick_message_spec.rb +35 -0
  23. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_3_user_message_spec.rb +47 -0
  24. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_4_server_message_spec.rb +33 -0
  25. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_5_oper_spec.rb +17 -0
  26. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_6_quit_spec.rb +17 -0
  27. data/spec/irc_parser/rfc1459/4_1_connection_registration/4_1_7_server_quit_message_spec.rb +32 -0
  28. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_1_join_message_spec.rb +65 -0
  29. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_2_part_message_spec.rb +23 -0
  30. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_3_1_channel_modes_spec.rb +159 -0
  31. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_3_2_user_modes_spec.rb +55 -0
  32. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_4_topic_message_spec.rb +36 -0
  33. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_5_names_message_spec.rb +25 -0
  34. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_6_list_message_spec.rb +23 -0
  35. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_7_invite_message_spec.rb +31 -0
  36. data/spec/irc_parser/rfc1459/4_2_channel_operations/4_2_8_kick_command_spec.rb +56 -0
  37. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_1_version_message_spec.rb +30 -0
  38. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_2_stats_message_spec.rb +32 -0
  39. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_3_links_message_spec.rb +31 -0
  40. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_4_time_message_spec.rb +34 -0
  41. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_5_connect_message_spec.rb +32 -0
  42. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_6_trace_message_spec.rb +28 -0
  43. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_7_admin_command_spec.rb +28 -0
  44. data/spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_8_info_command_spec.rb +38 -0
  45. data/spec/irc_parser/rfc1459/4_4_sending_messages/4_4_1_private_messages_spec.rb +63 -0
  46. data/spec/irc_parser/rfc1459/4_4_sending_messages/4_4_2_notice_spec.rb +63 -0
  47. data/spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_1_who_query_spec.rb +27 -0
  48. data/spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_2_whois_query_spec.rb +27 -0
  49. data/spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_3_whowas_spec.rb +40 -0
  50. data/spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_1_kill_message_spec.rb +20 -0
  51. data/spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_2_ping_message_spec.rb +35 -0
  52. data/spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_3_pong_message_spec.rb +26 -0
  53. data/spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_4_error_spec.rb +26 -0
  54. data/spec/irc_parser/rfc1459/5_0_optionals/5_1_0_away_spec.rb +25 -0
  55. data/spec/irc_parser/rfc1459/5_0_optionals/5_2_0_rehash_message_spec.rb +14 -0
  56. data/spec/irc_parser/rfc1459/5_0_optionals/5_3_0_restart_message_spec.rb +14 -0
  57. data/spec/irc_parser/rfc1459/5_0_optionals/5_4_0_summon_message_spec.rb +28 -0
  58. data/spec/irc_parser/rfc1459/5_0_optionals/5_5_0_users_spec.rb +27 -0
  59. data/spec/irc_parser/rfc1459/5_0_optionals/5_6_0_operwall_message_spec.rb +17 -0
  60. data/spec/irc_parser/rfc1459/5_0_optionals/5_7_0_userhost_message_spec.rb +16 -0
  61. data/spec/irc_parser/rfc1459/5_0_optionals/5_8_0_ison_message_spec.rb +16 -0
  62. data/spec/irc_parser/rfc1459/6_0_replies/6_1_error_parsing_spec.rb +488 -0
  63. data/spec/irc_parser/rfc1459/6_0_replies/6_2_command_responses_generation_spec.rb +934 -0
  64. data/spec/irc_parser/rfc2812/5_1_command_responses/5_1_command_responses_spec.rb +63 -0
  65. data/spec/spec_helper.rb +12 -0
  66. data/spec/support/messages_helper.rb +24 -0
  67. data/spec/support/simplecov.rb +12 -0
  68. metadata +185 -0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Emmanuel Oga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # IRCParser
2
+
3
+ A ruby 1.9.x parser for IRC messages which includes commands, errors and
4
+ replies classese according to the IRC RFCs definitions.
5
+
6
+ This library does not deal at all with networking.
7
+
8
+ ## Goals
9
+
10
+ In every irc library I've seen people implement the various irc messages
11
+ again and again.
12
+
13
+ IRCParser tackles that boring task so the hard work in making the RFC
14
+ compliant IRC messages can be shared across projects.
15
+
16
+ ## Anatomy of an IRC message
17
+
18
+ All irc messages have the same structure:
19
+
20
+ [optional prefix] COMMAND_NAME [optional_param [optional_param2, ...]] [optional postfix]
21
+
22
+ * The prefix always denotes a server or user name, and starts with ':'.
23
+ * The params are completely optional. IRCParser gives all params
24
+ apropriate names reflecting those found on the RFCs.
25
+ * The postfix is the last parameter. IRCParser sometimes aliases the
26
+ postfix to something more readable for some messages (e.g. 'body' for
27
+ PRIVMSG). The only kind of parameters which can embed spaces are the
28
+ postfixes.
29
+
30
+ ## Parsing Messages
31
+
32
+ The parser can be run so it returns the raw components of an irc message
33
+ ([prefix, command, *params]), or an specific class for each kind of
34
+ message constructed from those parts.
35
+
36
+ The parser is quite strict so it will expect the IRC delimiters in all
37
+ messages to parse (i.e. all messages must end with '\r\n').
38
+
39
+ ```ruby
40
+ require 'irc_parser'
41
+
42
+ # returns prefix, command, params. Notice final \r\n
43
+ IRCParser.parse_raw(":Angel PRIVMSG Wiz :Hello are you receiving this message?\r\n")
44
+
45
+ # => ["Angel", "PRIVMSG", ["Wiz", "Hello are you receiving this message ?"]]
46
+ ```
47
+
48
+ To get a subclass of IRCParser::Message instead of an array of components:
49
+
50
+ ```ruby
51
+ require 'irc_parser/messages'
52
+ msg = IRCParser.parse(":Angel PRIVMSG Wiz :Hello are you receiving this message?\r\n")
53
+ # <IRCParser::Messages::Privmsg:0x00000001476370 @params=["Wiz", "Hello are you receiving this message?"], @prefix="Angel">
54
+
55
+ msg.identifier # => "PRIVMSG"
56
+ msg.to_sym # => :priv_msg
57
+ msg.prefix # => "Angel"
58
+ msg.params # => ["Wiz", "Hello are you receiving this message?"]
59
+ msg.from # => "Angel"
60
+ msg.target # => "Wiz"
61
+ msg.body # => "Hello are you receiving this message?"
62
+ ```
63
+
64
+ ## Generating Messages
65
+
66
+ ```ruby
67
+ msg = IRCParser::Messages::PrivMsg.new
68
+ msg.from = "Wiz"
69
+ msg.target = "Angel"
70
+ msg.body = "Hello World!"
71
+ msg.to_s # => ":Wiz PRIVMSG Angel :Hello World!\r\n"
72
+ ```
73
+
74
+ There is also a shortcut:
75
+
76
+ ```ruby
77
+ require 'irc_parser/messages'
78
+ msg = IRCParser.message(:privmsg) do |m|
79
+ msg.from = "Wiz"
80
+ msg.target = "Angel"
81
+ msg.body = "Hello World!"
82
+ end
83
+ msg.to_s # => ":Wiz PRIVMSG Angel :Hello World!\r\n"
84
+ ```
85
+
86
+ ## TODO
87
+
88
+ * Documentation!
89
+ * It would be nice to add support for parsing/generating extended mirc
90
+ messages.
91
+ * Most severs/clients do not implement the messages exactly as defined
92
+ on the RFCs (sometimes http://www.mirc.net/raws/ was used as
93
+ reference). So, some messages may require adjustments to be usable
94
+ in the wild.
95
+ * 1459 compliant, with some of the messages updated to the rfc 2812.
96
+ Fixes/updates are warmly welcome!
97
+
98
+ ## AUTHORS
99
+
100
+ A lot of projects where reviewed while implementing this library. I may
101
+ or may not have stolen something from one of these, although off course
102
+ I'm the only one to blame for the contents of this gem. If I forget
103
+ about anyone please ping me so I can include you here.
104
+
105
+ * Ragel parser and other portions where taken from irk (brodock/irk)
data/Rakefile ADDED
@@ -0,0 +1,155 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ require 'rspec/core/rake_task'
47
+
48
+ RSpec::Core::RakeTask.new(:spec) do |spec|
49
+ spec.ruby_opts = '-Ilib/ -Ispec/'
50
+ spec.pattern = 'spec/**/*_spec.rb'
51
+ end
52
+
53
+ begin
54
+ require 'simplecov'
55
+ rescue LoadError
56
+ puts "simplecov gem is not available. Install it to get coverage reports"
57
+ else
58
+ RSpec::Core::RakeTask.new(:simplecov) do |spec|
59
+ spec.ruby_opts = '-I. -Ilib/ -Ispec/ -rspec/support/simplecov'
60
+ spec.pattern = 'spec/**/*_spec.rb'
61
+ end
62
+ end
63
+
64
+ task :default => :spec
65
+
66
+ desc "Open an irb session preloaded with this library"
67
+ task :console do
68
+ sh "irb -I ./lib/ -rubygems -r ./lib/#{name}.rb"
69
+ end
70
+
71
+ #############################################################################
72
+ #
73
+ # Custom tasks (add your own tasks here)
74
+ #
75
+ #############################################################################
76
+
77
+ begin
78
+ require 'yard'
79
+ YARD::Rake::YardocTask.new do |yard|
80
+ end
81
+ rescue LoadError
82
+ desc "generate documentation"
83
+ task :yard do
84
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
85
+ end
86
+ end
87
+
88
+ desc "compile the ragel parser"
89
+ task :ragel do
90
+ system("ragel -F1 -R lib/irc_parser/parser.rl")
91
+ end
92
+
93
+ #############################################################################
94
+ #
95
+ # Packaging tasks
96
+ #
97
+ #############################################################################
98
+
99
+ task :release => [:ragel, :build] do
100
+ unless `git branch` =~ /^\* master$/
101
+ puts "You must be on the master branch to release!"
102
+ exit!
103
+ end
104
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
105
+ sh "git tag v#{version}"
106
+ sh "git push origin master"
107
+ sh "git push --tags"
108
+ sh "gem push pkg/#{name}-#{version}.gem"
109
+ end
110
+
111
+ task :build => :gemspec do
112
+ sh "mkdir -p pkg"
113
+ sh "gem build #{gemspec_file}"
114
+ sh "mv #{gem_file} pkg"
115
+ end
116
+
117
+ task :gemspec => :validate do
118
+ # read spec file and split out manifest section
119
+ spec = File.read(gemspec_file)
120
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
121
+
122
+ # replace name version and date
123
+ replace_header(head, :name)
124
+ replace_header(head, :version)
125
+ replace_header(head, :date)
126
+ #comment this out if your rubyforge_project has a different name
127
+ replace_header(head, :rubyforge_project)
128
+
129
+ # determine file list from git ls-files
130
+ files = `git ls-files`.
131
+ split("\n").
132
+ sort.
133
+ reject { |file| file =~ /^\./ }.
134
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
135
+ map { |file| " #{file}" }.
136
+ join("\n")
137
+
138
+ # piece file back together and write
139
+ manifest = " s.files = %w[\n#{files}\n ]\n"
140
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
141
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
142
+ puts "Updated #{gemspec_file}"
143
+ end
144
+
145
+ task :validate do
146
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
147
+ unless libfiles.empty?
148
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
149
+ exit!
150
+ end
151
+ unless Dir['VERSION*'].empty?
152
+ puts "A `VERSION` file at root level violates Gem best practices."
153
+ exit!
154
+ end
155
+ end
@@ -0,0 +1,41 @@
1
+ require 'irc_parser'
2
+ require 'benchmark'
3
+
4
+ MSG1 = "200 Wiz Link 1.10 destination.com next_server.net\r\n"
5
+ MSG2 = "PRIVMSG #*.edu :NSFNet is undergoing work, expect interruptions\r\n"
6
+
7
+ IRCMessage = IRCParser.message(:priv_msg) do |msg|
8
+ msg.prefix= "Angel"
9
+ msg.target= "Wiz"
10
+ msg.body= "Hello are you receiving this message ?"
11
+ end.to_s
12
+
13
+ $BEFORE_BENCHMARK = `ps -Orss -p #{$$}`.split[7].to_i
14
+
15
+ Benchmark.bmbm do |rep|
16
+ rep.report("parsing / generation") do
17
+ 10_000.times do
18
+ IRCParser.parse(MSG1).to_s
19
+ IRCParser.parse(MSG2).to_s
20
+ end
21
+ 10_000.times do
22
+ IRCParser.message(:priv_msg) do |msg|
23
+ msg.prefix= "Angel"
24
+ msg.target= "Wiz"
25
+ msg.body= "Hello are you receiving this message ?"
26
+ end.to_s
27
+ end
28
+ end
29
+
30
+ rep.report("generation") do
31
+ 20_000.times do
32
+ IRCMessage.to_s
33
+ end
34
+ end
35
+ end
36
+
37
+ at_exit do
38
+ $AFTER_BENCHMARK = `ps -Orss -p #{$$}`.split[7].to_i
39
+
40
+ puts "Used: " << ($AFTER_BENCHMARK - $BEFORE_BENCHMARK).to_s << " Kilobytes."
41
+ end
@@ -0,0 +1,98 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'irc_parser'
7
+ s.version = '0.1.0'
8
+ s.date = '2011-08-08'
9
+ s.rubyforge_project = 'irc_parser'
10
+
11
+ s.summary = "Parses and generates IRC protocol messages."
12
+ s.description = "A ruby 1.9.x library to parse and generate IRC messages according to the IRC definition"
13
+
14
+ s.authors = ["Emmanuel Oga"]
15
+ s.email = 'EmmanuelOga@gmail.com'
16
+ s.homepage = 'http://github.com/EmmanuelOga/irc_parser'
17
+
18
+ s.require_paths = %w[lib]
19
+
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.extra_rdoc_files = %w[README.md LICENSE]
22
+
23
+ s.add_development_dependency('rspec', ["~> 2.0.0"])
24
+
25
+ # = MANIFEST =
26
+ s.files = %w[
27
+ LICENSE
28
+ README.md
29
+ Rakefile
30
+ extra/benchmark.rb
31
+ irc_parser.gemspec
32
+ lib/irc_parser.rb
33
+ lib/irc_parser/factory.erb
34
+ lib/irc_parser/helper.rb
35
+ lib/irc_parser/messages.rb
36
+ lib/irc_parser/messages/commands.rb
37
+ lib/irc_parser/messages/errors.rb
38
+ lib/irc_parser/messages/replies.rb
39
+ lib/irc_parser/parser.rb
40
+ lib/irc_parser/parser.rl
41
+ spec/fixtures/from_weechat.rb
42
+ spec/fixtures/inbound.log
43
+ spec/irc_parser/helper_spec.rb
44
+ spec/irc_parser/irc_parser_spec.rb
45
+ spec/irc_parser/messages_spec.rb
46
+ spec/irc_parser/parser_spec.rb
47
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_1_password_message_spec.rb
48
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_2_nick_message_spec.rb
49
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_3_user_message_spec.rb
50
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_4_server_message_spec.rb
51
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_5_oper_spec.rb
52
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_6_quit_spec.rb
53
+ spec/irc_parser/rfc1459/4_1_connection_registration/4_1_7_server_quit_message_spec.rb
54
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_1_join_message_spec.rb
55
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_2_part_message_spec.rb
56
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_3_1_channel_modes_spec.rb
57
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_3_2_user_modes_spec.rb
58
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_4_topic_message_spec.rb
59
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_5_names_message_spec.rb
60
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_6_list_message_spec.rb
61
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_7_invite_message_spec.rb
62
+ spec/irc_parser/rfc1459/4_2_channel_operations/4_2_8_kick_command_spec.rb
63
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_1_version_message_spec.rb
64
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_2_stats_message_spec.rb
65
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_3_links_message_spec.rb
66
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_4_time_message_spec.rb
67
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_5_connect_message_spec.rb
68
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_6_trace_message_spec.rb
69
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_7_admin_command_spec.rb
70
+ spec/irc_parser/rfc1459/4_3_server_queries_and_commands/4_3_8_info_command_spec.rb
71
+ spec/irc_parser/rfc1459/4_4_sending_messages/4_4_1_private_messages_spec.rb
72
+ spec/irc_parser/rfc1459/4_4_sending_messages/4_4_2_notice_spec.rb
73
+ spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_1_who_query_spec.rb
74
+ spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_2_whois_query_spec.rb
75
+ spec/irc_parser/rfc1459/4_5_user_based_queries/4_5_3_whowas_spec.rb
76
+ spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_1_kill_message_spec.rb
77
+ spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_2_ping_message_spec.rb
78
+ spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_3_pong_message_spec.rb
79
+ spec/irc_parser/rfc1459/4_6_miscellaneous_messages/4_6_4_error_spec.rb
80
+ spec/irc_parser/rfc1459/5_0_optionals/5_1_0_away_spec.rb
81
+ spec/irc_parser/rfc1459/5_0_optionals/5_2_0_rehash_message_spec.rb
82
+ spec/irc_parser/rfc1459/5_0_optionals/5_3_0_restart_message_spec.rb
83
+ spec/irc_parser/rfc1459/5_0_optionals/5_4_0_summon_message_spec.rb
84
+ spec/irc_parser/rfc1459/5_0_optionals/5_5_0_users_spec.rb
85
+ spec/irc_parser/rfc1459/5_0_optionals/5_6_0_operwall_message_spec.rb
86
+ spec/irc_parser/rfc1459/5_0_optionals/5_7_0_userhost_message_spec.rb
87
+ spec/irc_parser/rfc1459/5_0_optionals/5_8_0_ison_message_spec.rb
88
+ spec/irc_parser/rfc1459/6_0_replies/6_1_error_parsing_spec.rb
89
+ spec/irc_parser/rfc1459/6_0_replies/6_2_command_responses_generation_spec.rb
90
+ spec/irc_parser/rfc2812/5_1_command_responses/5_1_command_responses_spec.rb
91
+ spec/spec_helper.rb
92
+ spec/support/messages_helper.rb
93
+ spec/support/simplecov.rb
94
+ ]
95
+ # = MANIFEST =
96
+
97
+ s.test_files = s.files.select { |path| path =~ /^spec\/.+/ }
98
+ end
data/lib/irc_parser.rb ADDED
@@ -0,0 +1,25 @@
1
+ module IRCParser
2
+ VERSION = "0.1.0"
3
+
4
+ autoload :Helper, 'irc_parser/helper'
5
+ autoload :Params, 'irc_parser/params'
6
+ autoload :Messages, 'irc_parser/messages'
7
+
8
+ require 'irc_parser/parser'
9
+
10
+ def message(identifier, prefix = nil, params = nil)
11
+ klass = Messages::ALL[identifier]
12
+ raise IRCParser::Parser::Error, "Message not recognized: #{message.inspect}" unless klass
13
+ obj = klass.new(prefix, params)
14
+ yield obj if block_given?
15
+ obj
16
+ end
17
+
18
+ def message_class(identifier)
19
+ klass = Messages::ALL[identifier]
20
+ raise ArgumentError.new("no message with identifier #{identifier.inspect}") unless klass
21
+ klass
22
+ end
23
+
24
+ extend self
25
+ end