From b7fb844fdf03132c066b0b02666087ebea3530e5 Mon Sep 17 00:00:00 2001
From: danielvincent <danielgrippi@gmail.com>
Date: Wed, 4 Aug 2010 00:57:46 -0700
Subject: [PATCH] more cleanup on Diaspora::OStatusParser

---
 lib/diaspora/ostatus_parser.rb  | 39 +++++++++++++++++++--------------
 spec/lib/ostatus_parser_spec.rb |  2 +-
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/lib/diaspora/ostatus_parser.rb b/lib/diaspora/ostatus_parser.rb
index 201e908d2b..694cbcedbe 100644
--- a/lib/diaspora/ostatus_parser.rb
+++ b/lib/diaspora/ostatus_parser.rb
@@ -1,15 +1,11 @@
 module Diaspora
   module OStatusParser
-    def self.find_hub(xml)
-      xml = Nokogiri::HTML(xml) if xml.is_a? String
-      xml.xpath('//link[@rel="hub"]').first.attribute("href").value
-    end
 
     def self.process(xml)
       doc = Nokogiri::HTML(xml)
       author_hash = parse_author(doc)
 
-      author_hash[:hub] = find_hub(doc) 
+      author_hash[:hub] = self.hub(doc) 
       entry_hash = parse_entry(doc)
 
       author = Author.instantiate(author_hash)
@@ -38,44 +34,53 @@ module Diaspora
     end
 
 
-    ##author###
+    def self.hub(xml)
+      xml = Nokogiri::HTML(xml) if xml.is_a? String
+      xml.xpath('//link[@rel="hub"]').first.attribute("href").value
+    end
+
+    # Author #########################
     def self.service(doc)
-      doc.xpath('//generator').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//generator'))
     end
 
     def self.feed_url(doc)
-      doc.xpath('//id').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//id'))
     end
 
     def self.avatar_thumbnail(doc)
-        doc.xpath('//logo').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//logo'))
     end
 
     def self.username(doc)
-      doc.xpath('//author/name').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//author/name'))
     end
 
     def self.profile_url(doc)
-      doc.xpath('//author/uri').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//author/uri'))
     end
 
-
-    #entry##
+    # Entry ##########################
     def self.message(doc)
-      doc.xpath('//entry/title').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//entry/title'))
     end
 
     def self.permalink(doc)
-      doc.xpath('//entry/id').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//entry/id'))
     end
 
     def self.published_at(doc)
-      doc.xpath('//entry/published').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//entry/published'))
     end
 
     def self.updated_at(doc)
-      doc.xpath('//entry/updated').each{|x| return x.inner_html}
+      self.contents(doc.xpath('//entry/updated'))
     end 
 
+
+    def self.contents(xpath)
+      xpath.each{|x| return x.inner_html}
+    end
+
   end
 end
diff --git a/spec/lib/ostatus_parser_spec.rb b/spec/lib/ostatus_parser_spec.rb
index 3f8b3a3ab3..8a431db9d2 100644
--- a/spec/lib/ostatus_parser_spec.rb
+++ b/spec/lib/ostatus_parser_spec.rb
@@ -5,7 +5,7 @@ describe Diaspora::OStatusParser do
     xml_path = File.dirname(__FILE__) + '/../fixtures/identica_feed.atom'
     xml = File.open(xml_path).read
 
-    Diaspora::OStatusParser::find_hub(xml).should == 'http://identi.ca/main/push/hub'
+    Diaspora::OStatusParser::hub(xml).should == 'http://identi.ca/main/push/hub'
   end
 
 
-- 
GitLab