lib/html2rss/item.rb in html2rss-0.5.0 vs lib/html2rss/item.rb in html2rss-0.5.1
- old
+ new
@@ -13,29 +13,34 @@
end
private_class_method :new
def respond_to_missing?(method_name, _include_private = false)
- config.attribute_names.include?(method_name) || super
+ config.attribute?(method_name) || super
end
def method_missing(method_name, *_args)
- attribute_config = config.options(method_name.to_s)
- return super unless attribute_config
+ return super unless respond_to_missing?(method_name)
- extractor = ItemExtractors.get_extractor(attribute_config['extractor'])
- value = extractor.new(xml, attribute_config).get
+ attribute_options = config.attribute_options(method_name)
- post_process(value, attribute_config.fetch('post_process', false))
+ extractor = ItemExtractors.get_extractor(attribute_options['extractor'])
+ value = extractor.new(xml, attribute_options).get
+
+ post_process(value, attribute_options.fetch('post_process', false))
end
def available_attributes
@available_attributes ||= (%w[title link description author comments updated] &
@config.attribute_names) - ['categories']
end
+ ##
+ # At least a title or a description is required to be a valid RSS 2.0 item.
def valid?
- [title.to_s, description.to_s].join('') != ''
+ title = self.title if config.attribute?(:title)
+ description = self.description if config.attribute?(:description)
+ [title, description].join != ''
end
##
# @return [Array]
def categories