Module: Html2rss::Selectors::Extractors
- Defined in:
- lib/html2rss/selectors/extractors.rb,
lib/html2rss/selectors/extractors/href.rb,
lib/html2rss/selectors/extractors/html.rb,
lib/html2rss/selectors/extractors/text.rb,
lib/html2rss/selectors/extractors/static.rb,
lib/html2rss/selectors/extractors/attribute.rb
Overview
Provides a namespace for item extractors.
Defined Under Namespace
Classes: Attribute, Href, Html, Static, Text
Constant Summary collapse
- NAME_TO_CLASS =
Maps the extractor name to the class implementing the extractor.
The key is the name to use in the feed config.
{ attribute: Attribute, href: Href, html: Html, static: Static, text: Text }.freeze
- ITEM_OPTION_CLASSES =
Maps the extractor class to its corresponding options class.
Hash.new do |hash, klass| hash[klass] = klass.const_get(:Options) end
- DEFAULT_EXTRACTOR =
Extractor used when none is explicitly configured.
:text
Class Method Summary collapse
-
.element(xml, selector) ⇒ Nokogiri::XML::ElementSet
Retrieves an element from Nokogiri XML based on the selector.
-
.get(attribute_options, xml) ⇒ Object
Instance of the specified item extractor class.
Class Method Details
.element(xml, selector) ⇒ Nokogiri::XML::ElementSet
Retrieves an element from Nokogiri XML based on the selector.
36 37 38 |
# File 'lib/html2rss/selectors/extractors.rb', line 36 def element(xml, selector) selector ? xml.css(selector) : xml end |
.get(attribute_options, xml) ⇒ Object
Returns instance of the specified item extractor class.
44 45 46 47 48 49 |
# File 'lib/html2rss/selectors/extractors.rb', line 44 def get(, xml) extractor_class = NAME_TO_CLASS[[:extractor]&.to_sym || DEFAULT_EXTRACTOR] = ITEM_OPTION_CLASSES[extractor_class].new(.slice(*extractor_class::Options.members)) extractor_class.new(xml, ).get end |