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(name, args, &blk) ⇒ Download
constructor
A new instance of Download.
- #started? ⇒ Boolean
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_length ⇒ Object (readonly)
Returns the value of attribute content_length.
16 17 18 |
# File 'lib/shoes/download.rb', line 16 def content_length @content_length end |
#progress ⇒ Object (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
22 23 24 |
# File 'lib/shoes/download.rb', line 22 def finished? @finished end |
#started? ⇒ Boolean
18 19 20 |
# File 'lib/shoes/download.rb', line 18 def started? @started end |