class RuneRb::System::Types::SortedStack

A Stack object organizes work via RuneRb::System::Types::Task objects and ensures the sequential execution of Tasks based on their Priority.

Public Class Methods

new() click to toggle source

Constructs a new Stack object @return [Stack]

# File deployment/app/system/types/stack.rb, line 7
def initialize
  @registry = []
end

Public Instance Methods

<<(task)
Alias for: push
clear() click to toggle source

Removes all Tasks from the <@registry>

# File deployment/app/system/types/stack.rb, line 56
def clear
  @registry.clear
end
empty?() click to toggle source

Returns whether the <@registry> is empty or not via boolean values (true, false) @return [Boolean] is the <@registry> empty?

# File deployment/app/system/types/stack.rb, line 23
def empty?
  @registry.empty?
end
first() click to toggle source

Returns the first task in the <@registry> @return [RuneRb::System::Types::Task, NilClass] the first task in the registry.

# File deployment/app/system/types/stack.rb, line 29
def first
  @registry.first
end
last() click to toggle source

Returns the last task in the <@registry> @return [RuneRb::System::Types::Task, NilClass] the last task in the registry.

# File deployment/app/system/types/stack.rb, line 35
def last
  @registry.last
end
length() click to toggle source

Returns the length of the registry @return [Integer]

# File deployment/app/system/types/stack.rb, line 41
def length
  @registry.length
end
push(task) click to toggle source

Pushes a new task to the Stack. Options are passed directly to the Task constructor.

The <@registry> object is a SortedSet which automatically organizes each task on submission and links the task's process to its predecessor's (via Task#target_to). @param task [RuneRb::System::Types::Task] the task to post.

# File deployment/app/system/types/stack.rb, line 15
def push(task)
  @registry << task
end
Also aliased as: <<
sort!() click to toggle source

Sorts the registry and links it's children via Task#target_to

# File deployment/app/system/types/stack.rb, line 46
def sort!
  @registry.sort!
  @registry.each do |task|
    next if task == last

    task.target_to(@registry[@registry.index(task) + 1].worker)
  end
end