Sha256: 12580aa1afb1f06c064a760e7ff3a678f4d94148c085b07da582229504c1c44e

Contents?: true

Size: 686 Bytes

Versions: 2

Compression:

Stored size: 686 Bytes

Contents

class Shoes
  class Download
    def initialize app, name, args, &blk
      require 'open-uri'
      Thread.new do
        open name,
          content_length_proc: lambda{|len| @content_length, @started = len, true},
          progress_proc: lambda{|size| @progress = size} do |sio|
          open(args[:save], 'wb'){|fw| fw.print sio.read} if args[:save]
          @finished, @sio = true, sio
        end
      end
      a = app.animate do
        (a.stop; blk[@sio]) if @finished
      end if blk
    end
    
    attr_reader :progress, :content_length
    
    def started?
      @started
    end
    
    def finished?
      @finished
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
purple_shoes-0.6.153 lib/shoes/download.rb
purple_shoes-0.5.149 lib/shoes/download.rb