Class: RubyCrawl::Result
- Inherits:
-
Object
- Object
- RubyCrawl::Result
- Defined in:
- lib/rubycrawl/result.rb
Overview
Result object with lazy markdown conversion.
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#final_url ⇒ String?
The final URL after redirects.
-
#initialize(text:, html:, links:, metadata:, markdown: nil) ⇒ Result
constructor
A new instance of Result.
-
#markdown ⇒ String
Returns markdown, converting from HTML lazily if needed.
-
#markdown? ⇒ Boolean
Check if markdown has been computed.
- #to_h ⇒ Object
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
#html ⇒ Object (readonly)
Returns the value of attribute html.
6 7 8 |
# File 'lib/rubycrawl/result.rb', line 6 def html @html end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
6 7 8 |
# File 'lib/rubycrawl/result.rb', line 6 def links @links end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/rubycrawl/result.rb', line 6 def end |
#text ⇒ Object (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_url ⇒ String?
The final URL after redirects.
27 28 29 |
# File 'lib/rubycrawl/result.rb', line 27 def final_url ['final_url'] || [:final_url] end |
#markdown ⇒ String
Returns markdown, converting from HTML lazily if needed. Relative URLs are resolved using the page’s final_url.
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.
34 35 36 |
# File 'lib/rubycrawl/result.rb', line 34 def markdown? !@markdown.nil? end |
#to_h ⇒ Object
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 |