Sha256: 7819cab6bdbc0d957c0428189eedfb6c2577cc36e416a4d428ecd65d0ed4d135
Contents?: true
Size: 1.51 KB
Versions: 4
Compression:
Stored size: 1.51 KB
Contents
# # 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. # module IRCUtil # # 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. # def assert_hostmask(host, hostmask) return !!host.match(quote_regexp_for_mask(hostmask)) end module_function :assert_hostmask # # 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. # 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 module_function :quote_regexp_for_mask end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
cerberus-0.7.6 | lib/vendor/irc/lib/IRCUtil.rb |
cerberus-0.7.2 | lib/vendor/irc/lib/IRCUtil.rb |
cerberus-0.7.5 | lib/vendor/irc/lib/IRCUtil.rb |
cerberus-0.7 | lib/vendor/irc/lib/IRCUtil.rb |