Class: Html2rss::Scoring::Score

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

Overview

Composite score with quality/junk split and optional typed feature breakdown.

Constant Summary collapse

EMPTY_BREAKDOWN =

Shared empty feature breakdown for scores without per-feature tallies.

{}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#breakdownObject (readonly)

Returns the value of attribute breakdown

Returns:

  • (Object)

    the current value of breakdown



7
8
9
# File 'lib/html2rss/scoring/score.rb', line 7

def breakdown
  @breakdown
end

#compositeObject (readonly)

Returns the value of attribute composite

Returns:

  • (Object)

    the current value of composite



7
8
9
# File 'lib/html2rss/scoring/score.rb', line 7

def composite
  @composite
end

#junkObject (readonly)

Returns the value of attribute junk

Returns:

  • (Object)

    the current value of junk



7
8
9
# File 'lib/html2rss/scoring/score.rb', line 7

def junk
  @junk
end

#qualityObject (readonly)

Returns the value of attribute quality

Returns:

  • (Object)

    the current value of quality



7
8
9
# File 'lib/html2rss/scoring/score.rb', line 7

def quality
  @quality
end

Class Method Details

.build(composite:, quality: nil, junk: nil, breakdown: nil) ⇒ Score

Parameters:

  • composite (Numeric)
  • quality (Numeric, nil) (defaults to: nil)
  • junk (Numeric, nil) (defaults to: nil)
  • breakdown (Hash{Symbol => Numeric}, nil) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)

    when composite is not numeric



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/html2rss/scoring/score.rb', line 15

def self.build(composite:, quality: nil, junk: nil, breakdown: nil)
  raise ArgumentError, 'composite must be Numeric' unless composite.is_a?(Numeric)

  parts = breakdown.nil? ? Score::EMPTY_BREAKDOWN : breakdown.transform_keys { FeatureId.assert!(_1) }.freeze
  new(
    composite: composite.to_f,
    quality: (quality.nil? ? composite : quality).to_f,
    junk: (junk || 0).to_f,
    breakdown: parts
  )
end