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



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

#hostString (readonly)

Returns:



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

def host
  @host
end

#maskString (readonly)

Returns:



13
14
15
# File 'lib/cinch/mask.rb', line 13

def mask
  @mask
end

#nickString (readonly)

Returns:



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

def nick
  @nick
end

#userString (readonly)

Returns:



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

def user
  @user
end

Class Method Details

.from(target) ⇒ target, Mask

Parameters:

Returns:

  • (target)

    if already a Mask

  • (Mask)

Version:

  • 2.0.0



59
60
61
62
63
64
65
66
67
# File 'lib/cinch/mask.rb', line 59

def self.from(target)
  return target if target.is_a?(self)

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

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.1.0



25
26
27
# File 'lib/cinch/mask.rb', line 25

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.1.0



31
32
33
# File 'lib/cinch/mask.rb', line 31

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

#hashFixnum

Returns:

  • (Fixnum)


36
37
38
# File 'lib/cinch/mask.rb', line 36

def hash
  @mask.hash
end

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

Parameters:

Returns:

  • (Boolean)

Version:

  • 1.1.2



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

#to_sString

Returns:



51
52
53
# File 'lib/cinch/mask.rb', line 51

def to_s
  @mask.dup
end