Class: Shoes::Download

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Download.


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

def initialize 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]
      blk[sio] if blk
      @finished = true
    end
  end
end

Instance Attribute Details

#content_lengthObject (readonly)

Returns the value of attribute content_length


16
17
18
# File 'lib/shoes/download.rb', line 16

def content_length
  @content_length
end

#progressObject (readonly)

Returns the value of attribute progress


16
17
18
# File 'lib/shoes/download.rb', line 16

def progress
  @progress
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/shoes/download.rb', line 22

def finished?
  @finished
end

#started?Boolean

Returns:

  • (Boolean)

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

def started?
  @started
end