Class: RubyCrawl::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycrawl/result.rb

Overview

Result object with lazy markdown conversion.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:, html:, links:, metadata:, markdown: nil) ⇒ Result

Returns a new instance of Result.



8
9
10
11
12
13
14
# File 'lib/rubycrawl/result.rb', line 8

def initialize(text:, html:, links:, metadata:, markdown: nil)
  @text = text
  @html = html
  @links = links
   = 
  @markdown = markdown unless markdown.to_s.empty?
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



6
7
8
# File 'lib/rubycrawl/result.rb', line 6

def html
  @html
end

Returns the value of attribute links.



6
7
8
# File 'lib/rubycrawl/result.rb', line 6

def links
  @links
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/rubycrawl/result.rb', line 6

def 
  
end

#textObject (readonly)

Returns the value of attribute text.



6
7
8
# File 'lib/rubycrawl/result.rb', line 6

def text
  @text
end

Instance Method Details

#final_urlString?

The final URL after redirects.

Returns:

  • (String, nil)


27
28
29
# File 'lib/rubycrawl/result.rb', line 27

def final_url
  ['final_url'] || [:final_url]
end

#markdownString

Returns markdown, converting from HTML lazily if needed. Relative URLs are resolved using the page’s final_url.

Returns:

  • (String)

    Markdown content with absolute URLs



20
21
22
# File 'lib/rubycrawl/result.rb', line 20

def markdown
  @markdown ||= MarkdownConverter.convert(html, base_url: final_url)
end

#markdown?Boolean

Check if markdown has been computed.

Returns:

  • (Boolean)


34
35
36
# File 'lib/rubycrawl/result.rb', line 34

def markdown?
  !@markdown.nil?
end

#to_hObject



38
39
40
41
42
43
44
45
46
# File 'lib/rubycrawl/result.rb', line 38

def to_h
  {
    text: text,
    html: html,
    links: links,
    metadata: ,
    markdown: markdown
  }
end