rbsync 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/rbsync.rb +50 -0
  3. data/rbsync.gemspec +1 -1
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/lib/rbsync.rb CHANGED
@@ -329,6 +329,56 @@ class RbSync
329
329
  alias newer= updated_file_only=
330
330
  end
331
331
 
332
+ # ==プログレスバーを表示する.
333
+ # prg= ProgressBar.new
334
+ # prg.show_percent = true
335
+ # prg.size = 60
336
+ # prg.start("downloading\n")
337
+ # 100.times{|i|
338
+ # prg.progress(i, "#{i}/100")
339
+ # sleep 0.015
340
+ # }
341
+ # prg.end("done")
342
+ class ProgressBar
343
+ attr_accessor :size, :out, :bar_char_undone, :bar_char_done, :show_percent
344
+ def initialize()
345
+ @out = $stdout
346
+ @size = 11
347
+ @bar_char_undone = "_"
348
+ @bar_char_done = "#"
349
+ @show_percent = true
350
+ @printend_max_size = @size
351
+ end
352
+ def start(message="")
353
+ out.print message
354
+ out.print bar_char_undone * size
355
+ out.flush
356
+ end
357
+ def end(message="")
358
+ progress(100)
359
+ out.print " " + message
360
+ out.puts ""
361
+ out.flush
362
+ end
363
+ def clear()
364
+ out.print "\r"
365
+ line_size = [@printend_max_size, @size].max
366
+ out.print " " * line_size
367
+ out.flush
368
+ end
369
+ def progress(percent,message=nil)
370
+ clear()
371
+ str =""
372
+ str << "\r"
373
+ str << bar_char_done * ((percent.to_f/100.to_f)*size).to_i
374
+ str << bar_char_undone * (size - ((percent.to_f/100.to_f)*size).to_i)
375
+ str << " " + percent.to_s + "%" if show_percent
376
+ str << " " + message if message
377
+ @printend_max_size = str.size if str.size > @printend_max_size
378
+ out.print str
379
+ out.flush
380
+ end
381
+ end
332
382
 
333
383
  #require 'tmpdir'
334
384
  #require 'find'
data/rbsync.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rbsync}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["takuya"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbsync
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - takuya