Class: Atom::Content::External

Inherits:
Base show all
Defined in:
lib/atom.rb

Overview

External content reference within an Atom document.

Instance Method Summary collapse

Methods inherited from Base

#==

Methods included from Xml::Parseable

#==, #accessor_name, #current_node_is?, #document?, included, #next_node_is?, #parse

Methods inherited from String

#constantize, #demodulize, #singularize

Constructor Details

#initialize(o) ⇒ External

this one only works with XML::Reader instances, no strings, since the content won’t be inline.

Raises:

  • (ArgumentError)


221
222
223
224
225
# File 'lib/atom.rb', line 221

def initialize(o)
  raise ArgumentError, "Got #{o} which isn't an XML::Reader" unless o.kind_of?(Nokogiri::XML::Reader)
  super("")
  parse(o, :once => true)
end

Instance Method Details

#to_xml(builder = nil, name = 'content', namespace = nil, namespace_handler = nil) ⇒ Object



227
228
229
230
231
232
233
234
235
# File 'lib/atom.rb', line 227

def to_xml(builder = nil , name = 'content', namespace = nil, namespace_handler = nil)
  builder ||= Nokogiri::XML::Builder.new
  namespace_handler.prefix(builder, Atom::NAMESPACE) if namespace_handler
  attrs = {}
  attrs['type'] = self.type if self.type
  attrs['src'] = self.src if self.src
  builder.send("#{name}_", attrs)
  builder.doc.root
end