wdd-ruby-ext 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.4.0
@@ -0,0 +1,59 @@
1
+ # This Spinner class is CLI progress meter.
2
+ #
3
+ # To use it, instantiate a spinner and specify the total number of
4
+ # iterations to complete the job.
5
+ #
6
+ # Then call update on the spinner at the end of each iteration of work.
7
+ #
8
+ module WDD
9
+ module Utils
10
+ class Spinner
11
+ private
12
+
13
+ @work
14
+ @job
15
+
16
+ def spinner
17
+ return(['\\','|','/','-'][@spinner_index%4])
18
+ end
19
+
20
+ public
21
+
22
+ # refresh_iterations is how many iterations to wait betwee recalculating the velocity
23
+ # display_iterations is how many iterations to wait between display updates
24
+ def initialize max_iterations, job="Working", refresh_iterations=100, display_iterations=10
25
+ $stdout.sync = true
26
+ @max_iterations = max_iterations
27
+ @job = job
28
+ @i = 0
29
+ @spinner_index = 0
30
+ @delta_count = 0
31
+ @start_time = Time.now
32
+ @eta_string = ""
33
+ @average = 0.0
34
+ @refresh_iterations = refresh_iterations
35
+ @display_iterations = display_iterations
36
+ end
37
+
38
+ def update
39
+ @i += 1
40
+ @delta_count += 1
41
+ fraction = (@i.to_f/@max_iterations)
42
+ if @i % @refresh_iterations == 0
43
+ now = Time.now
44
+ delta_time = now-@start_time
45
+ time_per_iteration = delta_time.to_f / @delta_count
46
+ x = (@max_iterations-@i) * time_per_iteration
47
+ @eta_string = "#{(x.to_i/60).to_i} mins #{x.to_i%60} secs "
48
+ @delta_count=0
49
+ @start_time = Time.now
50
+ @average = @refresh_iterations.to_f / delta_time
51
+ end
52
+ if @i % @display_iterations == 0 || @i == @max_iterations
53
+ printf("\r#{@job}: %s %3.2f%s (#{@i}/#{@max_iterations}) AVG: %3.2f/s Time Left: %s",spinner,(fraction)*100,"%",@average, @eta_string)
54
+ @spinner_index += 1
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -6,4 +6,5 @@ require 'wdd-ruby-ext/utils/hash_object'
6
6
  require 'wdd-ruby-ext/utils/helpers'
7
7
  require 'wdd-ruby-ext/utils/fixed_point'
8
8
  require 'wdd-ruby-ext/utils/pretty_xml'
9
- require 'wdd-ruby-ext/utils/test_server'
9
+ require 'wdd-ruby-ext/utils/test_server'
10
+ require 'wdd-ruby-ext/utils/spinner'
data/wdd-ruby-ext.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wdd-ruby-ext}
8
- s.version = "0.3.3"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["shock"]
12
- s.date = %q{2011-02-13}
12
+ s.date = %q{2011-03-27}
13
13
  s.description = %q{Some of these are borrowed. Some are original. This gem simply provides a single place to source control them all for incorporation into other projects.}
14
14
  s.email = %q{billdoughty@capitalthought.com}
15
15
  s.extra_rdoc_files = [
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "lib/wdd-ruby-ext/utils/helpers.rb",
43
43
  "lib/wdd-ruby-ext/utils/pretty_xml.rb",
44
44
  "lib/wdd-ruby-ext/utils/simpledebug.rb",
45
+ "lib/wdd-ruby-ext/utils/spinner.rb",
45
46
  "lib/wdd-ruby-ext/utils/test_server.rb",
46
47
  "lib/wdd-ruby-ext/utils/time_gate.rb",
47
48
  "spec/lib/utils/fixed_point_spec.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wdd-ruby-ext
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - shock
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-13 00:00:00 -06:00
18
+ date: 2011-03-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -85,6 +85,7 @@ files:
85
85
  - lib/wdd-ruby-ext/utils/helpers.rb
86
86
  - lib/wdd-ruby-ext/utils/pretty_xml.rb
87
87
  - lib/wdd-ruby-ext/utils/simpledebug.rb
88
+ - lib/wdd-ruby-ext/utils/spinner.rb
88
89
  - lib/wdd-ruby-ext/utils/test_server.rb
89
90
  - lib/wdd-ruby-ext/utils/time_gate.rb
90
91
  - spec/lib/utils/fixed_point_spec.rb