lib/html2rss/config/selectors.rb in html2rss-0.11.0 vs lib/html2rss/config/selectors.rb in html2rss-0.12.0

- old
+ new

@@ -8,10 +8,13 @@ ITEMS_SELECTOR_NAME = :items # Struct to represent a selector with associated attributes for extraction and processing. Selector = Struct.new(:selector, :attribute, :extractor, :post_process, :order, :static, keyword_init: true) + # raised when an invalid selector name is used + class InvalidSelectorName < Html2rss::Error; end + ## # @param config [Hash<Symbol, Object>] def initialize(config) validate_config(config) @config = config @@ -26,13 +29,19 @@ ## # @param name [Symbol] # @return [Selector] def selector(name) - raise ArgumentError, "invalid item's selector name: #{name}" unless selector?(name) + raise InvalidSelectorName, "invalid selector name: #{name}" unless selector?(name) - Selector.new(config[name]) + keywords = config[name].slice(*available_keys) + + if (additional_keys = available_keys - keywords.keys).any? + warn "additional keys (#{additional_keys.join(', ')}) present in selector #{name}" + end + + Selector.new(keywords) end ## # @return [Set<Symbol>] def category_selector_names @@ -84,8 +93,10 @@ config.fetch(name) { Array(default) }.tap do |array| array.reject! { |entry| entry.to_s == '' } array.map!(&:to_sym) end.to_set end + + def available_keys = @available_keys ||= Selector.members end end end