Class: Cinch::Mask

Inherits:
Object
  • Object
show all
Defined in:
lib/cinch/mask.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mask) ⇒ Mask

Returns a new instance of Mask.

Parameters:

Version:

  • 1.1.2



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

#hostString (readonly)

Returns:



9
10
11
# File 'lib/cinch/mask.rb', line 9

def host
  @host
end

#maskString (readonly)

Returns:



11
12
13
# File 'lib/cinch/mask.rb', line 11

def mask
  @mask
end

#nickString (readonly)

Returns:



5
6
7
# File 'lib/cinch/mask.rb', line 5

def nick
  @nick
end

#userString (readonly)

Returns:



7
8
9
# File 'lib/cinch/mask.rb', line 7

def user
  @user
end

Class Method Details

.from(target) ⇒ target, Mask

Parameters:

Returns:

  • (target)

    if already a Mask

  • (Mask)

Version:

  • 2.0.0



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

#==(other) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.1.0



23
24
25
# File 'lib/cinch/mask.rb', line 23

def ==(other)
  other.respond_to?(:mask) && other.mask == @mask
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.1.0



29
30
31
# File 'lib/cinch/mask.rb', line 29

def eql?(other)
  other.is_a?(self.class) && self == other
end

#hashFixnum

Returns:

  • (Fixnum)


34
35
36
# File 'lib/cinch/mask.rb', line 34

def hash
  @mask.hash
end

#match(target) ⇒ Boolean Also known as: =~

Parameters:

Returns:

  • (Boolean)

Version:

  • 1.1.2



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

#to_sString

Returns:



49
50
51
# File 'lib/cinch/mask.rb', line 49

def to_s
  @mask.dup
end