Class: Pindo::PgyerUploadClient::PgyerUploadProgressBar
- Inherits:
-
Object
- Object
- Pindo::PgyerUploadClient::PgyerUploadProgressBar
- Defined in:
- lib/pindo/client/pgyeruploadclient.rb
Instance Attribute Summary collapse
-
#complete_size ⇒ Object
Returns the value of attribute complete_size.
-
#draw_char ⇒ Object
Returns the value of attribute draw_char.
-
#is_done ⇒ Object
Returns the value of attribute is_done.
-
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
-
#update_ing_size ⇒ Object
Returns the value of attribute update_ing_size.
-
#upload_total_size ⇒ Object
Returns the value of attribute upload_total_size.
Instance Method Summary collapse
- #complete_upload_index(upload_part: nil, complete_size: nil) ⇒ Object
- #delete_upload_index(upload_part: nil) ⇒ Object
-
#initialize(upload_total_size: nil, draw_char: '>') ⇒ PgyerUploadProgressBar
constructor
A new instance of PgyerUploadProgressBar.
- #update_upload_index(upload_part: nil, upload_size: nil) ⇒ Object
- #update_upload_progress ⇒ Object
Constructor Details
#initialize(upload_total_size: nil, draw_char: '>') ⇒ PgyerUploadProgressBar
Returns a new instance of PgyerUploadProgressBar.
457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 457 def initialize(upload_total_size:nil, draw_char:'>') @upload_total_size = upload_total_size @draw_char = draw_char @last_update_time = (Time.now.to_f * 1000).to_i #毫秒 @complete_size = 0 @update_ing_size = {} @is_done = false # 添加互斥锁来保护进度条更新 @mutex = Mutex.new end |
Instance Attribute Details
#complete_size ⇒ Object
Returns the value of attribute complete_size.
451 452 453 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 451 def complete_size @complete_size end |
#draw_char ⇒ Object
Returns the value of attribute draw_char.
450 451 452 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 450 def draw_char @draw_char end |
#is_done ⇒ Object
Returns the value of attribute is_done.
455 456 457 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 455 def is_done @is_done end |
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
453 454 455 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 453 def last_update_time @last_update_time end |
#update_ing_size ⇒ Object
Returns the value of attribute update_ing_size.
454 455 456 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 454 def update_ing_size @update_ing_size end |
#upload_total_size ⇒ Object
Returns the value of attribute upload_total_size.
452 453 454 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 452 def upload_total_size @upload_total_size end |
Instance Method Details
#complete_upload_index(upload_part: nil, complete_size: nil) ⇒ Object
482 483 484 485 486 487 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 482 def complete_upload_index(upload_part:nil, complete_size:nil) @mutex.synchronize do @complete_size = @complete_size + complete_size @update_ing_size[upload_part] = 0 end end |
#delete_upload_index(upload_part: nil) ⇒ Object
476 477 478 479 480 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 476 def delete_upload_index(upload_part:nil) @mutex.synchronize do @update_ing_size[upload_part] = 0 end end |
#update_upload_index(upload_part: nil, upload_size: nil) ⇒ Object
470 471 472 473 474 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 470 def update_upload_index(upload_part:nil, upload_size:nil) @mutex.synchronize do @update_ing_size[upload_part] = upload_size end end |
#update_upload_progress ⇒ Object
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 489 def update_upload_progress() time_now = (Time.now.to_f * 1000).to_i #毫秒 if time_now - @last_update_time > 80 @mutex.synchronize do @last_update_time = time_now total_num = @upload_total_size index_num = @complete_size @update_ing_size.each do |key, value| index_num = index_num + value end progress_str = sprintf("%.2f", 100.0 * index_num / total_num ) total_size = sprintf("%.2f", 1.00 * total_num / 1024 /1024 ) upload_size = sprintf("%.2f", 1.00 * index_num / 1024 /1024 ) index = 40.0 * index_num / total_num = "已上传:#{upload_size}MB|#{progress_str}\%【" + (@draw_char * (index/1).floor).ljust(40.0, '_') + "】Total:#{total_size}MB" Funlog.instance.() if index_num == total_num && !@is_done @is_done = true Funlog.instance.() end end end end |