Module: Psychgus::Ext::NodeExt

Defined in:
lib/psychgus/ext/node_ext.rb

Overview

Extensions to Psych::Nodes::Node.

Author:

  • Jonathan Bradley Whited (@esotericpig)

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#node_of?(*names) ⇒ true, false

Check if this Node is of a certain type (Alias, Mapping, Scalar, Sequence, etc.).

New versions of Psych have alias?(), mapping?(), etc., so this is for old versions.

This is equivalent to the following (with less typing):

node.is_a?(Psych::Nodes::Alias)
node.is_a?(Psych::Nodes::Mapping)
node.is_a?(Psych::Nodes::Scalar)
node.is_a?(Psych::Nodes::Sequence)

Examples:

node.node_of?(:alias)
node.node_of?(:mapping)
node.node_of?(:scalar)
node.node_of?(:sequence)
node.node_of?(:alias,:mapping,:scalar,:sequence) # OR
node.node_of?(:doc,:map,:seq) # OR

Parameters:

  • names (Symbol, String)

    the type(s) to check using OR

Returns:

  • (true, false)

    true if this Node is one of the names type, else false

See Also:

Since:

  • 1.0.0


57
58
59
60
61
62
63
# File 'lib/psychgus/ext/node_ext.rb', line 57

def node_of?(*names)
  names.each do |name|
    return true if is_a?(Psychgus.node_class(name))
  end
  
  return false
end