Class: Starlined::Animation
- Inherits:
-
Object
- Object
- Starlined::Animation
- Defined in:
- lib/starlined/animation.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#current_steps ⇒ Object
readonly
Returns the value of attribute current_steps.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #add_alias(aka) ⇒ Object
- #elapsed_time ⇒ Object
- #increment_step ⇒ Object
-
#initialize(message = 'Booting up', steps = 0) ⇒ Animation
constructor
A new instance of Animation.
- #remove_alias(aka) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(message = 'Booting up', steps = 0) ⇒ Animation
Returns a new instance of Animation.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/starlined/animation.rb', line 10 def initialize( = 'Booting up', steps = 0) = @start_time = Time.now @steps = steps @current_steps = 0 # variables de animación @pos = [0, 1, 2] @move = 1 # manejo de alias @aliases = [] @alias_pointer = 0 @alias_timer = 0 @alias_semaphore = Mutex.new @steps_semaphore = Mutex.new @running = false @thread = nil end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
8 9 10 |
# File 'lib/starlined/animation.rb', line 8 def aliases @aliases end |
#current_steps ⇒ Object (readonly)
Returns the value of attribute current_steps.
7 8 9 |
# File 'lib/starlined/animation.rb', line 7 def current_steps @current_steps end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/starlined/animation.rb', line 7 def end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/starlined/animation.rb', line 7 def start_time @start_time end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
7 8 9 |
# File 'lib/starlined/animation.rb', line 7 def steps @steps end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
7 8 9 |
# File 'lib/starlined/animation.rb', line 7 def thread @thread end |
Instance Method Details
#add_alias(aka) ⇒ Object
53 54 55 56 57 |
# File 'lib/starlined/animation.rb', line 53 def add_alias(aka) return if aka.nil? @alias_semaphore.synchronize { @aliases.push(aka) } end |
#elapsed_time ⇒ Object
69 70 71 |
# File 'lib/starlined/animation.rb', line 69 def elapsed_time (Time.now - @start_time).round(2).to_s end |
#increment_step ⇒ Object
47 48 49 50 51 |
# File 'lib/starlined/animation.rb', line 47 def increment_step @steps_semaphore.synchronize do @current_steps += 1 if @current_steps < @steps end end |
#remove_alias(aka) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/starlined/animation.rb', line 59 def remove_alias(aka) return if aka.nil? @alias_semaphore.synchronize do @aliases.delete(aka) # ajustar el puntero si se eliminó un elemento antes de la posición actual @alias_pointer = 0 if @alias_pointer >= @aliases.length && !@aliases.empty? end end |
#start ⇒ Object
32 33 34 35 36 37 |
# File 'lib/starlined/animation.rb', line 32 def start return if @running @running = true @thread = Thread.new { animation_loop } end |
#stop ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/starlined/animation.rb', line 39 def stop return unless @running @running = false @thread&.kill @thread = nil end |