class Frill::DependencyGraph

Attributes

nodes[R]

Public Class Methods

new() click to toggle source
# File lib/frill/frill.rb, line 48
def initialize
  @nodes = {}
end

Public Instance Methods

[](label) click to toggle source
# File lib/frill/frill.rb, line 65
def [](label)
  nodes[label]
end
add(label) click to toggle source
# File lib/frill/frill.rb, line 52
def add label
  nodes[label] ||= Node.new label
end
empty?() click to toggle source
# File lib/frill/frill.rb, line 69
def empty?
  nodes.empty?
end
include?(label) click to toggle source
# File lib/frill/frill.rb, line 73
def include? label
  nodes[label]
end
index(label) click to toggle source
# File lib/frill/frill.rb, line 77
def index label
  to_a.index label
end
move_before(label1, label2) click to toggle source
# File lib/frill/frill.rb, line 56
def move_before label1, label2
  node1 = add label1
  node2 = add label2

  node1.move_before node2

  CycleDetecter.detect! nodes
end
to_a() click to toggle source
# File lib/frill/frill.rb, line 81
def to_a
  array = []

  nodes.values.each do |node|
    array += construct_array(node) unless array.include? node.label
  end

  array
end

Private Instance Methods

construct_array(node) click to toggle source
# File lib/frill/frill.rb, line 94
def construct_array node
  array = []
  current_node = node.first

  while current_node
    array << current_node.label
    current_node = current_node.next
  end

  array
end