Module: Hanuman::GraphInstanceMethods

Included in:
Graph, GraphBuilder
Defined in:
lib/hanuman/graph.rb

Instance Method Summary collapse

Instance Method Details



28
29
30
31
32
# File 'lib/hanuman/graph.rb', line 28

def add_link type, from, into
  add_stage(from)
  add_stage(into)
  self.links << Hanuman::LinkFactory.connect(type, from.linkable_name(:in), into.linkable_name(:out))
end

#add_stage(stage) ⇒ Object



20
21
22
# File 'lib/hanuman/graph.rb', line 20

def add_stage stage
  stages[stage.label] = stage
end

#ancestors(stage = nil) ⇒ Object



14
15
16
17
18
# File 'lib/hanuman/graph.rb', line 14

def ancestors stage=nil
  links.find_all do |link|
    stage ? link.into == stage.label : true
  end.map(&:from).uniq.map { |label| stages[label] }.compact
end

#descendents(stage = nil) ⇒ Object



8
9
10
11
12
# File 'lib/hanuman/graph.rb', line 8

def descendents stage=nil
  links.find_all do |link|
    stage ? link.from == stage.label : true
  end.map(&:into).uniq.map { |label| stages[label] }.compact
end

#each_stage(&block) ⇒ Object



4
5
6
# File 'lib/hanuman/graph.rb', line 4

def each_stage &block
  stages.values.each(&block)
end

#has_link?(from, into) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/hanuman/graph.rb', line 24

def has_link? from, into
  links.detect { |link| link.from == from.label && link.into == into.label } ? true : false
end