Class: MotionBlender::GraphMaker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dependencies, opts = {}) ⇒ GraphMaker

Returns a new instance of GraphMaker.



10
11
12
13
14
15
16
# File 'lib/motion_blender/graph_maker.rb', line 10

def initialize dependencies, opts = {}
  @dependencies = dependencies
  @title = opts[:title]
  @filter = opts[:filter]
  @layout = opts[:layout].try(:to_sym) || :sfdp
  @output = opts[:output] || 'graph.pdf'
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



7
8
9
# File 'lib/motion_blender/graph_maker.rb', line 7

def dependencies
  @dependencies
end

#filterObject

Returns the value of attribute filter.



8
9
10
# File 'lib/motion_blender/graph_maker.rb', line 8

def filter
  @filter
end

#layoutObject

Returns the value of attribute layout.



8
9
10
# File 'lib/motion_blender/graph_maker.rb', line 8

def layout
  @layout
end

#outputObject

Returns the value of attribute output.



8
9
10
# File 'lib/motion_blender/graph_maker.rb', line 8

def output
  @output
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/motion_blender/graph_maker.rb', line 8

def title
  @title
end

Instance Method Details

#buildObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/motion_blender/graph_maker.rb', line 18

def build
  g = GraphViz.new(@title || 'Graph', type: :digraph, use: @layout)
  label = [@title, (@filter && "/#{@filter}/")].compact.join(' ')
  g[:label] = label if label.present?
  g[:overlap] = false

  deps =
    @dependencies
    .select { |k, _| acceptable? k }
    .map { |k, v| [k, v.select { |f| acceptable? f }] }
  deps.map { |k, v| [k, *v] }.flatten.uniq.reverse_each do |f|
    g.add_node f, node_options_for(f)
  end
  deps.each do |k, v|
    v.each { |f| g.add_edge k, f, edge_options_for(k, f) }
  end

  g.output(output_format => @output)
end