Class: FetchUtil::Result

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, final_url:, title:, byline:, excerpt:, site_name:, published_time:, canonical_url:, language:, name:, company:, location:, description:, ingredients:, instructions:, bedrooms:, bathrooms:, area_sqft:, html:, markdown:, metadata:, reader_mode:, content_type:, suspect:, warnings:, content_completeness_ratio: 1.0, content_format: nil, paywall_state: nil, price: nil, rating: nil, address: nil, social_kind: nil, platform: nil, handle: nil, reply_count: nil, community: nil, score: nil, error_message: nil) ⇒ Result

Returns a new instance of Result.



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/fetch_util/result.rb', line 180

def initialize(url:, final_url:, title:, byline:, excerpt:, site_name:, published_time:,
               canonical_url:, language:, name:, company:, location:, description:, ingredients:,
               instructions:, bedrooms:, bathrooms:, area_sqft:, html:, markdown:, metadata:,
               reader_mode:, content_type:, suspect:, warnings:,
               content_completeness_ratio: 1.0, content_format: nil, paywall_state: nil,
               price: nil, rating: nil, address: nil, social_kind: nil, platform: nil,
               handle: nil, reply_count: nil, community: nil, score: 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
  @name = name
  @company = company
  @location = location
  @description = description
  @ingredients = ingredients
  @instructions = instructions
  @bedrooms = bedrooms
  @bathrooms = bathrooms
  @area_sqft = area_sqft
  @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
  @price = price
  @rating = rating
  @address = address
  @social_kind = social_kind
  @platform = platform
  @handle = handle
  @reply_count = reply_count
  @community = community
  @score = score
  @error_message = error_message
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def address
  @address
end

#area_sqftObject (readonly)

Returns the value of attribute area_sqft.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def area_sqft
  @area_sqft
end

#bathroomsObject (readonly)

Returns the value of attribute bathrooms.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def bathrooms
  @bathrooms
end

#bedroomsObject (readonly)

Returns the value of attribute bedrooms.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def bedrooms
  @bedrooms
end

#bylineObject (readonly)

Returns the value of attribute byline.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def 
  @byline
end

#canonical_urlObject (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

#communityObject (readonly)

Returns the value of attribute community.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def community
  @community
end

#companyObject (readonly)

Returns the value of attribute company.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def company
  @company
end

#content_completeness_ratioObject (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_formatObject (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_typeObject (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

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def description
  @description
end

#error_messageObject (readonly)

Returns the value of attribute error_message.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def error_message
  @error_message
end

#excerptObject (readonly)

Returns the value of attribute excerpt.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def excerpt
  @excerpt
end

#final_urlObject (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

#handleObject (readonly)

Returns the value of attribute handle.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def handle
  @handle
end

#htmlObject (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def html
  @html
end

#ingredientsObject (readonly)

Returns the value of attribute ingredients.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def ingredients
  @ingredients
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def instructions
  @instructions
end

#languageObject (readonly)

Returns the value of attribute language.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def language
  @language
end

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def location
  @location
end

#markdownObject (readonly)

Returns the value of attribute markdown.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def markdown
  @markdown
end

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def name
  @name
end

#paywall_stateObject (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

#platformObject (readonly)

Returns the value of attribute platform.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def platform
  @platform
end

#priceObject (readonly)

Returns the value of attribute price.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def price
  @price
end

#published_timeObject (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

#ratingObject (readonly)

Returns the value of attribute rating.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def rating
  @rating
end

#reader_modeObject (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

#reply_countObject (readonly)

Returns the value of attribute reply_count.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def reply_count
  @reply_count
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def score
  @score
end

#site_nameObject (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

#social_kindObject (readonly)

Returns the value of attribute social_kind.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def social_kind
  @social_kind
end

#suspectObject (readonly)

Returns the value of attribute suspect.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def suspect
  @suspect
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/fetch_util/result.rb', line 5

def url
  @url
end

#warningsObject (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



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/fetch_util/result.rb', line 90

def error(url:, warning:, message:)
   = {
    content_url: url,
    content_type: "error",
    suspect: true,
    warnings: [warning],
    error_message: message,
    social_kind: nil,
    platform: nil,
    handle: nil,
    reply_count: nil,
    community: nil,
    score: nil
  }.freeze

  new(
    url: url,
    final_url: url,
    title: nil,
    byline: nil,
    excerpt: nil,
    site_name: nil,
    published_time: nil,
    canonical_url: nil,
    language: nil,
    name: nil,
    company: nil,
    location: nil,
    description: nil,
    ingredients: nil,
    instructions: nil,
    bedrooms: nil,
    bathrooms: nil,
    area_sqft: nil,
    html: nil,
    markdown: "",
    metadata: ,
    reader_mode: nil,
    content_type: "error",
    suspect: true,
    warnings: [warning],
    error_message: message
  )
end

.from_payload(url:, final_url:, payload:, canonical_url:, content_type:, warnings:, suspect:) ⇒ Object



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
50
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
80
81
82
83
84
85
86
87
88
# File 'lib/fetch_util/result.rb', line 15

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,
    name: payload["name"],
    company: payload["company"],
    location: payload["location"],
    description: payload["description"],
    ingredients: payload["ingredients"],
    instructions: payload["instructions"],
    bedrooms: payload["bedrooms"],
    bathrooms: payload["bathrooms"],
    area_sqft: payload["areaSqft"],
    price: payload["price"],
    rating: payload["rating"],
    address: payload["address"],
    social_kind: payload["socialKind"],
    platform: payload["platform"],
    handle: payload["handle"],
    reply_count: payload["replyCount"],
    community: payload["community"],
    score: payload["score"]
  )

  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"],
    name: payload["name"],
    company: payload["company"],
    location: payload["location"],
    description: payload["description"],
    ingredients: payload["ingredients"],
    instructions: payload["instructions"],
    bedrooms: payload["bedrooms"],
    bathrooms: payload["bathrooms"],
    area_sqft: payload["areaSqft"],
    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,
    price: payload["price"],
    rating: payload["rating"],
    address: payload["address"],
    social_kind: payload["socialKind"],
    platform: payload["platform"],
    handle: payload["handle"],
    reply_count: payload["replyCount"],
    community: payload["community"],
    score: payload["score"]
  )
end

Instance Method Details

#to_hObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/fetch_util/result.rb', line 227

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,
    name: name,
    company: company,
    location: location,
    description: description,
    ingredients: ingredients,
    instructions: instructions,
    bedrooms: bedrooms,
    bathrooms: bathrooms,
    area_sqft: area_sqft,
    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,
    price: price,
    rating: rating,
    address: address,
    social_kind: social_kind,
    platform: platform,
    handle: handle,
    reply_count: reply_count,
    community: community,
    score: score,
    error_message: error_message
  }
end