# frozen_string_literal: true module Html2rss module ItemExtractors ## # Return the text content of the attribute. This is the default extractor used, # when no extractor is explicitly given. # # Example HTML structure: # #

Lorem ipsum dolor ...

# # YAML usage example: # # selectors: # description: # selector: p # extractor: text # # Would return: # 'Lorem ipsum dolor ...' class Text # The available options for the text extractor. Options = Struct.new('TextOptions', :selector, keyword_init: true) ## # Initializes the Text extractor. # # @param xml [Nokogiri::XML::Element] # @param options [Options] def initialize(xml, options) @element = ItemExtractors.element(xml, options.selector) end ## # Retrieves and returns the text content of the element. # # @return [String] The text content. def get @element.text.to_s.strip.gsub(/\s+/, ' ') end end end end