Class: Feedcellar::Opml

Inherits:
Object
  • Object
show all
Defined in:
lib/feedcellar/opml.rb

Constant Summary collapse

OUTLINE_ATTRIBUTES =
[
  "text",
  "isComment",
  "isBreakpoint",
  "created",
  "category",
  "description",
  "url",
  "htmlUrl",
  "xmlUrl",
  "title",
  "version",
  "language",
]

Class Method Summary collapse

Class Method Details

.build(items) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/feedcellar/opml.rb', line 35

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) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/feedcellar/opml.rb', line 20

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