Class: Cereal::User
Overview
Synopsis
Cereal::User Represents a user in an IRC channel. This class is used by Cereal::Connection and Cereal::Bot to keep track of who is in each channel the bot currenty occupies. You may receive an array of Users if you request a list of users in a channel from the bot.
@lower_nick
is set on initialization (or when @nick
is changed) and is simply a downcase
d version of @nick
, stored as an instance variable for performance reasons.
Author
Ross “Raws” Paffett
Copyright
Copyright © 2009 Ross Paffett. Licensed under the MIT license: www.opensource.org/licenses/mit-license.php
Instance Attribute Summary collapse
-
#lower_nick ⇒ Object
readonly
Returns the value of attribute lower_nick.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Returns the result of calling <=> on lowercased nicks.
-
#eql?(other) ⇒ Boolean
Returns true as in ==.
-
#hash ⇒ Object
Returns the hash of this User object.
-
#initialize(prefix, nick) ⇒ User
constructor
Constructs a User object with a known prefix and nick.
-
#op(is_op) ⇒ Object
Sets whether or not this user is an operator.
-
#op? ⇒ Boolean
Returns whether or not this user is an operator.
-
#to_s ⇒ Object
Returns the nick of the user with their prefix, if any, attached.
-
#voice(has_voice) ⇒ Object
Sets whether or not this user has voice.
-
#voice? ⇒ Boolean
Returns whether or not this user has voice.
Constructor Details
#initialize(prefix, nick) ⇒ User
Constructs a User object with a known prefix and nick.
27 28 29 30 31 |
# File 'lib/user.rb', line 27 def initialize(prefix, nick) @prefix = prefix.strip @nick = nick.strip @lower_nick = @nick.downcase end |
Instance Attribute Details
#lower_nick ⇒ Object (readonly)
Returns the value of attribute lower_nick.
24 25 26 |
# File 'lib/user.rb', line 24 def lower_nick @lower_nick end |
#nick ⇒ Object
Returns the value of attribute nick.
24 25 26 |
# File 'lib/user.rb', line 24 def nick @nick end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
24 25 26 |
# File 'lib/user.rb', line 24 def prefix @prefix end |
Instance Method Details
#<=>(other) ⇒ Object
Returns the result of calling <=> on lowercased nicks. This is useful for sorting lists of Users.
88 89 90 91 92 93 94 |
# File 'lib/user.rb', line 88 def <=>(other) if other.is_a? Cereal::User other.lower_nick <=> @lower_nick else other.to_s.downcase! <=> @lower_nick end end |
#eql?(other) ⇒ Boolean
Returns true as in ==.
77 78 79 |
# File 'lib/user.rb', line 77 def eql?(other) self == other end |
#hash ⇒ Object
Returns the hash of this User object.
82 83 84 |
# File 'lib/user.rb', line 82 def hash @lower_nick.hash end |
#op(is_op) ⇒ Object
Sets whether or not this user is an operator.
39 40 41 42 43 44 45 |
# File 'lib/user.rb', line 39 def op(is_op) if is_op @prefix = voice? ? '@+' : '@' else @prefix = voice? ? '+' : '' end end |
#op? ⇒ Boolean
Returns whether or not this user is an operator.
34 35 36 |
# File 'lib/user.rb', line 34 def op? !@prefix.index('@').nil? end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/user.rb', line 66 def to_s @prefix + @nick end |
#voice(has_voice) ⇒ Object
Sets whether or not this user has voice.
53 54 55 56 57 58 59 |
# File 'lib/user.rb', line 53 def voice(has_voice) if has_voice @prefix = op? ? '@+' : '+' else @prefix = op? ? '@' : '' end end |
#voice? ⇒ Boolean
Returns whether or not this user has voice.
48 49 50 |
# File 'lib/user.rb', line 48 def voice? !@prefix.index('+').nil? end |