class Charts::Dispatcher

Attributes

chart[R]
options[R]

Public Class Methods

new(options) click to toggle source
# File lib/charts/bin/dispatcher.rb, line 5
def initialize(options)
  @options = options
  @chart = dispatch
end

Public Instance Methods

chart_options() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 40
def chart_options
  options.select do |key, _value|
    [
      :background_color,
      :colors,
      :columns,
      :filename,
      :group_labels,
      :height,
      :item_height,
      :item_width,
      :labels,
      :title,
      :type,
      :width
    ].include? key
  end
end
data() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 36
def data
  options[:data]
end
dispatch() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 18
def dispatch
  if type == :txt
    SymbolCountChart.new(data, chart_options)
  elsif [:svg, :png, :jpg, :gif].include? type
    if style == :circle
      CircleCountChart.new(data, chart_options)
    elsif style == :cross
      CrossCountChart.new(data, chart_options)
    elsif style == :manikin
      ManikinCountChart.new(data, chart_options)
    elsif style == :bar
      BarChart.new(data, chart_options)
    elsif style == :pie
      PieChart.new(data, chart_options)
    end
  end
end
render() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 10
def render
  if options[:filename]
    chart.render
  else
    puts chart.render
  end
end
style() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 63
def style
  options[:style].to_sym
end
type() click to toggle source
# File lib/charts/bin/dispatcher.rb, line 59
def type
  options[:type].to_sym
end