Class: Cinch::Mask
- Inherits:
-
Object
- Object
- Cinch::Mask
- Defined in:
- lib/cinch/mask.rb
Overview
This class represents masks, which are primarily used for bans.
Instance Attribute Summary collapse
- #host ⇒ String readonly
- #mask ⇒ String readonly
- #nick ⇒ String readonly
- #user ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Fixnum
-
#initialize(mask) ⇒ Mask
constructor
A new instance of Mask.
- #match(target) ⇒ Boolean (also: #=~)
- #to_s ⇒ String
Constructor Details
#initialize(mask) ⇒ Mask
Returns a new instance of Mask.
17 18 19 20 21 |
# File 'lib/cinch/mask.rb', line 17 def initialize(mask) @mask = mask @nick, @user, @host = mask.match(/(.+)!(.+)@(.+)/)[1..] @regexp = Regexp.new("^" + Regexp.escape(mask).gsub("\\*", ".*").gsub("\\?", ".?") + "$") end |
Instance Attribute Details
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean
25 26 27 |
# File 'lib/cinch/mask.rb', line 25 def ==(other) other.respond_to?(:mask) && other.mask == @mask end |
#eql?(other) ⇒ Boolean
31 32 33 |
# File 'lib/cinch/mask.rb', line 31 def eql?(other) other.is_a?(self.class) && self == other end |
#hash ⇒ Fixnum
36 37 38 |
# File 'lib/cinch/mask.rb', line 36 def hash @mask.hash end |
#match(target) ⇒ Boolean Also known as: =~
43 44 45 46 47 |
# File 'lib/cinch/mask.rb', line 43 def match(target) self.class.from(target).mask =~ @regexp # TODO support CIDR (freenode) end |