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.
15 16 17 18 19 |
# File 'lib/cinch/mask.rb', line 15 def initialize(mask) @mask = mask @nick, @user, @host = mask.match(/(.+)!(.+)@(.+)/)[1..-1] @regexp = Regexp.new("^" + Regexp.escape(mask).gsub("\\*", ".*").gsub("\\?", ".?") + "$") end |
Instance Attribute Details
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean
23 24 25 |
# File 'lib/cinch/mask.rb', line 23 def ==(other) other.respond_to?(:mask) && other.mask == @mask end |
#eql?(other) ⇒ Boolean
29 30 31 |
# File 'lib/cinch/mask.rb', line 29 def eql?(other) other.is_a?(self.class) && self == other end |
#hash ⇒ Fixnum
34 35 36 |
# File 'lib/cinch/mask.rb', line 34 def hash @mask.hash end |
#match(target) ⇒ Boolean Also known as: =~
41 42 43 44 45 |
# File 'lib/cinch/mask.rb', line 41 def match(target) return self.class.from(target).mask =~ @regexp # TODO support CIDR (freenode) end |