lib/html2rss/item.rb in html2rss-0.10.0 vs lib/html2rss/item.rb in html2rss-0.11.0

- old
+ new

@@ -15,10 +15,25 @@ Context = Struct.new('Context', :options, :item, :config, keyword_init: true) # Class to keep an Item's <enclosure>. Enclosure = Struct.new('Enclosure', :type, :bits_length, :url, keyword_init: true) ## + # Fetches items from a given URL using configuration settings. + # + # @param url [String] URL to fetch items from. + # @param config [Html2rss::Config] Configuration object. + # @return [Array<Html2rss::Item>] list of items fetched. + def self.from_url(url, config) + body = Utils.request_body_from_url(url, convert_json_to_xml: config.json?, headers: config.headers) + + Nokogiri.HTML(body) + .css(config.selector_string(Config::Selectors::ITEMS_SELECTOR_NAME)) + .map { |xml| new(xml, config) } + .select(&:valid?) + end + + ## # @param xml [Nokogiri::XML::Element] # @param config [Html2rss::Config] def initialize(xml, config) @xml = xml @config = config @@ -118,24 +133,9 @@ Enclosure.new( type: Html2rss::Utils.guess_content_type_from_url(url), bits_length: 0, url: url.to_s ) - end - - ## - # Fetches items from a given URL using configuration settings. - # - # @param url [String] URL to fetch items from. - # @param config [Html2rss::Config] Configuration object. - # @return [Array<Html2rss::Item>] list of items fetched. - def self.from_url(url, config) - body = Utils.request_body_from_url(url, convert_json_to_xml: config.json?, headers: config.headers) - - Nokogiri.HTML(body) - .css(config.selector_string(Config::Selectors::ITEMS_SELECTOR_NAME)) - .map { |xml| new(xml, config) } - .select(&:valid?) end private # @return [Nokogiri::XML::Element] XML element representing the item.