lib/html2rss/item.rb in html2rss-0.12.0 vs lib/html2rss/item.rb in html2rss-0.13.0
- old
+ new
@@ -21,11 +21,12 @@
#
# @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)
+ body = Utils.request_url(url, headers: config.headers).body
+ body = ObjectToXmlConverter.new(JSON.parse(body)).call if config.json?
Nokogiri.HTML(body)
.css(config.selector_string(Config::Selectors::ITEMS_SELECTOR_NAME))
.map { |xml| new(xml, config) }
.select(&:valid?)
@@ -45,10 +46,11 @@
# Checks if the object responds to a method dynamically based on the configuration.
#
# @param method_name [Symbol]
# @param _include_private [true, false]
# @return [true, false]
+ # :reek:BooleanParameter { enabled: false }
def respond_to_missing?(method_name, _include_private = false)
config.selector?(method_name) || super
end
##
@@ -108,10 +110,14 @@
##
# Retrieves categories for the item based on configured category selectors.
#
# @return [Array<String>] list of categories.
def categories
- config.category_selector_names.map { |method_name| public_send(method_name) }
+ config.category_selector_names
+ .filter_map do |method_name|
+ category = public_send(method_name)
+ category.strip unless category.to_s.empty?
+ end.uniq
end
##
# Checks if the item has an enclosure based on configuration.
#