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.
343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 343 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 end |
Instance Attribute Details
#complete_size ⇒ Object
Returns the value of attribute complete_size.
337 338 339 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 337 def complete_size @complete_size end |
#draw_char ⇒ Object
Returns the value of attribute draw_char.
336 337 338 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 336 def draw_char @draw_char end |
#is_done ⇒ Object
Returns the value of attribute is_done.
341 342 343 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 341 def is_done @is_done end |
#last_update_time ⇒ Object
Returns the value of attribute last_update_time.
339 340 341 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 339 def last_update_time @last_update_time end |
#update_ing_size ⇒ Object
Returns the value of attribute update_ing_size.
340 341 342 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 340 def update_ing_size @update_ing_size end |
#upload_total_size ⇒ Object
Returns the value of attribute upload_total_size.
338 339 340 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 338 def upload_total_size @upload_total_size end |
Instance Method Details
#complete_upload_index(upload_part: nil, complete_size: nil) ⇒ Object
364 365 366 367 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 364 def complete_upload_index(upload_part:nil, complete_size:nil) @complete_size = @complete_size + complete_size @update_ing_size[upload_part] = 0 end |
#delete_upload_index(upload_part: nil) ⇒ Object
360 361 362 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 360 def delete_upload_index(upload_part:nil) @update_ing_size[upload_part] = 0 end |
#update_upload_index(upload_part: nil, upload_size: nil) ⇒ Object
356 357 358 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 356 def update_upload_index(upload_part:nil, upload_size:nil) @update_ing_size[upload_part] = upload_size end |
#update_upload_progress ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/pindo/client/pgyeruploadclient.rb', line 369 def update_upload_progress() time_now = (Time.now.to_f * 1000).to_i #毫秒 if time_now - @last_update_time > 80 @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 |