Module: ChartHelpers

Defined in:
lib/chart_helpers.rb,
lib/chart_helpers/version.rb,
lib/chart_helpers/gantt_chart.rb,
lib/chart_helpers/parsers/gantt.rb,
lib/chart_helpers/parsers/graphviz.rb

Defined Under Namespace

Modules: Parsers Classes: GanttChart

Constant Summary collapse

VERSION =
'0.0.2'.freeze

Class Method Summary collapse

Class Method Details

.render_chart(chart, output_file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/chart_helpers.rb', line 9

def render_chart(chart, output_file)
  chart_lines = chart.split("\n")
  chart_type = chart_lines.shift.strip

  case chart_type
  when /\Agantt\Z/
    parse_gantt(chart_lines, output_file)
  when /\Agraph +\w+ +{/, /\Adigraph\s+\w+\s+{/
    g = GraphViz.parse_string(chart, output: 'svg', file: output_file)
    g.output(svg: output_file)
    g
  when /\Agraph/
    parse_graphviz(chart_lines, chart_type.split('graph').last.strip, output_file)
  else
    raise 'Unsupported chart type declared'
  end
end