lib/html2rss/item.rb in html2rss-0.6.0 vs lib/html2rss/item.rb in html2rss-0.7.0
- old
+ new
@@ -1,11 +1,8 @@
require 'faraday'
require 'faraday_middleware'
-require 'open-uri'
require 'nokogiri'
-require_relative 'item_extractors'
-require_relative 'attribute_post_processors'
module Html2rss
##
# Takes the selected Nokogiri::HTML and responds to accessors names
# defined in the feed config.
@@ -32,11 +29,11 @@
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']
+ @config.attribute_names) - %w[categories enclosure]
end
##
# At least a title or a description is required to be a valid RSS 2.0 item.
def valid?
@@ -52,17 +49,22 @@
categories.map!(&method(:method_missing))
categories.uniq!
categories.keep_if { |category| category.to_s != '' }
end
+ def enclosure_url
+ enclosure = method_missing(:enclosure)
+ return if enclosure.to_s == ''
+
+ Html2rss::Utils.build_absolute_url_from_relative(enclosure, config.url).to_s
+ end
+
##
# @return [Array]
def self.from_url(url, config)
body = get_body_from_url(url, config)
- Nokogiri::HTML(body).css(config.selector('items')).map do |xml_item|
- new xml_item, config
- end
+ Nokogiri.HTML(body).css(config.selector('items')).map { |xml_item| new xml_item, config }
end
private
def self.get_body_from_url(url, config)