Class: Html2rss::HtmlExtractor::IdGenerator

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

Overview

IdGenerator determines the unique ID for an article container node.

Class Method Summary collapse

Class Method Details

.call(article_tag, heading:, url:, selected_anchor:, fallback_anchorless:) ⇒ String?

Returns the generated ID, if any.

Parameters:

  • article_tag (Nokogiri::XML::Element)

    container node

  • heading (Nokogiri::XML::Node, nil)

    heading node

  • url (Html2rss::Url, nil)

    absolute article URL

  • selected_anchor (Nokogiri::XML::Node, nil)

    anchor element

  • fallback_anchorless (Boolean)

    whether to use fallback hashing

Returns:

  • (String, nil)

    the generated ID, if any



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/html2rss/html_extractor/id_generator.rb', line 18

def call(, heading:, url:, selected_anchor:, fallback_anchorless:)
  id_from_dom = parse_id_from_dom(, url, selected_anchor)
  return id_from_dom if id_from_dom

  heading_text = resolve_heading_text(, heading, fallback_anchorless)
  if heading_text && !heading_text.strip.empty?
    generate_slug(heading_text)
  elsif fallback_anchorless
    generate_content_hash()
  end
end