class FileGrabber::DownloadedDocument
Public Class Methods
new(filename)
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 3 def initialize filename @filename = filename end
Public Instance Methods
download() { || ... }
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 7 def download clean_if_failed if already_downloaded? Log.info "Skipping #{@filename} because already downloaded." else Log.info "DOWNLOAD START: #{@filename}" File.open @filename, 'wb' do |file| file << yield end sleep 2 end self end
download_failed?()
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 25 def download_failed? if !File.exist? @filename false else File.zero?(@filename) || File.size(@filename) < 1_000 end end
size()
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 21 def size File.size(@filename) end
Private Instance Methods
already_downloaded?()
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 39 def already_downloaded? File.exist? @filename end
clean_if_failed()
click to toggle source
# File lib/filegrabber/downloaded_document.rb, line 35 def clean_if_failed File.delete @filename if download_failed? end