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)
-
- (String) host
readonly
-
- (String) mask
readonly
-
- (String) nick
readonly
-
- (String) user
readonly
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Boolean) ==(other)
-
- (Boolean) eql?(other)
-
- (Fixnum) hash
-
- (Mask) initialize(mask)
constructor
A new instance of Mask.
-
- (Boolean) match(target)
(also: #=~)
-
- (String) to_s
Constructor Details
- (Mask) initialize(mask)
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
+ (target, Mask) from(target)
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cinch/mask.rb', line 57 def self.from(target) return target if target.is_a?(self) if target.respond_to?(:mask) mask = target.mask else mask = Mask.new(target.to_s) end return mask end |
Instance Method Details
- (Boolean) ==(other)
23 24 25 |
# File 'lib/cinch/mask.rb', line 23 def ==(other) other.respond_to?(:mask) && other.mask == @mask end |
- (Boolean) eql?(other)
29 30 31 |
# File 'lib/cinch/mask.rb', line 29 def eql?(other) other.is_a?(self.class) && self == other end |
- (Fixnum) hash
34 35 36 |
# File 'lib/cinch/mask.rb', line 34 def hash @mask.hash end |
- (Boolean) match(target) 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 |