Class: Html2rss::Selectors::Extractors::Attribute
- Inherits:
-
Object
- Object
- Html2rss::Selectors::Extractors::Attribute
- Defined in:
- lib/html2rss/selectors/extractors/attribute.rb
Overview
Returns the value of the attribute.
Imagine this time HTML tag 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, consider parsing it during post processing with PostProcessors::ParseTime.
Defined Under Namespace
Classes: Options
Constant Summary collapse
- OPTION_TYPES =
Config-facing option types (excluding shared selector fields supplied at runtime).
{ attribute: String }.freeze
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Return the value of an HTML attribute on the selected element. ' \ 'Requires sibling selector option `attribute` (attribute name).'
- EXAMPLES =
Example extractor name values for JSON Schema
examples. [ 'attribute' ].freeze
Class Method Summary collapse
-
.schema_doc ⇒ Hash{Symbol => Object}
JSON Schema fragment for this extractor name.
Instance Method Summary collapse
-
#get ⇒ String
Retrieves and returns the attribute's value as a string.
-
#initialize(xml, options) ⇒ Attribute
constructor
Initializes the Attribute extractor.
Constructor Details
#initialize(xml, options) ⇒ Attribute
Initializes the Attribute extractor.
52 53 54 55 |
# File 'lib/html2rss/selectors/extractors/attribute.rb', line 52 def initialize(xml, ) @options = @element = Extractors.element(xml, .selector) end |
Class Method Details
.schema_doc ⇒ Hash{Symbol => Object}
Returns JSON Schema fragment for this extractor name.
43 |
# File 'lib/html2rss/selectors/extractors/attribute.rb', line 43 def self.schema_doc = SchemaDoc.for_extractor(name: :attribute, klass: self) |
Instance Method Details
#get ⇒ String
Retrieves and returns the attribute's value as a string.
61 62 63 |
# File 'lib/html2rss/selectors/extractors/attribute.rb', line 61 def get @element.attr(@options.attribute).to_s end |