Class: ScrapeUnblocker::ParsedPage
- Inherits:
-
Object
- Object
- ScrapeUnblocker::ParsedPage
- Defined in:
- lib/scrapeunblocker/parsed_page.rb
Overview
Structured data extracted from a page (#get_parsed).
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
The extracted fields.
-
#page_type ⇒ String?
readonly
What the API classified the page as, e.g.
-
#raw ⇒ Hash
readonly
The full JSON payload as returned by the API.
-
#source ⇒ String?
readonly
How the data was extracted.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page_type:, source:, data:, raw:) ⇒ ParsedPage
constructor
A new instance of ParsedPage.
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
#data ⇒ Object (readonly)
Returns the extracted fields.
11 12 13 |
# File 'lib/scrapeunblocker/parsed_page.rb', line 11 def data @data end |
#page_type ⇒ String? (readonly)
Returns 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 |
#raw ⇒ Hash (readonly)
Returns the full JSON payload as returned by the API.
13 14 15 |
# File 'lib/scrapeunblocker/parsed_page.rb', line 13 def raw @raw end |
#source ⇒ String? (readonly)
Returns 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 |