Class: Html2rss::ItemExtractors::Attribute
- Inherits:
-
Object
- Object
- Html2rss::ItemExtractors::Attribute
- 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
- #get ⇒ String
-
#initialize(xml, options) ⇒ Attribute
constructor
A new instance of Attribute.
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 = @element = ItemExtractors.element(xml, ) end |
Instance Method Details
#get ⇒ String
32 33 34 |
# File 'lib/html2rss/item_extractors/attribute.rb', line 32 def get @element.attr(@options['attribute']).to_s end |