Class: Webpipe::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/webpipe/types.rb

Overview

Result of scraping a single page (scrape / browser / crawl data item). metadata is a plain Hash — the API adds extra keys (og:*, sourceURL, ...).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markdown: nil, html: nil, raw_html: nil, links: nil, metadata: nil, json: nil) ⇒ Document

Returns a new instance of Document.



16
17
18
19
20
21
22
23
# File 'lib/webpipe/types.rb', line 16

def initialize(markdown: nil, html: nil, raw_html: nil, links: nil, metadata: nil, json: nil)
  @markdown = markdown
  @html = html
  @raw_html = raw_html
  @links = links
  @metadata = 
  @json = json
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def html
  @html
end

#jsonObject (readonly)

Returns the value of attribute json.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def json
  @json
end

Returns the value of attribute links.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def links
  @links
end

#markdownObject (readonly)

Returns the value of attribute markdown.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def markdown
  @markdown
end

#metadataObject (readonly)

Returns the value of attribute metadata.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def 
  @metadata
end

#raw_htmlObject (readonly)

Returns the value of attribute raw_html.



14
15
16
# File 'lib/webpipe/types.rb', line 14

def raw_html
  @raw_html
end

Class Method Details

.from_hash(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/webpipe/types.rb', line 25

def self.from_hash(hash)
  hash ||= {}
  new(
    markdown: hash["markdown"],
    html: hash["html"],
    raw_html: hash["rawHtml"],
    links: hash["links"]&.map { |l| Link.from_hash(l) },
    metadata: hash["metadata"],
    json: hash["json"]
  )
end