spinner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/VERSION +1 -0
  2. data/lib/spinner.rb +44 -0
  3. metadata +65 -0
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,44 @@
1
+ module Spinner
2
+ class << self
3
+
4
+ def with_spinner opts={}, &blk
5
+ count = opts[:count] || nil
6
+ message = opts[:message] || "Working..."
7
+
8
+ current = 0
9
+ shown = build_string message, current, count
10
+ printf shown
11
+
12
+ spin = Proc.new do
13
+ clear shown
14
+ current += 1
15
+ shown = build_string message, current, count
16
+ printf shown
17
+ end
18
+
19
+ yield spin
20
+
21
+ clear shown
22
+ printf " " * shown.length
23
+ clear shown
24
+ end
25
+
26
+ private
27
+
28
+ def clear str
29
+ printf "\b" * str.length
30
+ end
31
+
32
+ def build_string message, current, total
33
+ char = %w{/ - \\ |}[current % 4]
34
+ str = "#{char} #{message}"
35
+
36
+ if total
37
+ percent = current * 100.0 / total
38
+ str += sprintf " %3.2f%%", percent
39
+ end
40
+
41
+ str
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spinner
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Ross Andrews
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-21 23:48:19.654676 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ Display an animated spinner on the console during long-running processes in your app, with a percentage completed.
23
+
24
+ email: randrews@geekfu.org
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - VERSION
33
+ - lib/spinner.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/randrews/spinner
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project: spinner
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Display an animated spinner during long-running processes
64
+ test_files: []
65
+