Skip to content

Commit 00cf531

Browse files
committed
changed the to_json2 method to be compatible with the json gem
1 parent 8330334 commit 00cf531

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

lib/open_flash_chart/base.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module OpenFlashChart
22
class Base
3-
3+
attr_accessor :elements
4+
attr_accessor :title
45
def initialize(args={})
56
# set all the instance variables we want
67
# assuming something like this OpenFlashChart.new(:x_axis => 5, :y_axis => 10, :elements => ["one", "two"], ...)
@@ -33,10 +34,27 @@ def render
3334
end
3435

3536
def to_json2
36-
self.instance_values.to_json
37+
#self.instance_values.to_json
38+
self.to_renderable.to_json
3739
end
3840

39-
alias_method :to_s, :render
41+
def to_renderable
42+
self.instance_values.inject({}) do |hash,key_val_arr|
43+
key,val = key_val_arr
44+
if key == "elements"
45+
hash[key] = val.map{|e| e.to_renderable}
46+
elsif val.class.name =~ /OpenFlashChart/
47+
puts "returning to_renderable on #{val.class.name} #{val.to_s}"
48+
hash[key] = val.to_renderable
49+
else
50+
puts "returning val for #{val.class.name} #{val.to_s}"
51+
hash[key] = val
52+
end
53+
hash
54+
end
55+
end
56+
57+
#alias_method :to_s, :render
4058

4159
def add_element(element)
4260
@elements ||= []

0 commit comments

Comments
 (0)