Class: Blather::Stanza::PubSub::Items

Inherits:
Blather::Stanza::PubSub show all
Includes:
Enumerable
Defined in:
lib/blather/stanza/pubsub/items.rb

Constant Summary

Constants inherited from Iq

Iq::VALID_TYPES

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Blather::Stanza::PubSub

import, #inherit, #pubsub

Methods inherited from Iq

import, #type=

Methods inherited from Blather::Stanza

#as_error, attribute_helpers_for, #from, handler_list, next_id, register, #reply, #reply!, #to

Methods inherited from XMPPNode

attribute_accessor, attribute_reader, attribute_writer, class_from_registration, content_attr_accessor, content_attr_reader, content_attr_writer, #content_from, import, #inherit, #inherit_attrs, #namespace=, #namespace_href, #nokogiri_namespace=, register, #remove_child, #remove_children, #set_content_for, #to_stanza

Methods inherited from Nokogiri::XML::Node

#[]=, #attr_set, #find_first, #nokogiri_xpath, #xpath

Class Method Details

.new(type = nil, host = nil) ⇒ Object



22
23
24
25
26
# File 'lib/blather/stanza/pubsub/items.rb', line 22

def self.new(type = nil, host = nil)
  new_node = super
  new_node.items
  new_node
end

.request(host, path, list = [], max = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/blather/stanza/pubsub/items.rb', line 11

def self.request(host, path, list = [], max = nil)
  node = self.new :get, host

  node.node = path
  node.max_items = max

  (list || []).each { |id| node.items_node << PubSubItem.new(id, nil, node.document) }

  node
end

Instance Method Details

#each(&block) ⇒ Object



44
45
46
# File 'lib/blather/stanza/pubsub/items.rb', line 44

def each(&block)
  items.each &block
end

#itemsObject



48
49
50
# File 'lib/blather/stanza/pubsub/items.rb', line 48

def items
  items_node.find('ns:item', :ns => self.class.registered_ns).map { |i| PubSubItem.new(nil,nil,self.document).inherit i }
end

#items_nodeObject



52
53
54
55
56
57
58
# File 'lib/blather/stanza/pubsub/items.rb', line 52

def items_node
  unless node = self.pubsub.find_first('ns:items', :ns => self.class.registered_ns)
    (self.pubsub << (node = XMPPNode.new('items', self.document)))
    node.namespace = self.pubsub.namespace
  end
  node
end

#max_itemsObject



36
37
38
# File 'lib/blather/stanza/pubsub/items.rb', line 36

def max_items
  items_node[:max_items].to_i if items_node[:max_items]
end

#max_items=(max_items) ⇒ Object



40
41
42
# File 'lib/blather/stanza/pubsub/items.rb', line 40

def max_items=(max_items)
  items_node[:max_items] = max_items
end

#nodeObject



28
29
30
# File 'lib/blather/stanza/pubsub/items.rb', line 28

def node
  items_node[:node]
end

#node=(node) ⇒ Object



32
33
34
# File 'lib/blather/stanza/pubsub/items.rb', line 32

def node=(node)
  items_node[:node] = node
end