Skip to content
Browse files

added add_common_feed_elements and add_common_feed_entry_elements. Cl…

…oses #22
  • Loading branch information...
1 parent 163a009 commit e44de3f7ca59131484dddf52a2f3e7aa4a5be1c8 @archiloque archiloque committed Jul 9, 2011
Showing with 38 additions and 7 deletions.
  1. +38 −7 lib/feedzirra/feed.rb
View
45 lib/feedzirra/feed.rb
@@ -49,37 +49,68 @@ def self.feed_classes
@feed_classes ||= [Feedzirra::Parser::RSS, Feedzirra::Parser::AtomFeedBurner, Feedzirra::Parser::Atom]
end
- # Makes all registered feeds types look for the passed in element to parse. This is actually just a call to
- # element (a SAXMachine call) in the class
+ # Makes all registered feeds types look for the passed in element to parse.
+ # This is actually just a call to element (a SAXMachine call) in the class.
#
# === Parameters
- # [element_tag<String>]
+ # [element_tag<String>] The element tag
# [options<Hash>] Valid keys are same as with SAXMachine
def self.add_common_feed_element(element_tag, options = {})
feed_classes.each do |k|
k.element element_tag, options
end
end
- # Makes all registered entry types look for the passed in element to parse. This is actually just a call to
- # element (a SAXMachine call) in the class
+ # Makes all registered feeds types look for the passed in elements to parse.
+ # This is actually just a call to elements (a SAXMachine call) in the class.
+ #
+ # === Parameters
+ # [element_tag<String>] The element tag
+ # [options<Hash>] Valid keys are same as with SAXMachine
+ def self.add_common_feed_elements(element_tag, options = {})
+ feed_classes.each do |k|
+ k.elements element_tag, options
+ end
+ end
+
+ # Makes all registered entry types look for the passed in element to parse.
+ # This is actually just a call to element (a SAXMachine call) in the class.
#
# === Parameters
# [element_tag<String>]
# [options<Hash>] Valid keys are same as with SAXMachine
def self.add_common_feed_entry_element(element_tag, options = {})
+ call_on_each_feed_entry :element, element_tag, options
+ end
+
+ # Makes all registered entry types look for the passed in elements to parse.
+ # This is actually just a call to element (a SAXMachine call) in the class.
+ #
+ # === Parameters
+ # [element_tag<String>]
+ # [options<Hash>] Valid keys are same as with SAXMachine
+ def self.add_common_feed_entry_elements(element_tag, options = {})
+ call_on_each_feed_entry :elements, element_tag, options
+ end
+
+ # Call a method on all feed entries classes.
+ #
+ # === Parameters
+ # [method<Symbol>] The method name
+ # [parameters<Array>] The method parameters
+ def self.call_on_each_feed_entry(method, *parameters)
feed_classes.each do |k|
# iterate on the collections defined in the sax collection
k.sax_config.collection_elements.each_value do |vl|
# vl is a list of CollectionConfig mapped to an attribute name
# we'll look for the one set as 'entries' and add the new element
vl.find_all{|v| (v.accessor == 'entries') && (v.data_class.class == Class)}.each do |v|
- v.data_class.element element_tag, options
+ v.data_class.send(method, *parameters)
end
end
end
end
-
+
# Fetches and returns the raw XML for each URL provided.
#
# === Parameters

0 comments on commit e44de3f

Please sign in to comment.
Something went wrong with that request. Please try again.