Skip to content

Commit d546abf

Browse files
author
Matt Swanson
committed
allow groups to be parsed in opml import, closes stringer-rss#12
1 parent 6cf38ed commit d546abf

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎app/utils/opml_parser.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ def parse_feeds(contents)
55
doc = Nokogiri.XML(contents)
66

77
doc.xpath("//body//outline").inject([]) do |feeds, outline|
8+
next feeds if missing_fields? outline.attributes
9+
810
feeds << {
911
name: outline.attributes["title"].value,
1012
url: outline.attributes["xmlUrl"].value
1113
}
1214
end
1315
end
16+
17+
private
18+
def missing_fields?(attributes)
19+
attributes["xmlUrl"].nil? || attributes["title"].nil?
20+
end
1421
end

‎spec/utils/opml_parser_spec.rb‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@
3030
result.last[:url].should eq "http://mdswanson.com/atom.xml"
3131
end
3232

33+
it "handles nested groups of feeds" do
34+
parser = OpmlParser.new
35+
36+
result = parser.parse_feeds(<<-eos)
37+
<?xml version="1.0" encoding="UTF-8"?>
38+
<opml version="1.0">
39+
<head>
40+
<title>matt swanson subscriptions in Google Reader</title>
41+
</head>
42+
<body>
43+
<outline text="Technology News">
44+
<outline text="a sample feed" title="a sample feed" type="rss"
45+
xmlUrl="http://feeds.feedburner.com/foobar" htmlUrl="http://www.example.org/"/>
46+
</outline>
47+
</body>
48+
</opml>
49+
eos
50+
51+
result.count.should eq 1
52+
result.first[:name].should eq "a sample feed"
53+
result.first[:url].should eq "http://feeds.feedburner.com/foobar"
54+
end
55+
3356
it "doesn't explode when there are no feeds" do
3457
parser = OpmlParser.new
3558

0 commit comments

Comments
 (0)