Class: Quacky::PieChartBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/quacky/pie_chart_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(init_data = []) ⇒ PieChartBuilder

Returns a new instance of PieChartBuilder.



6
7
8
# File 'lib/quacky/pie_chart_builder.rb', line 6

def initialize(init_data = [])
  @data = init_data
end

Instance Method Details

#add_data(input) ⇒ Object

Add data. If input is a hash, add it in. Otherwise (it’s an array, most likely), set @data to input.



18
19
20
21
22
23
24
# File 'lib/quacky/pie_chart_builder.rb', line 18

def add_data(input)
  if input.class == Hash
    @data << input
  else
    @data = input
  end
end

#clear_dataObject



26
27
28
# File 'lib/quacky/pie_chart_builder.rb', line 26

def clear_data
  @data = []
end

#drawObject

Return a content tag that can be selected by the client-side, and drawn on. The data attribute of the HTML tag is @data.



12
13
14
# File 'lib/quacky/pie_chart_builder.rb', line 12

def draw
  "<div class='pie-chart' data-chart='#{@data.to_json}'></div>".html_safe
end

#get_dataObject



30
31
32
# File 'lib/quacky/pie_chart_builder.rb', line 30

def get_data
  @data
end