Sha256: e2afd89275773d3059d147b98343fde4326d942d6459a7c9ac91c35545fe9c89

Contents?: true

Size: 1.76 KB

Versions: 21

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true
require 'stringio'
require 'psych/class_loader'
require 'psych/scalar_scanner'

module Psych
  module Nodes
    ###
    # The base class for any Node in a YAML parse tree.  This class should
    # never be instantiated.
    class Node
      include Enumerable

      # The children of this node
      attr_reader :children

      # An associated tag
      attr_reader :tag

      # The line number where this node start
      attr_accessor :start_line

      # The column number where this node start
      attr_accessor :start_column

      # The line number where this node ends
      attr_accessor :end_line

      # The column number where this node ends
      attr_accessor :end_column

      # Create a new Psych::Nodes::Node
      def initialize
        @children = []
      end

      ###
      # Iterate over each node in the tree. Yields each node to +block+ depth
      # first.
      def each &block
        return enum_for :each unless block_given?
        Visitors::DepthFirst.new(block).accept self
      end

      ###
      # Convert this node to Ruby.
      #
      # See also Psych::Visitors::ToRuby
      def to_ruby
        Visitors::ToRuby.create.accept(self)
      end
      alias :transform :to_ruby

      ###
      # Convert this node to YAML.
      #
      # See also Psych::Visitors::Emitter
      def yaml io = nil, options = {}
        real_io = io || StringIO.new(''.encode('utf-8'))

        Visitors::Emitter.new(real_io, options).accept self
        return real_io.string unless io
        io
      end
      alias :to_yaml :yaml

      def alias?;    false; end
      def document?; false; end
      def mapping?;  false; end
      def scalar?;   false; end
      def sequence?; false; end
      def stream?;   false; end
    end
  end
end

Version data entries

21 entries across 21 versions & 3 rubygems

Version Path
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/psych-3.1.0/lib/psych/nodes/node.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/psych-3.1.0/lib/psych/nodes/node.rb
psych-3.1.0-x86-mingw32 lib/psych/nodes/node.rb
psych-3.1.0-x64-mingw32 lib/psych/nodes/node.rb
psych-3.1.0-java lib/psych/nodes/node.rb
psych-3.1.0 lib/psych/nodes/node.rb
psych-3.0.3-x86-mingw32 lib/psych/nodes/node.rb
psych-3.0.3-x64-mingw32 lib/psych/nodes/node.rb
psych-3.0.3 lib/psych/nodes/node.rb
psych-3.0.3-java lib/psych/nodes/node.rb
psych-3.0.3.pre5-java lib/psych/nodes/node.rb
psych-3.0.3.pre4-java lib/psych/nodes/node.rb
psych-3.0.3.pre3-x64-mingw32 lib/psych/nodes/node.rb
psych-3.0.3.pre3-java lib/psych/nodes/node.rb
psych-3.0.3.pre3 lib/psych/nodes/node.rb
psych-3.0.3.pre2-x86-mingw32 lib/psych/nodes/node.rb
psych-3.0.3.pre2-x64-mingw32 lib/psych/nodes/node.rb
psych-3.0.3.pre2-java lib/psych/nodes/node.rb
psych-3.0.3.pre2 lib/psych/nodes/node.rb
psych-3.0.3.pre1 lib/psych/nodes/node.rb