summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/json_tree.rb
blob: dd06e806076990f7e92ab6ce89a9c0908d3fa8c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Psych
  module Visitors
    class JSONTree < YAMLTree
      def initialize options = {}, emitter = Psych::JSON::TreeBuilder.new
        super
      end

      def visit_Time o
        formatted = format_time o
        @emitter.scalar formatted, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
      end

      def visit_DateTime o
        visit_Time o.to_time
      end

      def visit_String o
        @emitter.scalar o.to_s, nil, nil, false, true, Nodes::Scalar::DOUBLE_QUOTED
      end
      alias :visit_Symbol :visit_String
    end
  end
end