Class: Html2rss::AutoSource::Scraper::LinkHeuristics::HrefExtractor
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Scraper::LinkHeuristics::HrefExtractor
- Defined in:
- lib/html2rss/auto_source/scraper/link_heuristics.rb
Overview
Extracts a normalized href from a Nokogiri anchor or raw href value.
Class Method Summary collapse
-
.call(anchor_or_href) ⇒ String?
Href without fragment, or nil when blank.
Instance Method Summary collapse
-
#call ⇒ String?
Href without fragment, or nil when blank.
-
#initialize(anchor_or_href) ⇒ HrefExtractor
constructor
A new instance of HrefExtractor.
Constructor Details
#initialize(anchor_or_href) ⇒ HrefExtractor
Returns a new instance of HrefExtractor.
45 46 47 |
# File 'lib/html2rss/auto_source/scraper/link_heuristics.rb', line 45 def initialize(anchor_or_href) @anchor_or_href = anchor_or_href end |
Class Method Details
.call(anchor_or_href) ⇒ String?
Returns href without fragment, or nil when blank.
42 |
# File 'lib/html2rss/auto_source/scraper/link_heuristics.rb', line 42 def self.call(anchor_or_href) = new(anchor_or_href).call |
Instance Method Details
#call ⇒ String?
Returns href without fragment, or nil when blank.
50 51 52 53 54 |
# File 'lib/html2rss/auto_source/scraper/link_heuristics.rb', line 50 def call raw_href.to_s.split('#', 2).first.to_s.strip.then do |href| href unless href.empty? end end |