Class: Html2rss::AutoSource::Discovery::SemanticAnchorCandidates::Context
- Inherits:
-
Object
- Object
- Html2rss::AutoSource::Discovery::SemanticAnchorCandidates::Context
- 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
-
#container ⇒ Object
readonly
Returns the value of attribute container.
-
#link_heuristics ⇒ Object
readonly
Returns the value of attribute link_heuristics.
Instance Method Summary collapse
-
#destination_facts(anchor) ⇒ Html2rss::AutoSource::LinkHeuristics::DestinationFacts?
Destination facts.
-
#heading ⇒ Nokogiri::XML::Node?
Heading used to identify title anchors.
-
#heading_text ⇒ String
Visible heading text.
-
#initialize(container, link_heuristics:) ⇒ Context
constructor
A new instance of Context.
-
#visible_text(node) ⇒ String
Visible text for the node.
Constructor Details
#initialize(container, link_heuristics:) ⇒ Context
Returns a new instance of Context.
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
#container ⇒ Object (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 |
#link_heuristics ⇒ Object (readonly)
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.
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 |
#heading ⇒ Nokogiri::XML::Node?
Returns 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_text ⇒ String
Returns 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.
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 |