Class: FetchUtil::Result
- Inherits:
-
Object
- Object
- FetchUtil::Result
- Defined in:
- lib/fetch_util/result.rb
Instance Attribute Summary collapse
-
#byline ⇒ Object
readonly
Returns the value of attribute byline.
-
#canonical_url ⇒ Object
readonly
Returns the value of attribute canonical_url.
-
#content_completeness_ratio ⇒ Object
readonly
Returns the value of attribute content_completeness_ratio.
-
#content_format ⇒ Object
readonly
Returns the value of attribute content_format.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#excerpt ⇒ Object
readonly
Returns the value of attribute excerpt.
-
#final_url ⇒ Object
readonly
Returns the value of attribute final_url.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#markdown ⇒ Object
readonly
Returns the value of attribute markdown.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#paywall_state ⇒ Object
readonly
Returns the value of attribute paywall_state.
-
#published_time ⇒ Object
readonly
Returns the value of attribute published_time.
-
#reader_mode ⇒ Object
readonly
Returns the value of attribute reader_mode.
-
#site_name ⇒ Object
readonly
Returns the value of attribute site_name.
-
#suspect ⇒ Object
readonly
Returns the value of attribute suspect.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
- .error(url:, warning:, message:) ⇒ Object
- .from_payload(url:, final_url:, payload:, canonical_url:, content_type:, warnings:, suspect:) ⇒ Object
Instance Method Summary collapse
-
#initialize(url:, final_url:, title:, byline:, excerpt:, site_name:, published_time:, canonical_url:, language:, html:, markdown:, metadata:, reader_mode:, content_type:, suspect:, warnings:, content_completeness_ratio: 1.0, content_format: nil, paywall_state: nil, error_message: nil) ⇒ Result
constructor
A new instance of Result.
- #to_h ⇒ Object
Constructor Details
#initialize(url:, final_url:, title:, byline:, excerpt:, site_name:, published_time:, canonical_url:, language:, html:, markdown:, metadata:, reader_mode:, content_type:, suspect:, warnings:, content_completeness_ratio: 1.0, content_format: nil, paywall_state: nil, error_message: nil) ⇒ Result
Returns a new instance of Result.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fetch_util/result.rb', line 105 def initialize(url:, final_url:, title:, byline:, excerpt:, site_name:, published_time:, canonical_url:, language:, html:, markdown:, metadata:, reader_mode:, content_type:, suspect:, warnings:, content_completeness_ratio: 1.0, content_format: nil, paywall_state: nil, error_message: nil) @url = url @final_url = final_url @title = title @byline = @excerpt = excerpt @site_name = site_name @published_time = published_time @canonical_url = canonical_url @language = language @html = html @markdown = markdown @metadata = .freeze @reader_mode = reader_mode @content_type = content_type @suspect = suspect @warnings = warnings.freeze @content_completeness_ratio = content_completeness_ratio @content_format = content_format&.freeze @paywall_state = paywall_state&.freeze @error_message = end |
Instance Attribute Details
#byline ⇒ Object (readonly)
Returns the value of attribute byline.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def @byline end |
#canonical_url ⇒ Object (readonly)
Returns the value of attribute canonical_url.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def canonical_url @canonical_url end |
#content_completeness_ratio ⇒ Object (readonly)
Returns the value of attribute content_completeness_ratio.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def content_completeness_ratio @content_completeness_ratio end |
#content_format ⇒ Object (readonly)
Returns the value of attribute content_format.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def content_format @content_format end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def content_type @content_type end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def @error_message end |
#excerpt ⇒ Object (readonly)
Returns the value of attribute excerpt.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def excerpt @excerpt end |
#final_url ⇒ Object (readonly)
Returns the value of attribute final_url.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def final_url @final_url end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def html @html end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def language @language end |
#markdown ⇒ Object (readonly)
Returns the value of attribute markdown.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def markdown @markdown end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def @metadata end |
#paywall_state ⇒ Object (readonly)
Returns the value of attribute paywall_state.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def paywall_state @paywall_state end |
#published_time ⇒ Object (readonly)
Returns the value of attribute published_time.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def published_time @published_time end |
#reader_mode ⇒ Object (readonly)
Returns the value of attribute reader_mode.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def reader_mode @reader_mode end |
#site_name ⇒ Object (readonly)
Returns the value of attribute site_name.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def site_name @site_name end |
#suspect ⇒ Object (readonly)
Returns the value of attribute suspect.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def suspect @suspect end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def url @url end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
5 6 7 |
# File 'lib/fetch_util/result.rb', line 5 def warnings @warnings end |
Class Method Details
.error(url:, warning:, message:) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fetch_util/result.rb', line 51 def error(url:, warning:, message:) = { content_url: url, content_type: "error", suspect: true, warnings: [warning], error_message: }.freeze new( url: url, final_url: url, title: nil, byline: nil, excerpt: nil, site_name: nil, published_time: nil, canonical_url: nil, language: nil, html: nil, markdown: "", metadata: , reader_mode: nil, content_type: "error", suspect: true, warnings: [warning], error_message: ) end |
.from_payload(url:, final_url:, payload:, canonical_url:, content_type:, warnings:, suspect:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fetch_util/result.rb', line 12 def from_payload(url:, final_url:, payload:, canonical_url:, content_type:, warnings:, suspect:) content_completeness_ratio = payload["contentCompletenessRatio"]&.to_f || 1.0 content_format = payload["contentFormat"] paywall_state = payload["paywallState"] = ( payload, canonical_url: canonical_url, final_url: final_url, content_type: content_type, suspect: suspect, warnings: warnings, content_completeness_ratio: content_completeness_ratio, content_format: content_format, paywall_state: paywall_state ) new( url: url, final_url: final_url, title: payload["title"], byline: payload["byline"], excerpt: payload["excerpt"], site_name: payload["siteName"], published_time: payload["publishedTime"], canonical_url: canonical_url, language: payload["language"], html: payload["html"], markdown: payload["markdown"], metadata: , reader_mode: payload["readerMode"], content_type: content_type, suspect: suspect, warnings: warnings, content_completeness_ratio: content_completeness_ratio, content_format: content_format, paywall_state: paywall_state ) end |
Instance Method Details
#to_h ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fetch_util/result.rb', line 130 def to_h { url: url, final_url: final_url, title: title, byline: , excerpt: excerpt, site_name: site_name, published_time: published_time, canonical_url: canonical_url, language: language, html: html, markdown: markdown, metadata: , reader_mode: reader_mode, content_type: content_type, suspect: suspect, warnings: warnings, content_completeness_ratio: content_completeness_ratio, content_format: content_format, paywall_state: paywall_state, error_message: } end |