Class: Frill::DependencyGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/frill/frill.rb

Defined Under Namespace

Classes: CycleDetecter, Node

Instance Method Summary collapse

Constructor Details

#initializeDependencyGraph

Returns a new instance of DependencyGraph.



48
49
50
# File 'lib/frill/frill.rb', line 48

def initialize
  @nodes = {}
end

Instance Method Details

#[](label) ⇒ Object



65
66
67
# File 'lib/frill/frill.rb', line 65

def [](label)
  nodes[label]
end

#add(label) ⇒ Object



52
53
54
# File 'lib/frill/frill.rb', line 52

def add label
  nodes[label] ||= Node.new label
end

#empty?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/frill/frill.rb', line 69

def empty?
  nodes.empty?
end

#include?(label) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/frill/frill.rb', line 73

def include? label
  nodes[label]
end

#index(label) ⇒ Object



77
78
79
# File 'lib/frill/frill.rb', line 77

def index label
  to_a.index label
end

#move_before(label1, label2) ⇒ Object



56
57
58
59
60
61
62
63
# 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_aObject



81
82
83
84
85
86
87
88
89
# 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