class ChartJS::Data

Public Class Methods

new() click to toggle source
# File lib/chart_js/chart/bar_chart/data.rb, line 7
def initialize
  @container = Hash.new
  @datasets  = Hash.new
end

Public Instance Methods

build(&block) click to toggle source
# File lib/chart_js/chart/bar_chart/data.rb, line 12
def build(&block)
  instance_eval(&block)
  self
end
dataset(label, &block) click to toggle source
# File lib/chart_js/chart/bar_chart/data.rb, line 22
def dataset(label, &block)
  @datasets[label] = Dataset.new(label, &block)
end
labels(labels = nil) click to toggle source
# File lib/chart_js/chart/bar_chart/data.rb, line 17
def labels(labels = nil)
  raise "Not an array!" unless labels.is_a? Array
  @container['labels'] = labels
end
to_h() click to toggle source
# File lib/chart_js/chart/bar_chart/data.rb, line 26
def to_h
  cont = @container.dup
  cont['datasets'] = []
  @datasets.each do |_, data|
    cont['datasets'] << data.to_h
  end
  cont
end