Class: Charts::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/charts/bin/dispatcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Dispatcher

Returns a new instance of Dispatcher.



5
6
7
8
# File 'lib/charts/bin/dispatcher.rb', line 5

def initialize(options)
  @options = options
  @chart = dispatch
end

Instance Attribute Details

#chartObject (readonly)

Returns the value of attribute chart.



3
4
5
# File 'lib/charts/bin/dispatcher.rb', line 3

def chart
  @chart
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/charts/bin/dispatcher.rb', line 3

def options
  @options
end

Instance Method Details

#chart_optionsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

#dataObject



36
37
38
# File 'lib/charts/bin/dispatcher.rb', line 36

def data
  options[:data]
end

#dispatchObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

#renderObject



10
11
12
13
14
15
16
# File 'lib/charts/bin/dispatcher.rb', line 10

def render
  if options[:filename]
    chart.render
  else
    puts chart.render
  end
end

#styleObject



63
64
65
# File 'lib/charts/bin/dispatcher.rb', line 63

def style
  options[:style].to_sym
end

#typeObject



59
60
61
# File 'lib/charts/bin/dispatcher.rb', line 59

def type
  options[:type].to_sym
end