Class: Blur::Network::User
- Inherits:
-
Object
- Object
- Blur::Network::User
- Defined in:
- library/blur/network/user.rb
Overview
make so that channels and users belongs to the network, and not like now where the user belongs to the channel, resulting in multiple user instances.
The User
class is used for encapsulating a user and its properties.
The user owns a reference to its parent channel.
Modes can be set for a user, but Blur is not ISupport-compliant yet.
Instance Attribute Summary collapse
-
#channel ⇒ Channel
A reference to the users channel.
-
#host ⇒ String
The users hostname.
-
#modes ⇒ String
All the modes set on the user.
-
#name ⇒ String
The users username.
-
#network ⇒ Network
A reference to the network.
-
#nick ⇒ String
The users nickname.
Instance Method Summary collapse
-
#admin? ⇒ Boolean
Check to see if the user is an admin (+a).
-
#half_operator? ⇒ Boolean
Check to see if the user is an half-operator (+h).
-
#initialize(nick) ⇒ User
constructor
Instantiate a user with a nickname.
-
#inspect ⇒ Object
Convert it to a debug-friendly format.
-
#merge_modes(modes) ⇒ Object
Merge the users mode corresponding to the leading character (+ or -).
-
#operator? ⇒ Boolean
Check to see if the user is an operator (+o).
-
#owner? ⇒ Boolean
Check to see if the user is the owner (+q).
-
#say(message) ⇒ Object
Send a private message to the user.
-
#to_s ⇒ Object
Get the users nickname.
-
#to_yaml(options = {}) ⇒ Object
Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.
-
#voice? ⇒ Boolean
Check to see if the user has voice (+v).
Constructor Details
#initialize(nick) ⇒ User
Instantiate a user with a nickname.
41 42 43 44 45 46 47 48 49 |
# File 'library/blur/network/user.rb', line 41 def initialize nick @nick = nick @modes = "" if modes = prefix_to_mode(nick[0]) @nick = nick[1..-1] @modes = modes end end |
Instance Attribute Details
#channel ⇒ Channel
Returns a reference to the users channel.
25 26 27 |
# File 'library/blur/network/user.rb', line 25 def channel @channel end |
#host ⇒ String
Returns the users hostname.
21 22 23 |
# File 'library/blur/network/user.rb', line 21 def host @host end |
#modes ⇒ String
Returns all the modes set on the user.
23 24 25 |
# File 'library/blur/network/user.rb', line 23 def modes @modes end |
#name ⇒ String
Returns the users username.
19 20 21 |
# File 'library/blur/network/user.rb', line 19 def name @name end |
#network ⇒ Network
Returns a reference to the network.
27 28 29 |
# File 'library/blur/network/user.rb', line 27 def network @network end |
#nick ⇒ String
Returns the users nickname.
17 18 19 |
# File 'library/blur/network/user.rb', line 17 def nick @nick end |
Instance Method Details
#admin? ⇒ Boolean
Check to see if the user is an admin (+a)
30 |
# File 'library/blur/network/user.rb', line 30 def admin?; @modes.include? "a" end |
#half_operator? ⇒ Boolean
Check to see if the user is an half-operator (+h)
38 |
# File 'library/blur/network/user.rb', line 38 def half_operator?; @modes.include? "h" end |
#inspect ⇒ Object
Convert it to a debug-friendly format.
77 78 79 |
# File 'library/blur/network/user.rb', line 77 def inspect %{#<#{self.class.name} @nick=#{@nick.inspect} @channel=#{@channel.name.inspect}>} end |
#merge_modes(modes) ⇒ Object
Merge the users mode corresponding to the leading character (+ or -).
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'library/blur/network/user.rb', line 54 def merge_modes modes addition = true modes.each_char do |char| case char when ?+ addition = true when ?- addition = false else addition ? @modes.concat(char) : @modes.delete!(char) end end end |
#operator? ⇒ Boolean
Check to see if the user is an operator (+o)
36 |
# File 'library/blur/network/user.rb', line 36 def operator?; @modes.include? "o" end |
#owner? ⇒ Boolean
Check to see if the user is the owner (+q)
34 |
# File 'library/blur/network/user.rb', line 34 def owner?; @modes.include? "q" end |
#say(message) ⇒ Object
Send a private message to the user.
72 73 74 |
# File 'library/blur/network/user.rb', line 72 def say @network.say self, end |
#to_s ⇒ Object
Get the users nickname.
88 89 90 |
# File 'library/blur/network/user.rb', line 88 def to_s @nick end |
#to_yaml(options = {}) ⇒ Object
Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.
83 84 85 |
# File 'library/blur/network/user.rb', line 83 def to_yaml = {} @nick.to_yaml end |
#voice? ⇒ Boolean
Check to see if the user has voice (+v)
32 |
# File 'library/blur/network/user.rb', line 32 def voice?; @modes.include? "v" end |