Class: Blur::Channel

Inherits:
Object
  • Object
show all
Defined in:
library/blur/channel.rb

Overview

TODO:

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

Instance Method Summary collapse

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   = String.new
  @network = network
end

Instance Attribute Details

#modesString

Returns all the modes set on the channel.

Returns:

  • (String)

    all the modes set on the channel.



22
23
24
# File 'library/blur/channel.rb', line 22

def modes
  @modes
end

#nameString

Returns the channels name.

Returns:

  • (String)

    the channels name.



16
17
18
# File 'library/blur/channel.rb', line 16

def name
  @name
end

#networkNetwork

Returns a reference to the network.

Returns:

  • (Network)

    a reference to the network.



24
25
26
# File 'library/blur/channel.rb', line 24

def network
  @network
end

#topicString

Returns the channels topic.

Returns:

  • (String)

    the channels topic.



18
19
20
# File 'library/blur/channel.rb', line 18

def topic
  @topic
end

#usersArray

Returns list of references to users in the channel.

Returns:

  • (Array)

    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

#inspectObject

Convert it to a debug-friendly format.



60
61
62
# File 'library/blur/channel.rb', line 60

def inspect
  %{#<#{self.class.name}:0x#{self.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 -).

Parameters:

  • modes (String)

    the modes to merge with.



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.

Parameters:

  • message (String)

    the message to send.



55
56
57
# File 'library/blur/channel.rb', line 55

def say message
  @network.say self, message
end

#to_sObject

Get the channels name.



71
72
73
# File 'library/blur/channel.rb', line 71

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.



66
67
68
# File 'library/blur/channel.rb', line 66

def to_yaml options = {}
  @name.to_yaml options
end