class Blur::User

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 {www.irc.org/tech_docs/005.html ISupport}-compliant yet.

@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.

Attributes

channels[RW]
host[RW]

@return [String] the users hostname.

modes[RW]

@return [String] all the modes set on the user.

name[RW]

@return [String] the users username.

network[RW]

@return [Network] a reference to the network.

nick[RW]

@return [String] the users nickname.

Public Class Methods

new(nick, network = nil) click to toggle source

Instantiate a user with a nickname.

# 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

Public Instance Methods

admin?() click to toggle source

Check to see if the user is an admin (+a)

# File library/blur/user.rb, line 28
def admin?; @modes.include? "a" end
half_operator?() click to toggle source

Check to see if the user is an half-operator (+h)

# File library/blur/user.rb, line 36
def half_operator?; @modes.include? "h" end
inspect() click to toggle source

Convert it to a debug-friendly format.

# 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) click to toggle source

Merge the users mode corresponding to the leading character (+ or -).

@param [String] modes the modes to merge with.

# 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?() click to toggle source

Check to see if the user is an operator (+o)

# File library/blur/user.rb, line 34
def operator?; @modes.include? "o" end
owner?() click to toggle source

Check to see if the user is the owner (+q)

# File library/blur/user.rb, line 32
def owner?; @modes.include? "q" end
say(message) click to toggle source

Send a private message to the user.

@param [String] message the message to send.

# File library/blur/user.rb, line 72
def say message
  @network.say self, message
end
to_s() click to toggle source

Get the users nickname.

# File library/blur/user.rb, line 88
def to_s
  @nick
end
to_yaml(options = {}) click to toggle source

Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.

# File library/blur/user.rb, line 83
def to_yaml options = {}
  @nick.to_yaml options
end
voice?() click to toggle source

Check to see if the user has voice (+v)

# File library/blur/user.rb, line 30
def voice?; @modes.include? "v" end

Private Instance Methods

prefix_to_mode(prefix) click to toggle source

Translate a nickname-prefix to a mode character.

# File library/blur/user.rb, line 95
def prefix_to_mode prefix
  case prefix
  when '@' then 'o'
  when '+' then 'v'
  when '%' then 'h'
  when '&' then 'a'
  when '~' then 'q'
  end
end