Sha256: 76c95596a839bf5b08a57ad2d23601c4e7d70c2f50b5630d523dccb613050379

Contents?: true

Size: 558 Bytes

Versions: 1

Compression:

Stored size: 558 Bytes

Contents

# frozen_string_literal: true

require "down"
require "uri"

module Miteru
  class Downloader
    attr_reader :url, :base_dir
    def initialize(url, base_dir = "/tmp")
      @url = url
      @base_dir = base_dir
    end

    def filename
      uri = URI.parse(url)
      File.basename(uri.path)
    end

    def destination
      @destination ||= "#{base_dir}/#{filename}"
    end

    def download
      Down.download(url, destination: destination)
    end

    def self.download(url, base_dir = "/tmp")
      new(url, base_dir).download
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
miteru-0.3.0 lib/miteru/downloader.rb