lib/html2rss/item_extractors.rb in html2rss-0.6.0 vs lib/html2rss/item_extractors.rb in html2rss-0.7.0
- old
+ new
@@ -1,24 +1,18 @@
-require_relative 'item_extractors/attribute'
-require_relative 'item_extractors/current_time'
-require_relative 'item_extractors/href'
-require_relative 'item_extractors/html'
-require_relative 'item_extractors/static'
-require_relative 'item_extractors/text'
-
module Html2rss
##
# Provides a namespace for item extractors.
module ItemExtractors
- DEFAULT = 'text'.freeze
+ DEFAULT = 'Text'.freeze
def self.get_extractor(name)
- @extractors = Hash.new do |hash, key|
- camel_cased_name = key.split('_').map(&:capitalize).join
+ @get_extractor ||= Hash.new do |extractors, key|
+ camel_cased_name = (key || DEFAULT).split('_').map(&:capitalize).join
class_name = ['Html2rss', 'ItemExtractors', camel_cased_name].join('::')
+ extractors[key] = Object.const_get(class_name)
+ end
- hash[key] = Object.const_get(class_name)
- end[name || DEFAULT]
+ @get_extractor[name]
end
##
# @return [Nokogiri::XML::Element]
def self.element(xml, options)