class Cinch::Mask

This class represents masks, which are primarily used for bans.

Attributes

host[R]

@return [String]

mask[R]

@return [String]

nick[R]

@return [String]

user[R]

@return [String]

Public Class Methods

from(target) click to toggle source

@param [String, mask] target @return [target] if already a Mask @return [Mask] @version 2.0.0

# File lib/cinch/mask.rb, line 59
def self.from(target)
  return target if target.is_a?(self)

  mask = if target.respond_to?(:mask)
           target.mask
         else
           Mask.new(target.to_s)
         end

  mask
end
new(mask) click to toggle source

@version 1.1.2 @param [String] mask

# File lib/cinch/mask.rb, line 17
def initialize(mask)
  @mask = mask
  @nick, @user, @host = mask.match(/(.+)!(.+)@(.+)/)[1..-1]
  @regexp = Regexp.new("^" + Regexp.escape(mask).gsub("\\*", ".*").gsub("\\?", ".?") + "$")
end

Public Instance Methods

==(other) click to toggle source

@return [Boolean] @since 1.1.0

# File lib/cinch/mask.rb, line 25
def ==(other)
  other.respond_to?(:mask) && other.mask == @mask
end
=~(target)
Alias for: match
eql?(other) click to toggle source

@return [Boolean] @since 1.1.0

# File lib/cinch/mask.rb, line 31
def eql?(other)
  other.is_a?(self.class) && self == other
end
hash() click to toggle source

@return [Fixnum]

# File lib/cinch/mask.rb, line 36
def hash
  @mask.hash
end
match(target) click to toggle source

@param [Mask, String, mask] target @return [Boolean] @version 1.1.2

# File lib/cinch/mask.rb, line 43
def match(target)
  self.class.from(target).mask =~ @regexp

  # TODO: support CIDR (freenode)
end
Also aliased as: =~
to_s() click to toggle source

@return [String]

# File lib/cinch/mask.rb, line 51
def to_s
  @mask.dup
end