Class: Codex::GraphvizFilter::Descriptor

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/codex/filters/graphviz_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Descriptor

Returns a new instance of Descriptor.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/codex/filters/graphviz_filter.rb', line 17

def initialize(string)
  @engine = "dot"
  @file_type = "svg"
  @width = nil
  @height = nil
  @file_name = nil

  if string && string =~ /^\[(.*)\]/
    @file_name = nil
    parse_params($1.dup)
  elsif string && string =~ /(.*?)\[(.*)\]/
    @file_name = $1
    parse_params($2.dup)
  else
    @file_name = string
  end
end

Instance Attribute Details

#engineObject (readonly)

Returns the value of attribute engine.



11
12
13
# File 'lib/codex/filters/graphviz_filter.rb', line 11

def engine
  @engine
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



11
12
13
# File 'lib/codex/filters/graphviz_filter.rb', line 11

def file_name
  @file_name
end

#file_typeObject (readonly)

Returns the value of attribute file_type.



11
12
13
# File 'lib/codex/filters/graphviz_filter.rb', line 11

def file_type
  @file_type
end

#heightObject (readonly)

Returns the value of attribute height.



11
12
13
# File 'lib/codex/filters/graphviz_filter.rb', line 11

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



11
12
13
# File 'lib/codex/filters/graphviz_filter.rb', line 11

def width
  @width
end

Instance Method Details

#graphviz_cmd(outputfile) ⇒ Object



58
59
60
61
62
# File 'lib/codex/filters/graphviz_filter.rb', line 58

def graphviz_cmd(outputfile)
  exec = which(@engine)
  file = (@file_name.nil? or @file_name.empty?)?"":File.expand_path(@file_name)
  "#{exec} #{file} -T#{@file_type} -o#{outputfile} #{@extra_options}"
end

#parse_params(params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/codex/filters/graphviz_filter.rb', line 35

def parse_params(params)
  params.split.each do |param|
    if param =~ /(.*?)=(.*)/
      case $1
      when "engine"
        @engine = $2
        fail "Unknown engine value. Choices are: dot,neato,twopi and circo." unless @engine =~ /dot|neato|twopi|circo/
      when "width"
        @width = $2
      when "height"
        @height = $2
      when "type"
        @file_type = $2
        fail "Unknown output format. Choices are: png,jpeg and svg" unless @file_type =~ /png|jpeg|svg/
      when "options" # Additional options for graphviz
        @extra_options = $2
      else
        fail "Unknown parameter #{$1} in '#{params}'"
      end
    end
  end
end