lib/fontist/downloader.rb in fontist-0.2.0 vs lib/fontist/downloader.rb in fontist-0.3.0
- old
+ new
@@ -1,13 +1,14 @@
require "down"
require "digest"
module Fontist
class Downloader
- def initialize(file, file_size: nil, sha: nil)
+ def initialize(file, file_size: nil, sha: nil, progress: nil)
@sha = sha
@file = file
+ @progress = progress
@file_size = file_size || default_file_size
end
def download
file = download_file
@@ -17,11 +18,11 @@
def verify_file_checksum(file)
file if Digest::SHA256.file(file) === sha
end
def raise_invalid_file
- raise(Fontist::Error, "Invalid / Tempared file")
+ raise(Fontist::Errors::TemparedFileError)
end
def self.download(file, options = {})
new(file, options).download
end
@@ -46,10 +47,10 @@
bar = ProgressBar.new(file_size / byte_to_megabyte)
Down.download(
@file,
progress_proc: -> (progress) {
- bar.increment(progress / byte_to_megabyte)
+ bar.increment(progress / byte_to_megabyte) if @progress === true
}
)
end
end