Class: Cinch::Mask
- Inherits:
-
Object
- Object
- Cinch::Mask
- Defined in:
- lib/cinch/mask.rb
Instance Attribute Summary collapse
- #host ⇒ String readonly
- #mask ⇒ String readonly
- #nick ⇒ String readonly
- #user ⇒ String readonly
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(mask) ⇒ Mask
constructor
A new instance of Mask.
- #match(target) ⇒ Boolean (also: #=~)
- #to_s ⇒ String
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
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean
18 19 20 |
# File 'lib/cinch/mask.rb', line 18 def ==(other) other.respond_to?(:mask) && other.mask == @mask end |
#eql?(other) ⇒ Boolean
23 24 25 |
# File 'lib/cinch/mask.rb', line 23 def eql?(other) other.is_a?(self.class) && self == other end |
#hash ⇒ Object
27 28 29 |
# File 'lib/cinch/mask.rb', line 27 def hash @mask.hash end |
#match(target) ⇒ Boolean Also known as: =~
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 |