Class: Html2rss::Selectors::Extractors::Href
- Inherits:
-
Object
- Object
- Html2rss::Selectors::Extractors::Href
- Defined in:
- lib/html2rss/selectors/extractors/href.rb
Overview
Returns the value of the href attribute.
It always returns absolute URLs. If the extracted href value is a
relative URL, it prepends the channel's URL.
Imagine this a HTML element with a href attribute:
<a href="/posts/latest-findings">...</a>
YAML usage example:
channel:
url: http://blog-without-a-feed.example.com
...
selectors:
link:
selector: a
extractor: href
Would return:
'http://blog-without-a-feed.example.com/posts/latest-findings'
Defined Under Namespace
Classes: Options
Constant Summary collapse
- DESCRIPTION =
JSON Schema description exported via
schema_doc. 'Return the absolute URL from the selected element\'s `href` attribute ' \ '(relative hrefs are resolved against the channel URL).'
- EXAMPLES =
Example extractor name values for JSON Schema
examples. [ 'href' ].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 normalized absolute URL.
-
#initialize(xml, options) ⇒ Href
constructor
Initializes the Href extractor.
Constructor Details
#initialize(xml, options) ⇒ Href
Initializes the Href extractor.
49 50 51 52 53 |
# File 'lib/html2rss/selectors/extractors/href.rb', line 49 def initialize(xml, ) @options = @element = Extractors.element(xml, .selector) @href = @element.attr('href').to_s end |
Class Method Details
.schema_doc ⇒ Hash{Symbol => Object}
Returns JSON Schema fragment for this extractor name.
40 |
# File 'lib/html2rss/selectors/extractors/href.rb', line 40 def self.schema_doc = SchemaDoc.for_extractor(name: :href, klass: self) |
Instance Method Details
#get ⇒ String
Retrieves and returns the normalized absolute URL.
59 60 61 62 63 |
# File 'lib/html2rss/selectors/extractors/href.rb', line 59 def get return nil unless @href Url.from_relative(@href, @options.channel[:url]) end |