lib/jsonify/json_value.rb in jsonify-0.0.8 vs lib/jsonify/json_value.rb in jsonify-0.0.9

- old
+ new

@@ -4,12 +4,12 @@ def initialize(values=nil) @values = values || [] end - def evaluate - wrap values.map {|v| v.evaluate}.join(',') + def to_json + wrap values.map {|v| v.to_json}.join(',') end def add(jsonValue) values << Generate.value(jsonValue) end @@ -39,11 +39,10 @@ @values.store(pair.key, pair) end end alias_method :<<, :add - alias_method :add!, :add # for consistency with the Builder api end class JsonArray < JsonValue @@ -59,58 +58,37 @@ end super(value) end alias_method :<<, :add - alias_method :add!, :add # for consistency with the Builder api end class JsonPair < JsonValue attr_accessor :key, :value def initialize(key, value=nil) @key = key.to_s @value = Generate.value(value) end - def evaluate - %Q{#{key.to_json}:#{value.evaluate}} + def to_json + %Q{#{key.to_json}:#{value.to_json}} end end - - class JsonString < JsonValue - attr_accessor :value - def initialize(value) - @value = value.to_s - end - def evaluate - value.to_json - end - end - - class JsonNumber < JsonValue - attr_accessor :value - def initialize(value) - @value = value - end - def evaluate - value - end - end class JsonTrue < JsonValue - def evaluate + def to_json 'true' end end class JsonFalse < JsonValue - def evaluate + def to_json 'false' end end class JsonNull < JsonValue - def evaluate + def to_json 'null' end end end \ No newline at end of file