From: Jeff Pritchard Date: 2006-06-02T16:27:00+09:00 Subject: Re: This is brain dead, but is it stupid? A modest beginning... class BDBarGraph def initialize(height,width,xmin,xmax) @height = height * 1.0 @width = width * 1.0 @xmin = xmin * 1.0 @xmax = xmax * 1.0 @dataPoints = [] # the y values to plot @htmlString = "" @barString = "\n" end attr_reader :xmin, :xmax, :dataPoints def points @dataPoints.length end def add_point(value) @dataPoints << value * 1.0 end def draw @dataPoints.each do |thisPoint| tempString = "" tempString << @barString tempString.gsub!(/replace_with_width/,(@width/points).to_i.to_s) barHeight = ((thisPoint - @xmin)/(@xmax - @xmin)) * @height tempString.gsub!(/replace_with_height/,barHeight.to_i.to_s) @htmlString << tempString end puts @htmlString end end bar = BDBarGraph.new(200,200,0,100) bar.add_point(50) bar.add_point(75) bar.add_point(100) bar.add_point(25) bar.draw [cpe-66-75-140-208:~] jeff% ruby BDBarGraph.rb [cpe-66-75-140-208:~] jeff% Still needs stuff to do x and y labels (probably using a table) Still needs error checking Maybe some refactoring to make it easier to use from erb Question, something like this that is intended to be used from erb, how is error checking usually handled? Just fail quietly? Seems like assertions might not be handled gracefully in erb. Any coding comments welcome. thanks, jp -- Posted via http://www.ruby-forum.com/.