class TheFox::Timr::Model::Stack

The Stack holds one or more Tracks. Only one Track can run at a time.

When you push a new Track on the Stack the underlying running will be paused.

Do not call Stack methods from extern. Only the Timr class is responsible to call Stack methods.

Attributes

timr[RW]

Timr instance.

tracks[R]

Holds all Tracks.

Public Class Methods

new() click to toggle source
Calls superclass method TheFox::Timr::Model::BasicModel.new
# File lib/timr/model/stack.rb, line 22
def initialize
    super()
    
    @timr = nil
    
    # Data
    @tracks = Array.new
end

Public Instance Methods

<<(track) click to toggle source

Append a Track.

# File lib/timr/model/stack.rb, line 103
def <<(track)
    @tracks << track
end
current_track() click to toggle source

Get the current Track (Top Track).

# File lib/timr/model/stack.rb, line 32
def current_track
    @tracks.last
end
inspect() click to toggle source
# File lib/timr/model/stack.rb, line 113
def inspect
    "#<Stack tracks=#{@tracks.count} current=#{@current_track.short_id}>"
end
on_stack?(track) click to toggle source

Check Track on Stack.

# File lib/timr/model/stack.rb, line 94
def on_stack?(track)
    unless track.is_a?(Track)
        raise StackError, "track variable must be a Track instance. #{track.class} given."
    end
    
    @tracks.include?(track)
end
push(track) click to toggle source

Push a Track.

# File lib/timr/model/stack.rb, line 62
def push(track)
    unless track.is_a?(Track)
        raise StackError, "track variable must be a Track instance. #{track.class} given."
    end
    
    @tracks << track
    
    # Mark Stack as changed.
    changed
end
remove(track) click to toggle source

Remove a Track.

# File lib/timr/model/stack.rb, line 74
def remove(track)
    unless track.is_a?(Track)
        raise StackError, "track variable must be a Track instance. #{track.class} given."
    end
    
    @tracks.delete(track)
    
    # Mark Stack as changed.
    changed
end
reset() click to toggle source

Remove all Tracks from Stack.

# File lib/timr/model/stack.rb, line 86
def reset
    @tracks = Array.new
    
    # Mark Stack as changed.
    changed
end
start(track) click to toggle source

Start a Track.

# File lib/timr/model/stack.rb, line 37
def start(track)
    unless track.is_a?(Track)
        raise StackError, "track variable must be a Track instance. #{track.class} given."
    end
    
    stop
    
    @tracks = Array.new
    @tracks << track
    
    # Mark Stack as changed.
    changed
end
stop() click to toggle source

Stop current running Track.

# File lib/timr/model/stack.rb, line 52
def stop
    if @tracks.count > 0
        @tracks.pop
        
        # Mark Stack as changed.
        changed
    end
end
to_s() click to toggle source

To String

# File lib/timr/model/stack.rb, line 108
def to_s
    tracks_s = TranslationHelper.pluralize(@tracks.count, 'track', 'tracks')
    'Stack: %s' % [tracks_s]
end