Class: Indicator::Spin

Inherits:
Object
  • Object
show all
Defined in:
lib/indicator/spin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#delayObject

Returns the value of attribute delay.



4
5
6
# File 'lib/indicator/spin.rb', line 4

def delay
  @delay
end

#postObject

Returns the value of attribute post.



4
5
6
# File 'lib/indicator/spin.rb', line 4

def post
  @post
end

#preObject

Returns the value of attribute pre.



4
5
6
# File 'lib/indicator/spin.rb', line 4

def pre
  @pre
end

Instance Method Details

#cleanObject



36
37
38
# File 'lib/indicator/spin.rb', line 36

def clean
  printf "\b" * @spin.length if @spin.length > 0
end

#incObject



21
22
23
# File 'lib/indicator/spin.rb', line 21

def inc
  @current += 1
end

#initObject



15
16
17
18
19
# File 'lib/indicator/spin.rb', line 15

def init
  @current = 0
  @spin = ''
 printf @spin
end

#spinObject



30
31
32
33
34
# File 'lib/indicator/spin.rb', line 30

def spin
  clean
  build
  printf @spin
end

#spinningObject



25
26
27
28
# File 'lib/indicator/spin.rb', line 25

def spinning
   spin
  sleep @delay if @delay
end