Class: Shoes::Download
Instance Attribute Summary collapse
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(app, name, args, &blk) ⇒ Download
constructor
A new instance of Download.
- #started? ⇒ Boolean
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_length ⇒ Object (readonly)
Returns the value of attribute content_length.
18 19 20 |
# File 'lib/shoes/download.rb', line 18 def content_length @content_length end |
#progress ⇒ Object (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
24 25 26 |
# File 'lib/shoes/download.rb', line 24 def finished? @finished end |
#started? ⇒ Boolean
20 21 22 |
# File 'lib/shoes/download.rb', line 20 def started? @started end |