Class: Blur::Network::Channel
- Inherits:
-
Object
- Object
- Blur::Network::Channel
- Defined in:
- library/blur/network/channel.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 Channel
class is used for encapsulating a channel and its properties.
Users inside the channel is stored in the #channels attribute.
Modes can be set for a channel, but Blur is not ISupport-compliant yet.
Instance Attribute Summary collapse
-
#encryption ⇒ Encryption::Fish
The channel encryption, if any.
-
#modes ⇒ String
All the modes set on the channel.
-
#name ⇒ String
The channels name.
-
#network ⇒ Network
A reference to the network.
-
#topic ⇒ String
The channels topic.
-
#users ⇒ Array
A list of users in the channel.
Instance Method Summary collapse
-
#encrypted? ⇒ Boolean
Check whether or not this is an encrypted channel.
-
#initialize(name, network = nil, users = []) ⇒ Channel
constructor
Instantiate a user with a nickname, a network and a user list.
-
#inspect ⇒ Object
Convert it to a debug-friendly format.
-
#merge_modes(modes) ⇒ Object
Merge the channels mode corresponding to the leading character (+ or -).
-
#say(message) ⇒ Object
Send a message to the channel.
-
#to_s ⇒ Object
Get the channels name.
-
#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.
-
#user_by_nick(nick) ⇒ Object
Find a user with
nick
as its nickname.
Constructor Details
#initialize(name, network = nil, users = []) ⇒ Channel
Instantiate a user with a nickname, a network and a user list.
33 34 35 36 37 38 39 40 |
# File 'library/blur/network/channel.rb', line 33 def initialize name, network = nil, users = [] @name = name @users = users @modes = "" @network = network users.each { |user| user.channel = self } end |
Instance Attribute Details
#encryption ⇒ Encryption::Fish
27 28 29 |
# File 'library/blur/network/channel.rb', line 27 def encryption @encryption end |
#modes ⇒ String
23 24 25 |
# File 'library/blur/network/channel.rb', line 23 def modes @modes end |
#name ⇒ String
17 18 19 |
# File 'library/blur/network/channel.rb', line 17 def name @name end |
#network ⇒ Network
25 26 27 |
# File 'library/blur/network/channel.rb', line 25 def network @network end |
#topic ⇒ String
21 22 23 |
# File 'library/blur/network/channel.rb', line 21 def topic @topic end |
#users ⇒ Array
19 20 21 |
# File 'library/blur/network/channel.rb', line 19 def users @users end |
Instance Method Details
#encrypted? ⇒ Boolean
Check whether or not this is an encrypted channel.
30 |
# File 'library/blur/network/channel.rb', line 30 def encrypted?; not @encryption.nil? end |
#inspect ⇒ Object
Convert it to a debug-friendly format.
75 76 77 |
# File 'library/blur/network/channel.rb', line 75 def inspect %{#<#{self.class.name} @name=#{@name.inspect} @users=#{@users.inspect}} end |
#merge_modes(modes) ⇒ Object
Merge the channels mode corresponding to the leading character (+ or -).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'library/blur/network/channel.rb', line 45 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 |
#say(message) ⇒ Object
Send a message to the channel.
63 64 65 |
# File 'library/blur/network/channel.rb', line 63 def say @network.say self, end |
#to_s ⇒ Object
Get the channels name.
86 87 88 |
# File 'library/blur/network/channel.rb', line 86 def to_s @name 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.
81 82 83 |
# File 'library/blur/network/channel.rb', line 81 def to_yaml = {} @name.to_yaml end |
#user_by_nick(nick) ⇒ Object
Find a user with nick
as its nickname.
70 71 72 |
# File 'library/blur/network/channel.rb', line 70 def user_by_nick nick @users.find { |user| user.nick == nick } end |