Module: IRCUtil
- Defined in:
- lib/IRCUtil.rb
Overview
IRCUtil is a module that contains utility functions for use with the rest of Ruby-IRC. There is nothing required of the user to know or even use these functions, but they are useful for certain tasks regarding IRC connections.
Class Method Summary collapse
-
.assert_hostmask(host, hostmask) ⇒ Object
Matches hostmasks against hosts.
-
.quote_regexp_for_mask(hostmask) ⇒ Object
A utility function used by assert_hostmask() to turn hostmasks into regular expressions.
Class Method Details
.assert_hostmask(host, hostmask) ⇒ Object
Matches hostmasks against hosts. Returns t/f on success/fail.
A hostmask consists of a simple wildcard that describes a host or class of hosts.
f.e., where the host is ‘bar.example.com’, a host mask of ‘*.example.com’ would assert.
19 20 21 |
# File 'lib/IRCUtil.rb', line 19 def assert_hostmask(host, hostmask) return !!host.match(quote_regexp_for_mask(hostmask)) end |
.quote_regexp_for_mask(hostmask) ⇒ Object
A utility function used by assert_hostmask() to turn hostmasks into regular expressions.
Rarely, if ever, should be used by outside code. It’s public exposure is merely for those who are interested in it’s functionality.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/IRCUtil.rb', line 34 def quote_regexp_for_mask(hostmask) # Big thanks to Jesse Williamson for his consultation while writing this. # # escape all other regexp specials except for . and *. # properly escape . and place an unescaped . before *. # confine the regexp to scan the whole line. # return the edited hostmask as a string. hostmask.gsub(/([\[\]\(\)\?\^\$])\\/, '\\1'). gsub(/\./, '\.'). gsub(/\*/, '.*'). sub(/^/, '^'). sub(/$/, '$') end |