Class: Blur::Channel
- Inherits:
-
Object
- Object
- Blur::Channel
- Defined in:
- library/blur/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
-
#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
List of references to users in the channel.
Instance Method Summary collapse
-
#initialize(name, network = nil) ⇒ 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.
Constructor Details
#initialize(name, network = nil) ⇒ Channel
Instantiate a user with a nickname, a network and a user list.
27 28 29 30 31 32 |
# File 'library/blur/channel.rb', line 27 def initialize name, network = nil @name = name @users = [] @modes = '' @network = network end |
Instance Attribute Details
#modes ⇒ String
Returns all the modes set on the channel.
22 23 24 |
# File 'library/blur/channel.rb', line 22 def modes @modes end |
#name ⇒ String
Returns the channels name.
16 17 18 |
# File 'library/blur/channel.rb', line 16 def name @name end |
#network ⇒ Network
Returns a reference to the network.
24 25 26 |
# File 'library/blur/channel.rb', line 24 def network @network end |
#topic ⇒ String
Returns the channels topic.
18 19 20 |
# File 'library/blur/channel.rb', line 18 def topic @topic end |
#users ⇒ Array
Returns list of references to users in the channel.
20 21 22 |
# File 'library/blur/channel.rb', line 20 def users @users end |
Instance Method Details
#inspect ⇒ Object
Convert it to a debug-friendly format.
60 61 62 63 64 65 |
# File 'library/blur/channel.rb', line 60 def inspect "#<#{self.class.name}:0x#{object_id.to_s 16} " \ "@name=#{@name.inspect} " \ "@topic=#{@topic.inspect} " \ "@users=#{@users.inspect}>" end |
#merge_modes(modes) ⇒ Object
Merge the channels mode corresponding to the leading character (+ or -).
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'library/blur/channel.rb', line 37 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.
55 56 57 |
# File 'library/blur/channel.rb', line 55 def say @network.say self, end |
#to_s ⇒ Object
Get the channels name.
74 75 76 |
# File 'library/blur/channel.rb', line 74 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.
69 70 71 |
# File 'library/blur/channel.rb', line 69 def to_yaml = {} @name.to_yaml end |