Class: Html2rss::AutoSource::Scraper::WordpressApi::PageScope

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb

Overview

Determines whether a WordPress page can safely be mapped to a posts query.

Defined Under Namespace

Classes: Resolver

Constant Summary collapse

CATEGORY_SEGMENT =

Canonical path segment for category archives.

'category'
TAG_SEGMENT =

Canonical path segment for tag archives.

'tag'
AUTHOR_SEGMENT =

Canonical path segment for author archives.

'author'
PAGE_SEGMENT =

Canonical path segment for paginated archives.

'page'
PAGED_QUERY_KEY =

Canonical query key used for paginated archives.

'paged'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, fetchable:, reason:) ⇒ PageScope

Returns a new instance of PageScope.

Parameters:

  • query (Hash{String => String})

    scoped query params for the posts endpoint

  • fetchable (Boolean)

    whether a posts follow-up is safe for this page

  • reason (Symbol)

    classification of the resolved page scope



33
34
35
36
37
38
# File 'lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb', line 33

def initialize(query:, fetchable:, reason:)
  @query = query.freeze
  @fetchable = fetchable
  @reason = reason
  freeze
end

Instance Attribute Details

#queryHash{String => String} (readonly)

Returns query params to apply to the posts request.

Returns:

  • (Hash{String => String})

    query params to apply to the posts request



42
43
44
# File 'lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb', line 42

def query
  @query
end

#reasonSymbol (readonly)

Returns classification of the resolved page scope.

Returns:

  • (Symbol)

    classification of the resolved page scope



52
53
54
# File 'lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb', line 52

def reason
  @reason
end

Class Method Details

.from(parsed_body:, url:) ⇒ PageScope

Returns derived page scope.

Parameters:

  • parsed_body (Nokogiri::HTML::Document)

    parsed HTML document

  • url (Html2rss::Url)

    canonical page URL

Returns:



25
26
27
# File 'lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb', line 25

def self.from(parsed_body:, url:)
  Resolver.new(parsed_body:, url:).call
end

Instance Method Details

#fetchable?Boolean

Returns whether the page may safely use the posts API follow-up.

Returns:

  • (Boolean)

    whether the page may safely use the posts API follow-up



46
47
48
# File 'lib/html2rss/auto_source/scraper/wordpress_api/page_scope.rb', line 46

def fetchable?
  @fetchable
end