Class: Html2rss::HtmlExtractor::SemanticAnchorCandidates

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/html_extractor/semantic_anchor_candidates.rb

Overview

Builds ranked anchor facts for one semantic content container.

Defined Under Namespace

Classes: AnchorFacts, Candidate, Context, DestinationWinners, Score

Instance Method Summary collapse

Constructor Details

#initialize(container, link_heuristics:) ⇒ SemanticAnchorCandidates

Returns a new instance of SemanticAnchorCandidates.

Parameters:



235
236
237
238
# File 'lib/html2rss/html_extractor/semantic_anchor_candidates.rb', line 235

def initialize(container, link_heuristics:)
  @container = container
  @context = Context.new(container, link_heuristics:)
end

Instance Method Details

#to_aArray<AnchorFacts>

Returns strongest candidate per destination.

Returns:

  • (Array<AnchorFacts>)

    strongest candidate per destination



241
242
243
244
245
# File 'lib/html2rss/html_extractor/semantic_anchor_candidates.rb', line 241

def to_a
  @container.css(HtmlExtractor::MAIN_ANCHOR_SELECTOR)
            .each_with_object(DestinationWinners.new) { |anchor, winners| add_anchor(anchor, winners) }
            .to_a
end