Class: BitlbeeConfig::Channel

Inherits:
Object
  • Object
show all
Includes:
XmlBuildable
Defined in:
lib/bitlbee_config/channel.rb

Overview

A channel on the bitlbee server. Can either be a control channel, in which you issue commands to the BitlBee root user, or a chat channel, which is a multi contact conversation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlBuildable

#to_xml_with_options

Constructor Details

#initialize(options = {}) ⇒ Channel

Returns a new instance of Channel.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :name (String)

    Channel name. Don’t forget # or &

  • :type ("control"|"chat")

    Type of channel

  • All (String)

    other entries will be converted to settings



32
33
34
35
36
# File 'lib/bitlbee_config/channel.rb', line 32

def initialize(options = {})
  @name = options.delete(:name)
  @type = options.delete(:type)
  @settings = options || {}
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/bitlbee_config/channel.rb', line 6

def name
  @name
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/bitlbee_config/channel.rb', line 6

def settings
  @settings
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/bitlbee_config/channel.rb', line 6

def type
  @type
end

Class Method Details

.from_xml(xml) ⇒ BitlbeeConfig::Channel

Returns The newly created channel.

Parameters:

  • xml (Nokogiri::XML::Element)

    XML element to create channel from

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bitlbee_config/channel.rb', line 11

def from_xml(xml)
  new_channel = {}

  # get setting attributes
  xml.attributes.each do |att_name, att_value|
    new_channel[att_name.to_sym] = att_value.text
  end

  # get setting children
  xml.children.select { |node| node.is_a?(Nokogiri::XML::Element) }.each do |setting_element|
    new_channel[setting_element.values.first.to_sym] = setting_element.text
  end

  BitlbeeConfig::Channel.new(new_channel)
end

Instance Method Details

#build_xml(xml_builder) ⇒ Object

Parameters:

  • xml_builder (Nokogiri::XML::Builder)

    All XML will be added to this builder



39
40
41
# File 'lib/bitlbee_config/channel.rb', line 39

def build_xml(xml_builder)
  to_xml_with_options(xml_builder, name: @name, type: @type)
end