Skip to content

Commit

Permalink
changed the to_json2 method to be compatible with the json gem
Browse files Browse the repository at this point in the history
  • Loading branch information
klochner committed Oct 26, 2009
1 parent 8330334 commit 00cf531
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/open_flash_chart/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module OpenFlashChart
class Base

attr_accessor :elements
attr_accessor :title
def initialize(args={})
# set all the instance variables we want
# assuming something like this OpenFlashChart.new(:x_axis => 5, :y_axis => 10, :elements => ["one", "two"], ...)
Expand Down Expand Up @@ -33,10 +34,27 @@ def render
end

def to_json2
self.instance_values.to_json
#self.instance_values.to_json
self.to_renderable.to_json
end

alias_method :to_s, :render
def to_renderable
self.instance_values.inject({}) do |hash,key_val_arr|
key,val = key_val_arr
if key == "elements"
hash[key] = val.map{|e| e.to_renderable}
elsif val.class.name =~ /OpenFlashChart/
puts "returning to_renderable on #{val.class.name} #{val.to_s}"
hash[key] = val.to_renderable
else
puts "returning val for #{val.class.name} #{val.to_s}"
hash[key] = val
end
hash
end
end

#alias_method :to_s, :render

def add_element(element)
@elements ||= []
Expand Down

0 comments on commit 00cf531

Please sign in to comment.