module ImageWgetErrors
Constants
- STYLE_TITLE
Public Instance Methods
Source
# File lib/image_wget_errors.rb, line 12 def format_download_error(url:, reason:, trace: nil) lines = [ IrcFormat.report_header(tag: "WGET", title: "download failed", style: STYLE_TITLE), reason.to_s.strip ] if trace&.any? lines << IrcFormat.divider("fetch trace") trace.each_with_index do |step, index| lines << format_trace_step(index + 1, step) end end footer = GoogleDriveUrl.google_drive_url?(url) ? "google drive" : "wget" lines << IrcFormat.report_footer(footer) lines.join("\n") end
Source
# File lib/image_wget_errors.rb, line 30 def format_trace_step(number, step) kind = step[:kind].to_s bytes = step[:bytes].to_i size_label = bytes.positive? ? "#{bytes} bytes" : "0 bytes" snippet = step[:snippet].to_s.strip host = trace_host(step[:url]) detail = [host, kind, size_label] detail << snippet unless snippet.empty? "Step #{number} ยท #{detail.join(' ยท ')}" end
Source
# File lib/image_wget_errors.rb, line 41 def trace_host(url) uri = URI.parse(url.to_s) path = uri.path.to_s path = path[0, 24] if path.length > 24 host = uri.host.to_s host = "#{host}#{path}" unless path.empty? || path == "/" host rescue URI::InvalidURIError url.to_s[0, 48] end