Class: Weechat::IRC::Server

Inherits:
Object
  • Object
show all
Extended by:
Properties
Defined in:
lib/weechat/irc/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::ClassMethods

#all, #apply_rtransformation, #apply_transformation, #init_properties, #known_integer_properties, #known_properties, #known_string_properties, #mappings, #rtransformations, #settable_properties, #transformations, #type

Constructor Details

#initialize(*args) ⇒ Server



49
50
51
# File 'lib/weechat/irc/server.rb', line 49

def initialize(*args)
  # TODO allow the creation of new channels using commands
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



9
10
11
# File 'lib/weechat/irc/server.rb', line 9

def name
  @name
end

#ptrObject (readonly)

Returns the value of attribute ptr



48
49
50
# File 'lib/weechat/irc/server.rb', line 48

def ptr
  @ptr
end

Class Method Details

.allObject



64
65
66
67
68
69
70
# File 'lib/weechat/irc/server.rb', line 64

def all
  servers = []
  Weechat::Infolist.parse("irc_server").each do |server|
    servers << Server.from_name(server[:name])
  end
  servers
end

.find(name) ⇒ Object Also known as: from_name



72
73
74
75
76
77
78
# File 'lib/weechat/irc/server.rb', line 72

def find(name)
  o = allocate
  o.instance_variable_set(:@ptr, name.to_s)
  o.instance_variable_set(:@name, name.to_s)
  raise Exception::UnknownServer, name if o.get_infolist.empty?
  o
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?, equal?



53
54
55
# File 'lib/weechat/irc/server.rb', line 53

def ==(other)
  other.respond_to?(:ptr) && @ptr == other.ptr
end

#autojoin?Boolean



44
45
46
# File 'lib/weechat/irc/server.rb', line 44

def autojoin?
  !disable_autojoin
end

#channelsObject



86
87
88
89
90
91
92
# File 'lib/weechat/irc/server.rb', line 86

def channels
  channels = []
  Weechat::Infolist.parse("irc_channel", "", @name).each do |channel|
    channels << IRC::Channel.new(channel[:buffer])
  end
  channels
end

#command(*parts) ⇒ Object Also known as: send_command, exec, execute



104
105
106
# File 'lib/weechat/irc/server.rb', line 104

def command(*parts)
  self.buffer.command(*parts)
end

#connectObject



94
95
96
97
# File 'lib/weechat/irc/server.rb', line 94

def connect
  return false if connected?
  Weechat.exec("/connect #{@name}")
end

#disconnectObject



99
100
101
102
# File 'lib/weechat/irc/server.rb', line 99

def disconnect
  return false if not connected?
  exec("/disconnect #{@name}")
end

#get_infolist(*fields) ⇒ Object



82
83
84
# File 'lib/weechat/irc/server.rb', line 82

def get_infolist(*fields)
  Weechat::Infolist.parse(self.class.type, "", @ptr, {}, *fields)
end

#hashObject



59
60
61
# File 'lib/weechat/irc/server.rb', line 59

def hash
  @ptr.hash
end