module OpmlParser

OpmlParser Module

A very simple and easy to use module for importing and exporting OPML.

Credits

Kevin Gillieron <gw-computing at kevin.gillieron.net>

Public Instance Methods

export(feeds, title="No title") click to toggle source

Export an OPML String into an array of Outline objects.

Arguments:

feeds: (Array of Outline) An array of Outline objects
title: (String) Title of the OPML document
# File lib/opml-parser.rb, line 47
def export(feeds, title="No title")
        builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
                xml.opml(version: "1.0") do
                        xml.head { xml.title title }
                        xml.body { feeds.each { |outline| xml.outline(outline.attributes) }}
                end
        end
        builder.to_xml
end
import(contents) click to toggle source

Parse an OPML String into an array of Outline objects.

Arguments:

contents: (String) A String that contains the OMPL
# File lib/opml-parser.rb, line 33
def import(contents)
        doc = Nokogiri.XML(contents)

        doc.xpath("//body//outline").inject(Array.new) do |feeds, outline|
                next if outline.attributes.empty?
                feeds << Outline.new(xml_node_to_hash(outline.attributes))
        end
end