Class: Html2rss::Capture

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

Overview

Analyzes a URL and produces a reusable feed config hash with derived CSS selectors.

Uses the auto-source pipeline to extract articles, then traces back through SST segments to build items + attribute selectors suitable for a static feed config.

Defined Under Namespace

Classes: CaptureResult

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, strategy: :auto, **options) ⇒ Capture

Returns a new instance of Capture.

Parameters:

  • url (String)

    source page URL

  • strategy (Symbol) (defaults to: :auto)

    request strategy

  • options (Hash)

    additional options

Options Hash (**options):

  • :items_selector (String, nil)

    optional selector hint

  • :max_redirects (Integer, nil)

    optional redirect limit override

  • :max_requests (Integer, nil)

    optional request budget override

  • :limit (Integer, nil)

    max articles to keep

  • :local_file_path (String, nil)

    optional local HTML file path



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

def initialize(url, strategy: :auto, **options)
  @url = url
  @strategy = strategy
  @items_selector_hint = options.delete(:items_selector)
  @max_redirects = options.delete(:max_redirects)
  @max_requests = options.delete(:max_requests)
  @limit = options.delete(:limit)
  @local_file_path = options.delete(:local_file_path)
end

Class Method Details

.build(url, strategy: :auto) ⇒ CaptureResult

Analyzes a URL and builds a reusable feed config.

Parameters:

  • url (String)

    source page URL

  • strategy (Symbol) (defaults to: :auto)

    request strategy (+:auto+, :faraday, :botasaurus)

  • options (Hash)

    a customizable set of options

Returns:



32
33
34
# File 'lib/html2rss/capture.rb', line 32

def build(url, strategy: :auto, **)
  new(url, strategy:, **).build
end

Instance Method Details

#buildCaptureResult

Runs the capture pipeline.

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/html2rss/capture.rb', line 60

def build # rubocop:disable Metrics/MethodLength
  response = fetch_response
  articles = extract_articles(response)
  selectors = derive_selectors(response, articles)

  config = {
    channel: build_channel(response),
    selectors: selectors.empty? ? nil : selectors,
    **local_file_request_overlay
  }.compact

  CaptureResult.new(
    config:,
    articles_count: articles.size,
    channel_title: channel_title_from(response)
  )
end