Module: Html2rss::AutoSource::Segmenter::List

Defined in:
lib/html2rss/auto_source/segmenter/list.rb

Overview

Builds repeated-list article segments from tag_path frequency (port of Discovery::ListCandidates using tag_path instead of xpath).

Class Method Summary collapse

Class Method Details

.call(segmenter) ⇒ Array<Segment>

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/html2rss/auto_source/segmenter/list.rb', line 15

def call(segmenter)
  primary = PrimaryLink.new(segmenter)
  pairs = article_pairs(segmenter)
  seen = {}.compare_by_identity

  pairs.each_with_index.filter_map do |(, selected_anchor), position|
    next unless seen[].nil?

    seen[] = true

    link = selected_anchor || primary.select()
    next unless link || segmenter.permit_unanchored

    Segment.build(root_node: , primary_link: link, strategy: :list, position:)
  end
end