Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry/Item level attributes #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/simple-rss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ def parse
elsif match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)#{attrib}=['"](.*?)['"](.*?)/\s*>}mi
nil
end
item[clean_tag("#{tag}_#{attrib}")] = clean_content(tag, attrib, $3) if $3

# MM2: Account for attributes on the item/entry tag
if tag == "item" || tag == "entry"
if match[2] =~ /#{attrib}=['"](.*)['"]/
item[clean_tag("#{tag}_#{attrib}")] = clean_content(tag, attrib, $1)
end
else
item[clean_tag("#{tag}_#{attrib}")] = clean_content(tag, attrib, $3) if $3
end
else
if match[3] =~ %r{<(rss:|atom:)?#{tag}(.*?)>(.*?)</(rss:|atom:)?#{tag}>}mi
nil
Expand Down
27 changes: 27 additions & 0 deletions test/base/entry_attributes_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require File.dirname(__FILE__) + '/../test_helper'
class EntryAttributesTest < Test::Unit::TestCase
def setup
SimpleRSS.item_tags << :'entry#gr:crawl-timestamp-msec'

@rss09 = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/rss09.rdf')
@rss20 = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/rss20.xml')
@media_rss = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/media_rss.xml')
@atom = SimpleRSS.parse open(File.dirname(__FILE__) + '/../data/atom.xml')
end

def test_rss09
assert_equal "1291841305234", @rss09.items.first[:'entry_gr_crawl-timestamp-msec']
end

def test_media_rss
assert_equal "1291841305234", @media_rss.items.first[:'entry_gr_crawl-timestamp-msec']
end

def test_rss20
assert_equal "1291841305234", @rss20.items.first[:'entry_gr_crawl-timestamp-msec']
end

def test_atom
assert_equal "1291841305234", @atom.entries.first[:'entry_gr_crawl-timestamp-msec']
end
end
2 changes: 1 addition & 1 deletion test/data/atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<generator uri="http://www.example.com/" version="1.0">
Example Toolkit
</generator>
<entry>
<entry gr:crawl-timestamp-msec="1291841305234">
<title>Atom draft-07 snapshot</title>
<link rel="alternate" type="text/html"
href="http://example.org/2005/04/02/atom"/>
Expand Down
2 changes: 1 addition & 1 deletion test/data/media_rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<link>http://www.flickr.com/photos/herval/</link>
</image>

<item>
<item gr:crawl-timestamp-msec="1291841305234">
<title>Woof?</title>
<link>http://www.flickr.com/photos/herval/4671960608/</link>
<description> &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/herval/&quot;&gt;herval&lt;/a&gt; posted a photo:&lt;/p&gt;
Expand Down
2 changes: 1 addition & 1 deletion test/data/rss09.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ xmlns="http://my.netscape.com/rdf/simple/0.9/">
<link>http://slashdot.org/</link>
</image>

<item>
<item gr:crawl-timestamp-msec="1291841305234">
<title>JBoss - A Developer's Notebook</title>
<link>http://books.slashdot.org/article.pl?sid=05/08/29/1319236&amp;from=rss</link>
<dc:date>2005-09-09T02:52:31-07:00</dc:date>
Expand Down
Loading