From 8473bf111757e1e119dbc12cbb4a6b6764a1fe17 Mon Sep 17 00:00:00 2001
From: Mark McSpadden
Date: Sat, 11 Dec 2010 01:35:12 -0600
Subject: [PATCH] Allow for entry/item level attributes. (SimpleRSS.item_tags
<< 'entry#my_attr')
---
lib/simple-rss.rb | 10 +-
test/base/entry_attributes_test.rb | 27 +++
test/data/atom.xml | 2 +-
test/data/media_rss.xml | 2 +-
test/data/rss09.rdf | 2 +-
test/data/rss20.xml | 302 ++++++++++++++---------------
6 files changed, 190 insertions(+), 155 deletions(-)
create mode 100644 test/base/entry_attributes_test.rb
diff --git a/lib/simple-rss.rb b/lib/simple-rss.rb
index fc375ab..380d434 100644
--- a/lib/simple-rss.rb
+++ b/lib/simple-rss.rb
@@ -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
diff --git a/test/base/entry_attributes_test.rb b/test/base/entry_attributes_test.rb
new file mode 100644
index 0000000..0170bd7
--- /dev/null
+++ b/test/base/entry_attributes_test.rb
@@ -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
\ No newline at end of file
diff --git a/test/data/atom.xml b/test/data/atom.xml
index 3d6ae54..81ddda7 100644
--- a/test/data/atom.xml
+++ b/test/data/atom.xml
@@ -15,7 +15,7 @@
Example Toolkit
-
+ Atom draft-07 snapshot
diff --git a/test/data/media_rss.xml b/test/data/media_rss.xml
index 3cdecf7..cb59031 100644
--- a/test/data/media_rss.xml
+++ b/test/data/media_rss.xml
@@ -19,7 +19,7 @@
http://www.flickr.com/photos/herval/
-
+ Woof?
http://www.flickr.com/photos/herval/4671960608/
<p><a href="http://www.flickr.com/people/herval/">herval</a> posted a photo:</p>
diff --git a/test/data/rss09.rdf b/test/data/rss09.rdf
index bc10ead..b7c2686 100644
--- a/test/data/rss09.rdf
+++ b/test/data/rss09.rdf
@@ -18,7 +18,7 @@ xmlns="http://my.netscape.com/rdf/simple/0.9/">
http://slashdot.org/
-
+JBoss - A Developer's Notebook
http://books.slashdot.org/article.pl?sid=05/08/29/1319236&from=rss
2005-09-09T02:52:31-07:00
diff --git a/test/data/rss20.xml b/test/data/rss20.xml
index 09e616d..aa41f01 100644
--- a/test/data/rss20.xml
+++ b/test/data/rss20.xml
@@ -1,26 +1,26 @@
-
-
-
-
-
-
- Technoblog
- http://tech.rufy.com
- Lucas Carlson's jounal of the technical ramblings. Contains tutorials, howto's, and rants and ravings.
- Thu, 25 Aug 2005 00:16:16 +0000
- http://wordpress.org/?v=1.5
- en
-
- This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.
-
- some_string.starts_with? “Foo” || some_string.ends_with? “bar.”
- http://feeds.feedburner.com/rufytech?m=68
- http://tech.rufy.com/entry/82#comments
- Wed, 24 Aug 2005 13:33:34 +0000
- Lucas Carlson
- Programming
- Ruby
- http://tech.rufy.com/entry/82
+
+
+
+
+
+
+ Technoblog
+ http://tech.rufy.com
+ Lucas Carlson's jounal of the technical ramblings. Contains tutorials, howto's, and rants and ravings.
+ Thu, 25 Aug 2005 00:16:16 +0000
+ http://wordpress.org/?v=1.5
+ en
+
+ This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.
+
+ some_string.starts_with? “Foo” || some_string.ends_with? “bar.”
+ http://feeds.feedburner.com/rufytech?m=68
+ http://tech.rufy.com/entry/82#comments
+ Wed, 24 Aug 2005 13:33:34 +0000
+ Lucas Carlson
+ Programming
+ Ruby
+ http://tech.rufy.com/entry/82
+some_string.starts_with? 'Foo' || some_string.ends_with? 'bar.']]>I also liked:
x = s.startswith('Go')
@@ -68,19 +68,19 @@ end
some_string.starts_with? 'Foo' || some_string.ends_with? 'bar.'
-]]>
- http://tech.rufy.com/entry/82/feed/
- http://tech.rufy.com/entry/82
-
-
- if some_object.in? [1, 2, 3]
- http://feeds.feedburner.com/rufytech?m=67
- http://tech.rufy.com/entry/81#comments
- Wed, 24 Aug 2005 12:53:46 +0000
- Lucas Carlson
- Programming
- Ruby
- http://tech.rufy.com/entry/81
+]]>
+ http://tech.rufy.com/entry/82/feed/
+ http://tech.rufy.com/entry/82
+
+
+ if some_object.in? [1, 2, 3]
+ http://feeds.feedburner.com/rufytech?m=67
+ http://tech.rufy.com/entry/81#comments
+ Wed, 24 Aug 2005 12:53:46 +0000
+ Lucas Carlson
+ Programming
+ Ruby
+ http://tech.rufy.com/entry/81
+end]]>
Looking over some Python code, I really really like the syntax:
if some_object in [1, 2, 3]:
@@ -124,19 +124,19 @@ if some_object.in? [1, 2, 3]
end
-]]>
- http://tech.rufy.com/entry/81/feed/
- http://tech.rufy.com/entry/81
-
-
- Y Combinator’s 2005 Summer Founders Program: A Complete Dud
- http://feeds.feedburner.com/rufytech?m=66
- http://tech.rufy.com/entry/80#comments
- Wed, 10 Aug 2005 18:23:20 +0000
- Lucas Carlson
- General
- http://tech.rufy.com/entry/80
-
+]]>
+ http://tech.rufy.com/entry/81/feed/
+ http://tech.rufy.com/entry/81
+
+
+ Y Combinator’s 2005 Summer Founders Program: A Complete Dud
+ http://feeds.feedburner.com/rufytech?m=66
+ http://tech.rufy.com/entry/80#comments
+ Wed, 10 Aug 2005 18:23:20 +0000
+ Lucas Carlson
+ General
+ http://tech.rufy.com/entry/80
+ I know that by writing this I may well be killing any chances at future funding from Paul Graham and Co. over at Y Combinator, but this was downright atrocious. Let me preface this by saying I am personally disappointed because I applied to the Summer Founders Program and was rejected. From what I can tell, I can reproduce in a weekend what took these people 3 months to accomplish.
Background
Paul Graham started a VC for mini startups called Y Combinator. They gave 9 groups $6,000-10,000 PER PERSON to work on any website they wanted for 3 months. My entry was Web Collaborator. During my summer, I created Print Promotion, worked on a top secret project with Adaptive Path that will soon change the way you feel about blogging, and am now working with O’Reilly on an amazingly innovative project. Quite productive for 3 months.
@@ -161,24 +161,24 @@ end
This account says that “at least half of the startups in the program are seriously cool” so maybe I have just seen the bad half.
-]]>
- http://tech.rufy.com/entry/80/feed/
- http://tech.rufy.com/entry/80
-
-
- OSCon 2005: Lucas
- http://feeds.feedburner.com/rufytech?m=65
- http://tech.rufy.com/entry/79#comments
- Mon, 08 Aug 2005 11:43:47 +0000
- Lucas Carlson
- General
- http://tech.rufy.com/entry/79
+]]>
+ http://tech.rufy.com/entry/80/feed/
+ http://tech.rufy.com/entry/80
+
+
+ OSCon 2005: Lucas
+ http://feeds.feedburner.com/rufytech?m=65
+ http://tech.rufy.com/entry/79#comments
+ Mon, 08 Aug 2005 11:43:47 +0000
+ Lucas Carlson
+ General
+ http://tech.rufy.com/entry/79
+I was shot at OSCON. Thanks Duncan!]]>
@@ -192,23 +192,23 @@ I was shot at OSCON. Thanks Duncan!]]>
-]]>
- http://tech.rufy.com/entry/79/feed/
- http://tech.rufy.com/entry/79
-
-
- OSCON 2005: Matz Talks about Yielding to the Power of Blocks in Ruby
- http://feeds.feedburner.com/rufytech?m=64
- http://tech.rufy.com/entry/78#comments
- Thu, 04 Aug 2005 08:33:42 +0000
- Lucas Carlson
- General
- http://tech.rufy.com/entry/78
+]]>
+ http://tech.rufy.com/entry/79/feed/
+ http://tech.rufy.com/entry/79
+
+
+ OSCON 2005: Matz Talks about Yielding to the Power of Blocks in Ruby
+ http://feeds.feedburner.com/rufytech?m=64
+ http://tech.rufy.com/entry/78#comments
+ Thu, 04 Aug 2005 08:33:42 +0000
+ Lucas Carlson
+ General
+ http://tech.rufy.com/entry/78
+Unlike many of the other talks, many people are taking pictures of this one... mainly of the audience. I guess [...]]]>
I am sitting and waiting for Matz to talk about blocks right now. Keep watching, I will post notes as I go.
The room is packed with people even sitting on the floor to get a peak.
Unlike many of the other talks, many people are taking pictures of this one… mainly of the audience. I guess they find it as interesting as I do that people are crawling over themselves to get to this talk.
@@ -458,21 +458,21 @@ ary.to_enum(:each_with_index).reject { |x,i| i%2==0 } # => [[4,0], [1,3]]
Matz uses Emacs and some version of Linux ons small panasonic laptop
-]]>
- http://tech.rufy.com/entry/78/feed/
- http://tech.rufy.com/entry/78
-
-
- OSCON 2005: Business For Geeks
- http://feeds.feedburner.com/rufytech?m=63
- http://tech.rufy.com/entry/77#comments
- Mon, 01 Aug 2005 09:49:53 +0000
- Lucas Carlson
- General
- http://tech.rufy.com/entry/77
+]]>
+ http://tech.rufy.com/entry/78/feed/
+ http://tech.rufy.com/entry/78
+
+
+ OSCON 2005: Business For Geeks
+ http://feeds.feedburner.com/rufytech?m=63
+ http://tech.rufy.com/entry/77#comments
+ Mon, 01 Aug 2005 09:49:53 +0000
+ Lucas Carlson
+ General
+ http://tech.rufy.com/entry/77
+the ideaDon’t talk about how the product works. Tell them about the market.“I’ve got this idea” Obsess about the need I will fulfillTalk about the needYou will never have an idea where everybody likes the idea/company nameDon’t sit down [...]]]>
I am at Business for Geeks right now waiting for Marc Hedlund to teach me fun stuff.
the idea
@@ -621,22 +621,22 @@ Flickr
Book: Art of the Start – http://garage.com/
-]]>
- http://tech.rufy.com/entry/77/feed/
- http://tech.rufy.com/entry/77
-
-
- Does Ruby on Rails scale? A clear and definitive answer
- http://feeds.feedburner.com/rufytech?m=62
- http://tech.rufy.com/entry/76#comments
- Thu, 28 Jul 2005 23:25:36 +0000
- Lucas Carlson
- Programming
- Ruby
- http://tech.rufy.com/entry/76
+]]>
+ http://tech.rufy.com/entry/77/feed/
+ http://tech.rufy.com/entry/77
+
+
+ Does Ruby on Rails scale? A clear and definitive answer
+ http://feeds.feedburner.com/rufytech?m=62
+ http://tech.rufy.com/entry/76#comments
+ Thu, 28 Jul 2005 23:25:36 +0000
+ Lucas Carlson
+ Programming
+ Ruby
+ http://tech.rufy.com/entry/76
+I don't think anyone would argue [...]]]>
The last post on this page ends with “I’ll just have to do the damn tests myself”. What tests? I never knew there was a set of tests that could be done against any framework or programming language to definitively say it “scales”. If I am wrong, please correct me.
I don’t think anyone would argue that the following languages couldn’t be used to scale a website since they have all been used in commercial web applications: C, C++, Java, PHP, Perl, Python, Lisp. If all of those languages have been used to build “scalable” websites, then why would anyone think that Ruby couldn’t scale? What would have to be so fundamentally wrong with Ruby that make people so hesitant? Is it because it is interpreted? So are PHP, Perl, and Python. Is it because there are no extremely high traffic sites built with Ruby to date? It was just the other day that no extremely high traffic sites were built in PHP or Python either.
No, scalability is not about the language. To ask if a programming language can scale or not is equivalent to asking if a certain written language can be used to write an epic novel. Very very few mature modern languages can’t scale for web sites (I concede that BASIC might be one of them). Similar discussion has happened here.
@@ -661,19 +661,19 @@ I don't think anyone would argue [...]]]>
This is exactly what David Hansson means by saying it’s boring to scale with Ruby on Rails. This is also why I can’t imagine a test you can do against a framework to see if it can scale. You can’t do any test that looks for a positive outcome because the scalability of a website is highly dependent on how the site was implemented. You can however look for any roadblocks to the common design patterns, and approached this way you can even ask people familiar with the framework your questions and get back reasonable answers.
-]]>
- http://tech.rufy.com/entry/76/feed/
- http://tech.rufy.com/entry/76
-
-
- Executing interactive system commands in Ruby
- http://feeds.feedburner.com/rufytech?m=61
- http://tech.rufy.com/entry/75#comments
- Sun, 24 Jul 2005 01:26:29 +0000
- Lucas Carlson
- Programming
- Ruby
- http://tech.rufy.com/entry/75
+]]>
+ http://tech.rufy.com/entry/76/feed/
+ http://tech.rufy.com/entry/76
+
+
+ Executing interactive system commands in Ruby
+ http://feeds.feedburner.com/rufytech?m=61
+ http://tech.rufy.com/entry/75#comments
+ Sun, 24 Jul 2005 01:26:29 +0000
+ Lucas Carlson
+ Programming
+ Ruby
+ http://tech.rufy.com/entry/75
+Hope this helps anybody looking for the answer. An example [...]]]>
Following a Ruby Talk thread about how to interactively run shell commands, I think I’ve finally got it. Let’s say you want to run a command, answer the first question it gives you, and get the output.
@@ -713,19 +713,19 @@ end
-]]>
- http://tech.rufy.com/entry/75/feed/
- http://tech.rufy.com/entry/75
-
-
- Lisp on Rails
- http://feeds.feedburner.com/rufytech?m=60
- http://tech.rufy.com/entry/74#comments
- Tue, 19 Jul 2005 12:32:21 +0000
- Lucas Carlson
- Programming
- http://tech.rufy.com/entry/74
-
+]]>
+ http://tech.rufy.com/entry/75/feed/
+ http://tech.rufy.com/entry/75
+
+
+ Lisp on Rails
+ http://feeds.feedburner.com/rufytech?m=60
+ http://tech.rufy.com/entry/74#comments
+ Tue, 19 Jul 2005 12:32:21 +0000
+ Lucas Carlson
+ Programming
+ http://tech.rufy.com/entry/74
+ I know there is is some toying around with Lisp on Rails like stuff (lisp-on-lines), but that is a little too Lispy for me just yet. Rather, what do you think of this? Worth exploring more? Should I light up the midnight flame to get a proof-of-concept version on Lisp on Rails working (/me *drools* at the thought of machine code with the flexibility of Ruby).
Some ideas that would be great include adding continuations and being able to have a self-containted file (as in the example that follows) for those times when you really only want a couple controllers and a couple actions.
@@ -770,18 +770,18 @@ end
-]]>
- http://tech.rufy.com/entry/74/feed/
- http://tech.rufy.com/entry/74
-
-
- A wish: Abolition of passing data with flags and symbol-like options when calling Unix programs
- http://feeds.feedburner.com/rufytech?m=59
- http://tech.rufy.com/entry/73#comments
- Tue, 19 Jul 2005 00:16:03 +0000
- Lucas Carlson
- General
- http://tech.rufy.com/entry/73
+]]>
+ http://tech.rufy.com/entry/74/feed/
+ http://tech.rufy.com/entry/74
+
+
+ A wish: Abolition of passing data with flags and symbol-like options when calling Unix programs
+ http://feeds.feedburner.com/rufytech?m=59
+ http://tech.rufy.com/entry/73#comments
+ Tue, 19 Jul 2005 00:16:03 +0000
+ Lucas Carlson
+ General
+ http://tech.rufy.com/entry/73
+The difference between -- and : is huge for me [...]]]>
I wish I could call every program on the command line like this:
mysql -v :user foo :password bar :host rufy.com :port 3306
For me, this is much easier to type than what I would currently need to do:
@@ -809,10 +809,10 @@ The difference between -- and : is huge for me [...]]]>
Anyone know how I can alias a colon to work along side the double-dash in getopt_long()?