Class: Butler::IRC::Hostmask
- Inherits:
-
Object
- Object
- Butler::IRC::Hostmask
- Defined in:
- lib/butler/irc/hostmask.rb
Overview
Provides methods to see if hostmasks match
Constant Summary collapse
- Filter =
[ [/([\\\[\]{}^`.-])/, '\\\\\1'], [/\?/, "."], [/\*/, ".*?"], ]
Instance Method Summary collapse
-
#initialize(mask) ⇒ Hostmask
constructor
FIXME, not yet correct, escaped * and ?.
- #match(mask) ⇒ Object
- #matches?(mask) ⇒ Boolean
- #to_str ⇒ Object (also: #to_s)
Constructor Details
#initialize(mask) ⇒ Hostmask
FIXME, not yet correct, escaped * and ?
24 25 26 27 28 29 |
# File 'lib/butler/irc/hostmask.rb', line 24 def initialize(mask) @mask = mask.dup.freeze filtered = Filter.inject('[]{}^`.-') { |s,(a,b)| s.gsub(a,b) } #string.gsub(/[\\\x00-\x1f]/) { |match| ("\\%02x" % match[0]) } #implement later @regex = Regexp.new("\A#{filtered}\z") end |
Instance Method Details
#match(mask) ⇒ Object
36 37 38 39 |
# File 'lib/butler/irc/hostmask.rb', line 36 def match(mask) mask = mask.hostmask if mask.kind_of?(User) @regex.match(mask.to_str) end |
#matches?(mask) ⇒ Boolean
31 32 33 34 |
# File 'lib/butler/irc/hostmask.rb', line 31 def matches?(mask) mask = mask.hostmask if mask.kind_of?(User) return !@regex.match(mask.to_str).nil? end |
#to_str ⇒ Object Also known as: to_s
41 42 43 |
# File 'lib/butler/irc/hostmask.rb', line 41 def to_str @mask end |