Class: Purple::Getter::Getter_curl
- Defined in:
- lib/purple/getter_curl.rb
Instance Attribute Summary
Attributes inherited from Generic
#content_type, #length, #thread, #uri
Instance Method Summary collapse
- #get ⇒ Object
- #get_status ⇒ Object
-
#initialize(*args) ⇒ Getter_curl
constructor
A new instance of Getter_curl.
-
#parse_input(pw, pr, pe) ⇒ Object
curl specific methods.
Constructor Details
#initialize(*args) ⇒ Getter_curl
Returns a new instance of Getter_curl.
6 7 8 9 |
# File 'lib/purple/getter_curl.rb', line 6 def initialize *args super @done = "0" end |
Instance Method Details
#get ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/purple/getter_curl.rb', line 11 def get @thread = Thread.new do filename = File.basename uri.path Open3.popen3 "curl -o '#{@destdir}/#{filename}' #{@uri.to_s}" do |pw, pr, pe| parse_input pw, pr, pe end end end |
#get_status ⇒ Object
21 22 23 |
# File 'lib/purple/getter_curl.rb', line 21 def get_status [@status, @done] end |
#parse_input(pw, pr, pe) ⇒ Object
curl specific methods
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/purple/getter_curl.rb', line 27 def parse_input pw, pr, pe puts "DEBUG Getter_curl#parse_input: Start" if $DEBUG # Start line 2.times { pe.gets } # Data incoming while line = pe.read(79) puts "->#{line.inspect}" if $DEBUG break if line.size < 79 # % Total % Received % Xferd AverageDload SpeedUpload # TimeTotal Current Left Speed Current md = / (...) (......) (...) (.....) (...) (...) (.....) (......) (........) (........) (........) (.....)/.match line if md @done = md[1] @rate = md[7] end if "100" == @done @status = "Done" end end pe.read puts "DEBUG Getter_curl#parse_input: Done" if $DEBUG end |