Class: IRC::Mask
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #!=(mask) ⇒ Object
- #==(mask) ⇒ Object
-
#initialize(nick = nil, user = nil, host = nil) ⇒ Mask
constructor
A new instance of Mask.
- #match(mask) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nick = nil, user = nil, host = nil) ⇒ Mask
Returns a new instance of Mask.
25 26 27 28 29 |
# File 'lib/failirc/mask.rb', line 25 def initialize (nick=nil, user=nil, host=nil) @nick = nick @user = user @host = host end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
23 24 25 |
# File 'lib/failirc/mask.rb', line 23 def host @host end |
#nick ⇒ Object
Returns the value of attribute nick.
23 24 25 |
# File 'lib/failirc/mask.rb', line 23 def nick @nick end |
#user ⇒ Object
Returns the value of attribute user.
23 24 25 |
# File 'lib/failirc/mask.rb', line 23 def user @user end |
Class Method Details
.parse(string) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/failirc/mask.rb', line 73 def self.parse (string) if !string return Mask.new end if !string.match(/[!@]/) return Mask.new(string) end if string.include?('!') matches = string.match(/^(.*?)!(.*)$/) if !matches[1] || matches[1].empty? || matches[1] == '*' nick = nil else nick = matches[1] end string = matches[2] end if string.include?('@') matches = string.match(/^(.*?)@(.*)$/) if !matches[1] || matches[1].empty? || matches[1] == '*' user = nil else user = matches[1] end if !matches[2] || matches[2].empty? || matches[2] == '*' host = nil else host = matches[2] end else user = string host = nil end return Mask.new(nick, user, host) end |
.toRegexp(string) ⇒ Object
69 70 71 |
# File 'lib/failirc/mask.rb', line 69 def self.toRegexp (string) return Regexp.new(Regexp.escape(string).gsub(/\\\*/, '.*?').gsub(/\\\?/, '.')) end |
Instance Method Details
#!=(mask) ⇒ Object
61 62 63 |
# File 'lib/failirc/mask.rb', line 61 def != (mask) !(self == mask) end |
#==(mask) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/failirc/mask.rb', line 53 def == (mask) if !mask.is_a?(Mask) return false end return (@nick == mask.nick && @user == mask.user && @host == mask.host) end |
#match(mask) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/failirc/mask.rb', line 31 def match (mask) if !mask || mask.is_a?(String) mask = Mask.parse(mask || '*!*@*') end matches = {} if !nick || !mask.nick || Mask.toRegexp(nick).match(mask.nick) matches[:nick] = true end if !user || !mask.user || Mask.toRegexp(user).match(mask.user) matches[:user] = true end if !host || !mask.host || Mask.toRegexp(host).match(mask.host) matches[:host] = true end return matches[:nick] && matches[:user] && matches[:host] end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/failirc/mask.rb', line 65 def to_s return "#{nick || '*'}!#{user || '*'}@#{host || '*'}" end |