Class: Indicator::Spin
- Inherits:
-
Object
- Object
- Indicator::Spin
- Defined in:
- lib/indicator/spin.rb
Instance Attribute Summary collapse
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#post ⇒ Object
Returns the value of attribute post.
-
#pre ⇒ Object
Returns the value of attribute pre.
Instance Method Summary collapse
- #clean ⇒ Object
- #inc ⇒ Object
- #init ⇒ Object
-
#initialize(opts = {}) ⇒ Spin
constructor
A new instance of Spin.
- #spin ⇒ Object
- #spinning ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Spin
Returns a new instance of Spin.
6 7 8 9 10 11 12 13 |
# File 'lib/indicator/spin.rb', line 6 def initialize opts={} @frames = opts[:frames] || %w{ | / - \\ } @delay = opts[:delay] || 0.1 @pre = opts[:pre] || '' @post = opts[:post] || '' @count = opts[:count] || nil init end |
Instance Attribute Details
#delay ⇒ Object
Returns the value of attribute delay.
4 5 6 |
# File 'lib/indicator/spin.rb', line 4 def delay @delay end |
#post ⇒ Object
Returns the value of attribute post.
4 5 6 |
# File 'lib/indicator/spin.rb', line 4 def post @post end |
#pre ⇒ Object
Returns the value of attribute pre.
4 5 6 |
# File 'lib/indicator/spin.rb', line 4 def pre @pre end |
Instance Method Details
#clean ⇒ Object
36 37 38 |
# File 'lib/indicator/spin.rb', line 36 def clean printf "\b" * @spin.length if @spin.length > 0 end |
#inc ⇒ Object
21 22 23 |
# File 'lib/indicator/spin.rb', line 21 def inc @current += 1 end |
#init ⇒ Object
15 16 17 18 19 |
# File 'lib/indicator/spin.rb', line 15 def init @current = 0 @spin = '' printf @spin end |
#spin ⇒ Object
30 31 32 33 34 |
# File 'lib/indicator/spin.rb', line 30 def spin clean build printf @spin end |
#spinning ⇒ Object
25 26 27 28 |
# File 'lib/indicator/spin.rb', line 25 def spinning spin sleep @delay if @delay end |