class Splitter_atom

Public Class Methods

new(document, destination) click to toggle source
# File lib/abelard/load.rb, line 132
def initialize(document, destination)
  @doc = document
  @dest = destination
end

Public Instance Methods

save(node) click to toggle source
# File lib/abelard/load.rb, line 163
def save(node)
      id = node.children.find { |n| n.name == "id" }
      id = id && id.content

      path = XmlUtil::self_link(node)

      case node.name
      when "entry"
        category = XmlUtil::child_attribute(node, "category", "term")

        if @feed_type
              entry_type = @feed_type 
        else
              entry_type = category.split('#').last if category
        end
        
        case entry_type
        when "post"
              postnumber = path.split('/').last
              filename = "#{@dest}/post-#{postnumber}.xml"
              write_item(node, filename)
        when "comment"
              pathsplit = path.split('/')
              postnumber = pathsplit[-4]
              commentnumber = pathsplit[-1]
              filename = "#{@dest}/comment-#{postnumber}-#{commentnumber}.xml"
              write_item(node,filename)
        end
      end
end
split_items() click to toggle source
# File lib/abelard/load.rb, line 137
def split_items
  feed = @doc.root

  feedself = XmlUtil::self_link(feed)

  @feed_type = nil # unknown
  @feed_type = "post" if (feedself =~ %r{/posts/default$})
  @feed_type = "comment" if (feedself =~ %r{/comments/default$})
  
  @parent = LibXML::XML::Document.new()
  root = LibXML::XML::Node.new(feed.name)
  @parent.root = root
  feed.namespaces.definitions.each {|ns| LibXML::XML::Namespace.new(root, ns.prefix, ns.href)}
  feed.attributes.each { |a| root.attributes[a.name] = a.value }

  feed.children.select(&:element?).each do |node|
    if (node.name == "entry")
      save(node)
    else
      root << @parent.import(node)
    end
  end

  write_doc_clean(@parent, "#{@dest}/feed.xml")
end