Class: Html2rss::AutoSource::Scraper::LinkHeuristics::HrefExtractor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(anchor_or_href) ⇒ HrefExtractor

Returns a new instance of HrefExtractor.

Parameters:

  • anchor_or_href (Nokogiri::XML::Element, String, #to_s)

    anchor element or href-like value



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.

Parameters:

  • anchor_or_href (Nokogiri::XML::Element, String, #to_s)

    anchor element or href-like value

Returns:

  • (String, nil)

    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

#callString?

Returns href without fragment, or nil when blank.

Returns:

  • (String, nil)

    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