class Blackbeard::Chart
Attributes
dom_id[R]
Public Class Methods
new(options)
click to toggle source
# File lib/blackbeard/chart.rb, line 5 def initialize(options) [:dom_id, :height, :title].each{|m| instance_variable_set("@#{m}", options[m]) } [:rows, :columns].each{|m| instance_variable_set("@#{m}", options[m] || []) } end
Public Instance Methods
data()
click to toggle source
# File lib/blackbeard/chart.rb, line 14 def data {:rows => rows, :cols => columns} end
options()
click to toggle source
# File lib/blackbeard/chart.rb, line 10 def options {:title => @title, :height => height} end
Private Instance Methods
cell_type(value)
click to toggle source
# File lib/blackbeard/chart.rb, line 45 def cell_type(value) case value.class.name when 'Fixnum' 'number' when 'Float' 'number' when 'String' 'string' when 'Date' 'string' else 'string' end end
column(label, type)
click to toggle source
# File lib/blackbeard/chart.rb, line 60 def column(label, type) {:label => label, :type => type} end
column_types()
click to toggle source
# File lib/blackbeard/chart.rb, line 41 def column_types @rows.first.map{ |cell_value| cell_type(cell_value) } end
columns()
click to toggle source
# File lib/blackbeard/chart.rb, line 36 def columns types = column_types @columns.map{ |label| column(label,types.shift) } end
height()
click to toggle source
# File lib/blackbeard/chart.rb, line 20 def height @height || 300 end
row(r)
click to toggle source
# File lib/blackbeard/chart.rb, line 28 def row(r) { :c => r.map{ |c| row_cell(c) } } end
row_cell(cell_value)
click to toggle source
# File lib/blackbeard/chart.rb, line 32 def row_cell(cell_value) { :v => cell_value } end
rows()
click to toggle source
# File lib/blackbeard/chart.rb, line 24 def rows @rows.map{ |r| row(r) } end