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:, 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 = error_message
end

Instance Attribute Details

#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

#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

#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

#htmlObject (readonly)

Returns the value of attribute html.



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

def html
  @html
end

#languageObject (readonly)

Returns the value of attribute language.



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

def language
  @language
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

#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

#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

#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

#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

#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



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: 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: 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_hObject



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: error_message
  }
end