Module: Html2rss::FeedResolution::Scorer

Defined in:
lib/html2rss/feed_resolution/scorer.rb

Overview

Scores probe targets and picks winners from cheap PageRecon::Assessment facts or syndication item counts.

Constant Summary collapse

ARTICLE_WEIGHT =

Weight for admitted article counts on HTML probes.

10
LISTING_SURFACE_BONUS =

Bonus when the surface looks like a listing rather than a hub/shell.

5

Class Method Summary collapse

Class Method Details

.pick_winner(scored:, entry_articles_count:) ⇒ Probe::Scored?

Parameters:

Returns:



39
40
41
42
43
44
45
46
# File 'lib/html2rss/feed_resolution/scorer.rb', line 39

def pick_winner(scored:, entry_articles_count:)
  winner = scored.max_by(&:score)
  return unless winner
  return if winner.articles_count <= entry_articles_count.to_i
  return if winner.score <= 0

  winner
end

.score_assessment(assessment) ⇒ Integer

Parameters:

Returns:

  • (Integer)


26
27
28
29
30
31
32
33
# File 'lib/html2rss/feed_resolution/scorer.rb', line 26

def score_assessment(assessment)
  score = assessment.articles_count * ARTICLE_WEIGHT
  score += LISTING_SURFACE_BONUS if assessment.listing_bonus?
  drops = assessment.admission_drops.values.sum
  total = assessment.articles_count + drops
  score -= ((drops.to_f / total) * ARTICLE_WEIGHT).round if total.positive?
  score
end

.score_feed(articles_count:) ⇒ Integer

Parameters:

  • articles_count (Integer)

Returns:

  • (Integer)


19
20
21
# File 'lib/html2rss/feed_resolution/scorer.rb', line 19

def score_feed(articles_count:)
  articles_count.to_i * ARTICLE_WEIGHT
end