Sha256: 8048db0cb7c9d23eeef2631ffc4d8505bfb3af844392c92addcd4a5018bec492

Contents?: true

Size: 926 Bytes

Versions: 9

Compression:

Stored size: 926 Bytes

Contents

module Html2rss
  module ItemExtractors
    ##
    # Returns the value of the attribute.
    #
    # Imagine this +time+ HTML element with a +datetime+ attribute:
    #
    #     <time datetime="2019-07-01">...</time>
    #
    # YAML usage example:
    #
    #    selectors:
    #      link:
    #        selector: time
    #        extractor: attribute
    #        attribute: datetime
    #
    # Would return:
    #    '2019-07-01'
    #
    # In case you're extracting a date or a time, do not forget to parse it
    # during post processing with
    # {AttributePostProcessors::ParseTime}[rdoc-ref:Html2rss::AttributePostProcessors::ParseTime].
    class Attribute
      def initialize(xml, options)
        @options = options
        @element = ItemExtractors.element(xml, options)
      end

      ##
      # @return [String]
      def get
        @element.attr(@options['attribute']).to_s
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
html2rss-0.8.1 lib/html2rss/item_extractors/attribute.rb
html2rss-0.8.0 lib/html2rss/item_extractors/attribute.rb
html2rss-0.7.0 lib/html2rss/item_extractors/attribute.rb
html2rss-0.6.0 lib/html2rss/item_extractors/attribute.rb
html2rss-0.5.2 lib/html2rss/item_extractors/attribute.rb
html2rss-0.5.1 lib/html2rss/item_extractors/attribute.rb
html2rss-0.5.0 lib/html2rss/item_extractors/attribute.rb
html2rss-0.4.1 lib/html2rss/item_extractors/attribute.rb
html2rss-0.4.0 lib/html2rss/item_extractors/attribute.rb