Class: Html2rss::FeedPipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_pipeline.rb,
lib/html2rss/feed_pipeline/auto_fallback.rb,
lib/html2rss/feed_pipeline/strategy_plan.rb,
lib/html2rss/feed_pipeline/runtime_policy.rb

Overview

Builds feeds from validated config through request, extraction, and rendering stages.

Defined Under Namespace

Classes: AutoFallback, PipelineOutcome, RuntimePolicy, StrategyPlan

Instance Method Summary collapse

Constructor Details

#initialize(raw_config) ⇒ FeedPipeline

Returns a new instance of FeedPipeline.

Parameters:

  • raw_config (Hash{Symbol => Object})

    user-provided feed config



17
18
19
# File 'lib/html2rss/feed_pipeline.rb', line 17

def initialize(raw_config)
  @raw_config = raw_config
end

Instance Method Details

#deduplicated_articles(config:, response:, request_session:) ⇒ Array(Array<Html2rss::Article>, Integer)

Returns unique articles and drop count.

Parameters:

Returns:



60
61
62
63
64
# File 'lib/html2rss/feed_pipeline.rb', line 60

def deduplicated_articles(config:, response:, request_session:)
  collected = collect_articles(config:, response:, request_session:)
  unique = Article::Deduplicator.new(collected).call
  [unique, collected.size - unique.size]
end

#request_session_for(config, strategy:, resources:) ⇒ Html2rss::RequestSession

Parameters:

Returns:



46
47
48
49
50
51
52
53
# File 'lib/html2rss/feed_pipeline.rb', line 46

def request_session_for(config, strategy:, resources:)
  RequestSession.build(
    config:,
    strategy:,
    budget: resources.budget,
    policy: resources.policy
  )
end

#to_resultHtml2rss::FeedResult

Runs the pipeline once and returns an opaque, Marshal-cacheable result.

rubocop:disable Metrics/AbcSize, Metrics/MethodLength -- Status kwargs stay co-located with Channel



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/html2rss/feed_pipeline.rb', line 26

def to_result
  config = Config.from_hash(raw_config, params: raw_config[:params])
  outcome = pipeline_outcome_for(config)
  channel = Channel.from_response(outcome.response, overrides: config.channel)
  status = Status.build(
    articles: outcome.articles,
    dedup_dropped: outcome.dedup_dropped,
    selected_strategy: outcome.selected_strategy,
    attempt_count: outcome.attempt_count,
    strategy_attempts: outcome.strategy_attempts
  )
  FeedResult.new(channel:, articles: outcome.articles, status:, stylesheets: config.stylesheets)
end