Class: ScrapeUnblocker::ParsedPage

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapeunblocker/parsed_page.rb

Overview

Structured data extracted from a page (#get_parsed).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_type:, source:, data:, raw:) ⇒ ParsedPage

Returns a new instance of ParsedPage.



15
16
17
18
19
20
# File 'lib/scrapeunblocker/parsed_page.rb', line 15

def initialize(page_type:, source:, data:, raw:)
  @page_type = page_type
  @source = source
  @data = data
  @raw = raw
end

Instance Attribute Details

#dataObject (readonly)

Returns the extracted fields.

Returns:

  • the extracted fields



11
12
13
# File 'lib/scrapeunblocker/parsed_page.rb', line 11

def data
  @data
end

#page_typeString? (readonly)

Returns what the API classified the page as, e.g. "product".

Returns:

  • (String, nil)

    what the API classified the page as, e.g. "product"



7
8
9
# File 'lib/scrapeunblocker/parsed_page.rb', line 7

def page_type
  @page_type
end

#rawHash (readonly)

Returns the full JSON payload as returned by the API.

Returns:

  • (Hash)

    the full JSON payload as returned by the API



13
14
15
# File 'lib/scrapeunblocker/parsed_page.rb', line 13

def raw
  @raw
end

#sourceString? (readonly)

Returns how the data was extracted.

Returns:

  • (String, nil)

    how the data was extracted



9
10
11
# File 'lib/scrapeunblocker/parsed_page.rb', line 9

def source
  @source
end

Class Method Details

.from_hash(payload) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/scrapeunblocker/parsed_page.rb', line 22

def self.from_hash(payload)
  inner = payload["data"].is_a?(Hash) ? payload["data"] : payload
  new(
    page_type: inner["page_type"],
    source: inner["source"],
    data: inner["data"],
    raw: payload
  )
end