Class: Musa::Series::Constructors::QueueSerie Private

Inherits:
Object
  • Object
show all
Defined in:
lib/musa-dsl/series/queue-serie.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Serie that processes multiple source series in queue/sequence fashion.

Combines multiple series by playing them sequentially - when one series exhausts, moves to the next. New series can be added dynamically with << operator.

All queued series must be instances (not prototypes). The queue can be cleared with clear method.

Examples:

Sequential series playback

serie_a = FromArray.new([1, 2, 3]).instance
serie_b = FromArray.new([4, 5, 6]).instance
queue = QueueSerie.new([serie_a, serie_b])
queue.next_value  # => 1
queue.next_value  # => 2
queue.next_value  # => 3
queue.next_value  # => 4 (switches to serie_b)

Dynamic queueing

queue = QueueSerie.new([serie_a]).instance
queue << serie_b  # Add series on the fly
queue.clear       # Empty the queue

Instance Method Summary collapse

Constructor Details

#initialize(series) ⇒ QueueSerie

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of QueueSerie.



77
78
79
80
# File 'lib/musa-dsl/series/queue-serie.rb', line 77

def initialize(series)
  self.sources = series
  init
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **key_args, &block) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



136
137
138
139
140
141
142
# File 'lib/musa-dsl/series/queue-serie.rb', line 136

private def method_missing(method_name, *args, **key_args, &block)
  if @current&.respond_to?(method_name)
    @current.send method_name, *args, **key_args, &block
  else
    super
  end
end

Instance Method Details

#<<(serie) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


82
83
84
85
86
87
88
89
90
91
92
# File 'lib/musa-dsl/series/queue-serie.rb', line 82

def <<(serie)
  # when queue is a prototype it is also frozen so no serie can be added (it would raise an Exception if tried).
  # when queue is an instance the added serie should also be an instance (raise an Exception otherwise)
  #
  raise ArgumentError, "Only an instance serie can be queued" unless serie.instance?

  @sources << serie
  @current ||= @sources[@index]

  self
end

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
97
98
# File 'lib/musa-dsl/series/queue-serie.rb', line 94

def clear
  @sources.clear
  init
  self
end

#infinite?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


126
127
128
# File 'lib/musa-dsl/series/queue-serie.rb', line 126

def infinite?
  !!@sources.find(&:infinite?)
end