Module: Html2rss::Html::CardWalk

Defined in:
lib/html2rss/html/card_walk.rb

Overview

Leftover parent-card walk policy shared by Nokogiri and SST extractors. Adapters traverse; this module decides miss / thin wrapper / crowded abort. Keep/drop stays on ArticleRules::Description. Capture's selector lift is a separate job (set-aware abort) and is not encoded here.

Class Method Summary collapse

Class Method Details

.crowded?(heading_count:, distinct_main_hrefs:) ⇒ Boolean

Returns true when the parent looks like a listing, not one card.

Parameters:

  • heading_count (Integer)

    headings inside the candidate parent

  • distinct_main_hrefs (Integer)

    unique eligible main-article hrefs

Returns:

  • (Boolean)

    true when the parent looks like a listing, not one card



36
37
38
# File 'lib/html2rss/html/card_walk.rb', line 36

def crowded?(heading_count:, distinct_main_hrefs:)
  heading_count > 1 || distinct_main_hrefs > 1
end

.miss?(heading_or_anchor_item:, published_at:, description:) ⇒ Boolean

Returns whether to climb to a parent card.

Parameters:

  • heading_or_anchor_item (Boolean)

    true when the extract root is a heading or wrapping a

  • published_at (Object, nil)
  • description (String, nil)

    leftover description after Description keep/drop

Returns:

  • (Boolean)

    whether to climb to a parent card



17
18
19
# File 'lib/html2rss/html/card_walk.rb', line 17

def miss?(heading_or_anchor_item:, published_at:, description:)
  heading_or_anchor_item && published_at.nil? && description.nil?
end

.thin_wrapper?(children:, item:, descendant_of:) ⇒ Boolean

Returns true when the parent only wraps the item (no sibling content).

Parameters:

  • children (Enumerable)

    immediate children of the candidate parent

  • item (Object)

    heading/anchor being extracted

  • descendant_of (Proc)

    (item, child) — whether item sits inside child

Returns:

  • (Boolean)

    true when the parent only wraps the item (no sibling content)



26
27
28
29
30
# File 'lib/html2rss/html/card_walk.rb', line 26

def thin_wrapper?(children:, item:, descendant_of:)
  children.none? do |child|
    !child.equal?(item) && !descendant_of.call(item, child)
  end
end