class Feedcellar::Opml

Constants

OUTLINE_ATTRIBUTES

Public Class Methods

build(items) click to toggle source
# File lib/feedcellar/opml.rb, line 53
def self.build(items)
  document = REXML::Document.new

  xml_decl = REXML::XMLDecl.new
  xml_decl.version = "1.0"
  xml_decl.encoding = "UTF-8"
  document.add(xml_decl)

  root = document.add_element("opml")
  root.add_attributes("version" => "1.0")

  head = root.add_element("head")
  title = head.add_element("title")
  title.add_text("registers in feedcellar")

  body = root.add_element("body")
  items.each do |item|
    outline = body.add_element("outline")
    item.attributes.each do |key, value|
      outline.add_attributes(key => value)
    end
  end

  document.to_s
end
parse(file) click to toggle source
# File lib/feedcellar/opml.rb, line 38
def self.parse(file)
  # FIXME improve valiable names
  # FIXME outline for tags
  outlines = []
  doc = REXML::Document.new(File.open(file))
  REXML::XPath.each(doc, "//outline") do |outline|
    attributes = {}
    OUTLINE_ATTRIBUTES.each do |attribute|
      attributes[attribute] = outline.attributes[attribute]
    end
    outlines << attributes
  end
  outlines
end