Class: Shoes::Download

Inherits:
Object show all
Defined in:
lib/shoes/download.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, name, args, &blk) ⇒ Download

Returns a new instance of Download.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/shoes/download.rb', line 3

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 10, args[:repaint] do
    (a.stop; blk[@sio]) if @finished
  end if blk
end

Instance Attribute Details

#content_lengthObject (readonly)

Returns the value of attribute content_length.



18
19
20
# File 'lib/shoes/download.rb', line 18

def content_length
  @content_length
end

#progressObject (readonly)

Returns the value of attribute progress.



18
19
20
# File 'lib/shoes/download.rb', line 18

def progress
  @progress
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/shoes/download.rb', line 24

def finished?
  @finished
end

#started?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/shoes/download.rb', line 20

def started?
  @started
end