Class: Blur::User
- Inherits:
-
Object
- Object
- Blur::User
- Defined in:
- library/blur/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
-
#channels ⇒ Object
Returns the value of attribute channels.
-
#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, network = nil) ⇒ 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, network = nil) ⇒ User
Instantiate a user with a nickname.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'library/blur/user.rb', line 39 def initialize nick, network = nil @nick = nick @modes = String.new @channels = [] @network = network if modes = prefix_to_mode(nick[0]) @nick = nick[1..-1] @modes = modes end end |
Instance Attribute Details
#channels ⇒ Object
Returns the value of attribute channels.
25 26 27 |
# File 'library/blur/user.rb', line 25 def channels @channels end |
#host ⇒ String
Returns the users hostname.
20 21 22 |
# File 'library/blur/user.rb', line 20 def host @host end |
#modes ⇒ String
Returns all the modes set on the user.
22 23 24 |
# File 'library/blur/user.rb', line 22 def modes @modes end |
#name ⇒ String
Returns the users username.
18 19 20 |
# File 'library/blur/user.rb', line 18 def name @name end |
#network ⇒ Network
Returns a reference to the network.
24 25 26 |
# File 'library/blur/user.rb', line 24 def network @network end |
#nick ⇒ String
Returns the users nickname.
16 17 18 |
# File 'library/blur/user.rb', line 16 def nick @nick end |
Instance Method Details
#admin? ⇒ Boolean
Check to see if the user is an admin (+a)
28 |
# File 'library/blur/user.rb', line 28 def admin?; @modes.include? "a" end |
#half_operator? ⇒ Boolean
Check to see if the user is an half-operator (+h)
36 |
# File 'library/blur/user.rb', line 36 def half_operator?; @modes.include? "h" end |
#inspect ⇒ Object
Convert it to a debug-friendly format.
77 78 79 |
# File 'library/blur/user.rb', line 77 def inspect %{#<#{self.class.name}:0x#{self.object_id.to_s 16} @nick=#{@nick.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/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)
34 |
# File 'library/blur/user.rb', line 34 def operator?; @modes.include? "o" end |
#owner? ⇒ Boolean
Check to see if the user is the owner (+q)
32 |
# File 'library/blur/user.rb', line 32 def owner?; @modes.include? "q" end |
#say(message) ⇒ Object
Send a private message to the user.
72 73 74 |
# File 'library/blur/user.rb', line 72 def say @network.say self, end |
#to_s ⇒ Object
Get the users nickname.
88 89 90 |
# File 'library/blur/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/user.rb', line 83 def to_yaml = {} @nick.to_yaml end |
#voice? ⇒ Boolean
Check to see if the user has voice (+v)
30 |
# File 'library/blur/user.rb', line 30 def voice?; @modes.include? "v" end |