Class: Psych::Nodes::Document

Inherits:
Node show all
Defined in:
lib/psych/nodes/document.rb

Overview

This represents a YAML Document. This node must be a child of Psych::Nodes::Stream. A Psych::Nodes::Document must have one child, and that child may be one of the following:

  • Psych::Nodes::Sequence

  • Psych::Nodes::Mapping

  • Psych::Nodes::Scalar

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #end_column, #end_line, #start_column, #start_line, #tag

Instance Method Summary collapse

Methods inherited from Node

#alias?, #each, #mapping?, #scalar?, #sequence?, #stream?, #to_ruby, #yaml

Constructor Details

#initialize(version = [], tag_directives = [], implicit = false) ⇒ Document

Create a new Psych::Nodes::Document object.

version is a list indicating the YAML version. tags_directives is a list of tag directive declarations implicit is a flag indicating whether the document will be implicitly started.

Example:

This creates a YAML document object that represents a YAML 1.1 document with one tag directive, and has an implicit start:

Psych::Nodes::Document.new(
  [1,1],
  [["!", "tag:tenderlovemaking.com,2009:"]],
  true
)

See Also

See also Psych::Handler#start_document



45
46
47
48
49
50
51
# File 'lib/psych/nodes/document.rb', line 45

def initialize version = [], tag_directives = [], implicit = false
  super()
  @version        = version
  @tag_directives = tag_directives
  @implicit       = implicit
  @implicit_end   = true
end

Instance Attribute Details

#implicitObject

Was this document implicitly created?



20
21
22
# File 'lib/psych/nodes/document.rb', line 20

def implicit
  @implicit
end

#implicit_endObject

Is the end of the document implicit?



23
24
25
# File 'lib/psych/nodes/document.rb', line 23

def implicit_end
  @implicit_end
end

#tag_directivesObject

A list of tag directives for this document



17
18
19
# File 'lib/psych/nodes/document.rb', line 17

def tag_directives
  @tag_directives
end

#versionObject

The version of the YAML document



14
15
16
# File 'lib/psych/nodes/document.rb', line 14

def version
  @version
end

Instance Method Details

#document?Boolean

Returns:

  • (Boolean)


60
# File 'lib/psych/nodes/document.rb', line 60

def document?; true; end

#rootObject

Returns the root node. A Document may only have one root node: yaml.org/spec/1.1/#id898031



56
57
58
# File 'lib/psych/nodes/document.rb', line 56

def root
  children.first
end