summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/psych/visitors/json_tree.rb22
-rw-r--r--lib/psych/visitors/yaml_tree.rb8
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/psych/visitors/json_tree.rb b/lib/psych/visitors/json_tree.rb
index 0440dc7..774b043 100644
--- a/lib/psych/visitors/json_tree.rb
+++ b/lib/psych/visitors/json_tree.rb
@@ -1,16 +1,26 @@
module Psych
module Visitors
class JSONTree < YAMLTree
- def visit_Symbol o
- append create_scalar o.to_s
- end
-
def visit_NilClass o
- scalar = Nodes::Scalar.new(
+ scalar = create_scalar(
'null', nil, nil, true, false, Nodes::Scalar::PLAIN)
append scalar
end
+ def visit_Integer o
+ append create_scalar(o.to_s, nil, nil, true, false, Nodes::Scalar::PLAIN)
+ end
+
+ def visit_Float o
+ return super if o.nan? || o.infinite?
+ visit_Integer o
+ end
+
+ def visit_String o
+ append create_scalar o.to_s
+ end
+ alias :visit_Symbol :visit_String
+
private
def create_document
doc = super
@@ -26,7 +36,7 @@ module Psych
end
def create_scalar value, anchor = nil, tag = nil, plain = false, quoted = true, style = Nodes::Scalar::ANY
- super(value, anchor, tag, false, true, style)
+ super
end
def create_sequence anchor = nil, tag = nil, implicit = true, style = Nodes::Sequence::FLOW
diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 4c8ba29..608da6d 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/lib/psych/visitors/yaml_tree.rb
@@ -151,7 +151,7 @@ module Psych
end
def visit_Integer o
- append Nodes::Scalar.new o.to_s
+ append create_scalar o.to_s
end
alias :visit_TrueClass :visit_Integer
alias :visit_FalseClass :visit_Integer
@@ -159,11 +159,11 @@ module Psych
def visit_Float o
if o.nan?
- append Nodes::Scalar.new '.nan'
+ append create_scalar '.nan'
elsif o.infinite?
- append Nodes::Scalar.new(o.infinite? > 0 ? '.inf' : '-.inf')
+ append create_scalar(o.infinite? > 0 ? '.inf' : '-.inf')
else
- append Nodes::Scalar.new o.to_s
+ append create_scalar o.to_s
end
end