Sha256: d190ea29e9a3a7c2c8af477455937363814894ff1f30df5be6ca12b2ef515480

Contents?: true

Size: 602 Bytes

Versions: 4

Compression:

Stored size: 602 Bytes

Contents

require 'open-uri'

class GMS
  class Downloader

    attr_accessor :files, :output_dir

    def initialize(files, output_dir="tiles")
      @output_dir = output_dir
      @files = files
    end

    def mkdir?(dir)
      Dir.mkdir(dir) if !Dir.exists?(dir)
    end

    def process
      mkdir?(@output_dir)
      @files.each do |tile|
        mkdir?(File.join(@output_dir,tile[:dir]))
        File.open(File.join(@output_dir,tile[:dir],tile[:file]), 'w+') do |file|
          open(tile[:url], 'rb') do |image|
            file.write(image.read)
          end
        end
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
google-map-stitch-0.1.4 lib/google-map-stitch/downloader.rb
google-map-stitch-0.1.3 lib/google-map-stitch/downloader.rb
google-map-stitch-0.1.2 lib/google-map-stitch/downloader.rb
google-map-stitch-0.1.1 lib/google-map-stitch/downloader.rb