Class: Html2rss::ItemExtractors::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/item_extractors/attribute.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(xml, options) ⇒ Attribute

Returns a new instance of Attribute



25
26
27
28
# File 'lib/html2rss/item_extractors/attribute.rb', line 25

def initialize(xml, options)
  @options = options
  @element = ItemExtractors.element(xml, options)
end

Instance Method Details

#getString

Returns:

  • (String)


32
33
34
# File 'lib/html2rss/item_extractors/attribute.rb', line 32

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