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.
Constant Summary collapse
- COMMON_SYMBOL_MODES =
Returns a map of symbols to channel user modes.
{ '@' => 'o', '+' => 'v', '%' => 'h', '&' => 'a', '~' => 'q' }.freeze
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.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'library/blur/user.rb', line 62 def initialize nick, network = nil @nick = nick @modes = String.new @channels = [] @network = network return unless (modes = prefix_to_mode(nick[0])) @nick = nick[1..] @modes = modes 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)
37 38 39 |
# File 'library/blur/user.rb', line 37 def admin? @modes.include? 'a' end |
#half_operator? ⇒ Boolean
Check to see if the user is an half-operator (+h)
57 58 59 |
# File 'library/blur/user.rb', line 57 def half_operator? @modes.include? 'h' end |
#inspect ⇒ Object
Convert it to a debug-friendly format.
100 101 102 |
# File 'library/blur/user.rb', line 100 def inspect %(#<#{self.class.name}:0x#{object_id.to_s 16} @nick=#{@nick.inspect}>) end |
#merge_modes(modes) ⇒ Object
Merge the users mode corresponding to the leading character (+ or -).
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'library/blur/user.rb', line 77 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)
52 53 54 |
# File 'library/blur/user.rb', line 52 def operator? @modes.include? 'o' end |
#owner? ⇒ Boolean
Check to see if the user is the owner (+q)
47 48 49 |
# File 'library/blur/user.rb', line 47 def owner? @modes.include? 'q' end |
#say(message) ⇒ Object
Send a private message to the user.
95 96 97 |
# File 'library/blur/user.rb', line 95 def say @network.say self, end |
#to_s ⇒ Object
Get the users nickname.
111 112 113 |
# File 'library/blur/user.rb', line 111 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.
106 107 108 |
# File 'library/blur/user.rb', line 106 def to_yaml = {} @nick.to_yaml end |
#voice? ⇒ Boolean
Check to see if the user has voice (+v)
42 43 44 |
# File 'library/blur/user.rb', line 42 def voice? @modes.include? 'v' end |