Sha256: 26ccd22d912e85f71f135221f8efea8d1fee398e8602a4046ff6a201eba5bb44

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

require "open-uri"
require "fileutils"

module Unicoder
  module Downloader
    def self.fetch(identifier,
        unicode_version: CURRENT_UNICODE_VERSION,
        destination_directory: LOCAL_DATA_DIRECTORY,
        destination: nil,
        filename: nil
      )
      filename = UNICODE_FILES[identifier.to_sym] || filename
      raise ArgumentError, "No valid file identifier or filename given" if !filename
      filename.sub! 'VERSION', unicode_version
      source = UNICODE_DATA_ENDPOINT + filename
      destination ||= destination_directory + filename

      open(source){ |f|
        FileUtils.mkdir_p(File.dirname(destination))
        File.write(destination, f.read)
      }

      puts "GET #{source} => #{destination}"
    rescue => e
      $stderr.puts "#{e.class}: #{e.message}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicoder-0.1.0 lib/unicoder/downloader.rb