Hello,
I've bundled up a new alternate opmlparser gem [1]
that lets you read / parse outlines (incl. feed subscription lists)
in the OPML (Outline Processor Markup Language) format in xml.
Use OPML.load or OPML.load_file to get back a "plain standard
vanilla" hash table or use Outline.parse or Outline.read to get back
outline struct(ure)s.
Example from the readme:
Option 1) `OPML.load` - load from string. Example:
hash = OPML.load( <<TXT )
<opml version="1.1">
<head>
<title>Planet Ruby</title>
<dateCreated>Mon, 02 Mar 2020 08:21:56 -0000</dateCreated>
</head>
<body>
<outline text="Ruby Lang News"
xmlUrl="http://www.ruby-lang.org/en/feeds/news.rss"/>
<outline text="JRuby Lang News" xmlUrl="http://www.jruby.org/atom.xml"/>
<outline text="RubyGems News" xmlUrl="http://blog.rubygems.org/atom.xml"/>
<outline text="Sinatra News" xmlUrl="http://sinatrarb.com/feed.xml"/>
<outline text="Hanami News" xmlUrl="https://hanamirb.org/atom.xml"/>
<outline text="Jekyll News" xmlUrl="http://jekyllrb.com/feed.xml"/>
</body>
</opml>
TXT
Option 2) `OPML.load_file` - load from file (shortcut). Example:
hash = OPML.load_file( './planet.opml.xml' )
All together now. Example:
require 'opmlparser'
xml = <<TXT
<opml version="1.1">
<head>
<title>Planet Ruby</title>
<dateCreated>Mon, 02 Mar 2020 08:21:56 -0000</dateCreated>
</head>
<body>
<outline text="Ruby Lang News"
xmlUrl="http://www.ruby-lang.org/en/feeds/news.rss"/>
<outline text="JRuby Lang News" xmlUrl="http://www.jruby.org/atom.xml"/>
<outline text="RubyGems News" xmlUrl="http://blog.rubygems.org/atom.xml"/>
<outline text="Sinatra News" xmlUrl="http://sinatrarb.com/feed.xml"/>
<outline text="Hanami News" xmlUrl="https://hanamirb.org/atom.xml"/>
<outline text="Jekyll News" xmlUrl="http://jekyllrb.com/feed.xml"/>
</body>
</opml>
TXT
hash = OPML.load( xml )
pp hash
resulting in:
{"meta"=>
{"title"=>"Planet Ruby",
"dateCreated"=>"Mon, 02 Mar 2020 08:21:56 -0000"},
"outline"=>
[{"text"=>"Ruby Lang News",
"xmlUrl"=>"http://www.ruby-lang.org/en/feeds/news.rss"},
{"text"=>"JRuby Lang News", "xmlUrl"=>"http://www.jruby.org/atom.xml"},
{"text"=>"RubyGems News", "xmlUrl"=>"http://blog.rubygems.org/atom.xml"},
{"text"=>"Sinatra News", "xmlUrl"=>"http://sinatrarb.com/feed.xml"},
{"text"=>"Hanami News", "xmlUrl"=>"https://hanamirb.org/atom.xml"},
{"text"=>"Jekyll News", "xmlUrl"=>"http://jekyllrb.com/feed.xml"}]}
to access use:
hash['meta']['title'] #=> "Planet Ruby"
hash['outline'][0]['text'] #=> "Ruby Lang News"
hash['outline'][0]['xmlUrl'] #=> "http://www.ruby-lang.org/en/feeds/news.rss"
hash['outline'][1]['text'] #=> "JRuby Lang News"
hash['outline'][1]['xmlUrl'] #=> "http://www.jruby.org/atom.xml"
What about using a "type-safe" outline struct(ure)?
Option 1) `Outline.parse` - parse from string. Example:
outline = Outline.parse( <<TXT )
<opml version="1.1">
<head>
<title>Planet Ruby</title>
<dateCreated>Mon, 02 Mar 2020 08:21:56 -0000</dateCreated>
</head>
<body>
<outline text="Ruby Lang News"
xmlUrl="http://www.ruby-lang.org/en/feeds/news.rss"/>
<outline text="JRuby Lang News" xmlUrl="http://www.jruby.org/atom.xml"/>
<outline text="RubyGems News" xmlUrl="http://blog.rubygems.org/atom.xml"/>
<outline text="Sinatra News" xmlUrl="http://sinatrarb.com/feed.xml"/>
<outline text="Hanami News" xmlUrl="https://hanamirb.org/atom.xml"/>
<outline text="Jekyll News" xmlUrl="http://jekyllrb.com/feed.xml"/>
</body>
</opml>
TXT
Option 2) `Outline.read` - read from file (shortcut). Example:
outline = Outline.read( './planet.opml.xml' )
to access use:
outline.meta.title #=> "Planet Ruby"
outline[0].text #=> "Ruby Lang News"
outline[0].xml_url #=> "http://www.ruby-lang.org/en/feeds/news.rss"
outline[1].text #=> "JRuby Lang News"
outline[1].xml_url #=> "http://www.jruby.org/atom.xml"
Cheers. Prost.
[1]: https://github.com/feedreader/pluto/tree/master/opmlparser