Class: Cinch::Mask

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mask) ⇒ Mask

Returns a new instance of Mask.



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

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:



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

def host
  @host
end

#maskString (readonly)

Returns:



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

def mask
  @mask
end

#nickString (readonly)

Returns:



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

def nick
  @nick
end

#userString (readonly)

Returns:



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

def user
  @user
end

Class Method Details

.from(target) ⇒ Mask

Parameters:

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cinch/mask.rb', line 47

def self.from(target)
  case target
  when User, Ban
    target.mask
  when String
    Mask.new(target)
  when Mask
    target
  else
    raise ArgumentError
  end
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cinch/mask.rb', line 18

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



27
28
29
# File 'lib/cinch/mask.rb', line 27

def hash
  @mask.hash
end

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

Parameters:

Returns:

  • (Boolean)


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

def match(target)
  return self.class.from(target).mask =~ @regexp

  # TODO support CIDR (freenode)
end

#to_sString

Returns:



41
42
43
# File 'lib/cinch/mask.rb', line 41

def to_s
  @mask.dup
end