Class: Html2rss::Scoring::LinkResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/scoring/link_resolver.rb

Overview

Resolves href strings into memoized LinkDestination::DestinationFacts for one page base URL.

Constant Summary collapse

HREF_BASE_PATTERN =

Captures the href portion before a fragment for memoization keys.

/\A([^#]*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url) ⇒ LinkResolver

Returns a new instance of LinkResolver.

Parameters:



12
13
14
15
16
17
# File 'lib/html2rss/scoring/link_resolver.rb', line 12

def initialize(base_url)
  @base_url = base_url
  @by_href = {}
  @by_node = {}.compare_by_identity
  @text_classifier = LinkDestination::TextClassifier.new
end

Instance Attribute Details

#text_classifierLinkDestination::TextClassifier (readonly)



20
21
22
# File 'lib/html2rss/scoring/link_resolver.rb', line 20

def text_classifier
  @text_classifier
end

Instance Method Details

#destination_facts(node_or_href) ⇒ LinkDestination::DestinationFacts?

Parameters:

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/html2rss/scoring/link_resolver.rb', line 25

def destination_facts(node_or_href)
  return @by_node[node_or_href] if node_or_href.is_a?(SST::Node) && @by_node.key?(node_or_href)

  href = extract_href(node_or_href)
  return unless href

  facts = (@by_href[href] ||= build_facts(href))
  @by_node[node_or_href] = facts if node_or_href.is_a?(SST::Node)
  facts
rescue ArgumentError
  nil
end

Parameters:

  • text (String, #to_s)

Returns:

  • (Boolean)


51
# File 'lib/html2rss/scoring/link_resolver.rb', line 51

def recommended_text?(text) = @text_classifier.recommended?(text)

#utility_prefix_text?(text) ⇒ Boolean

Parameters:

  • text (String, #to_s)

Returns:

  • (Boolean)


46
# File 'lib/html2rss/scoring/link_resolver.rb', line 46

def utility_prefix_text?(text) = @text_classifier.utility_prefix?(text)

#utility_text?(text) ⇒ Boolean

Parameters:

  • text (String, #to_s)

Returns:

  • (Boolean)


41
# File 'lib/html2rss/scoring/link_resolver.rb', line 41

def utility_text?(text) = @text_classifier.utility?(text)