Class: Html2rss::AutoSource::Discovery::SemanticAnchorCandidates::Context

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

Overview

Shared context for all anchors in one semantic container.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, link_heuristics:) ⇒ Context

Returns a new instance of Context.

Parameters:



44
45
46
47
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 44

def initialize(container, link_heuristics:)
  @container = container
  @link_heuristics = link_heuristics
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



40
41
42
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 40

def container
  @container
end

Returns the value of attribute link_heuristics.



40
41
42
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 40

def link_heuristics
  @link_heuristics
end

Instance Method Details

#destination_facts(anchor) ⇒ Html2rss::AutoSource::LinkHeuristics::DestinationFacts?

Returns destination facts.

Parameters:

  • anchor (Nokogiri::XML::Node)

    anchor candidate

Returns:



69
70
71
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 69

def destination_facts(anchor)
  @link_heuristics.destination_facts(anchor)
end

#headingNokogiri::XML::Node?

Returns heading used to identify title anchors.

Returns:

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

    heading used to identify title anchors



50
51
52
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 50

def heading
  @heading ||= @container.at_css(Html2rss::Html::Navigator::HEADING_TAGS.join(','))
end

#heading_textString

Returns visible heading text.

Returns:

  • (String)

    visible heading text



55
56
57
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 55

def heading_text
  @heading_text ||= visible_text(heading)
end

#visible_text(node) ⇒ String

Returns visible text for the node.

Parameters:

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

    node to extract text from

Returns:

  • (String)

    visible text for the node



61
62
63
64
65
# File 'lib/html2rss/auto_source/discovery/semantic_anchor_candidates.rb', line 61

def visible_text(node)
  return '' unless node

  (@visible_texts ||= {}.compare_by_identity)[node] ||= Html2rss::Html::Navigator.extract_visible_text(node).to_s.strip
end