YAML::Schema::Core - Crystal 1.19.1

# module YAML::Schema::Core

##
Overview

Provides utility methods for the YAML 1.1 core schema with the additional independent types specified in http://yaml.org/type/

##
Defined in:

yaml/schema/core.cr

##
Class Method Summary

- .each(node : YAML::Nodes::Mapping, &)

  Invokes the block for each of the given nodes keys and values, resolving merge keys (<<) when found (keys and values of the resolved merge mappings are yielded, recursively).

- .parse(data : String | IO) : YAML::Any

  Deserializes a YAML document.

- .parse_all(data : String | IO) : Array(YAML::Any)

  Deserializes multiple YAML documents.

- .parse_int(node : Nodes::Node, type : T.class) : T forall T

  Parses an integer of the given type according to the core schema.

- .parse_null?(node : Nodes::Node)

  Returns `true` if node parses to a null value.

- .parse_null_or(node : YAML::Nodes::Node, &)

  If `node` parses to a null value, returns `nil`, otherwise invokes the given block.

- .parse_scalar(pull_parser : YAML::PullParser) : Nil | Bool | Int64 | Float64 | String | Time | Bytes

  Assuming the pull_parser is positioned in a scalar, parses it according to the core schema, taking the scalar's style and tag into account, then advances the pull parser.

- .parse_scalar(string : String) : Nil | Bool | Int64 | Float64 | String | Time | Bytes

  Parses a string according to the core schema, assuming the string had a plain style.

- .parse_scalar(node : YAML::Nodes::Scalar) : Nil | Bool | Int64 | Float64 | String | Time | Bytes

  Parses a scalar value from the given node.

- .reserved_string?(string) : Bool

  Returns whether a string is reserved and must non be output with a plain style, according to the core schema.

##
Class Method Detail

def self.each(node : YAML::Nodes::Mapping, &) #

Invokes the block for each of the given nodes keys and values, resolving merge keys (<<) when found (keys and values of the resolved merge mappings are yielded, recursively).

def self.parse(data : String | IO) : YAML::Any #

Deserializes a YAML document.

Same as `YAML.parse`.

def self.parse_all(data : String | IO) : Array(YAML::Any) #

Deserializes multiple YAML documents.

Same as `YAML.parse_all`.

def self.parse_int(node : Nodes::Node, type : T.class) : T forall T #

Parses an integer of the given type according to the core schema.

type must be a primitive integer type. Raises `YAML::ParseException` if node is not a valid integer or its value is outside type's range.

def self.parse_null?(node : Nodes::Node) #

Returns `true` if node parses to a null value.

def self.parse_null_or(node : YAML::Nodes::Node, &) #

If `node` parses to a null value, returns `nil`, otherwise invokes the given block.

def self.parse_scalar(pull_parser : YAML::PullParser) : Nil | Bool | Int64 | Float64 | String | Time | Bytes #

Assuming the pull_parser is positioned in a scalar, parses it according to the core schema, taking the scalar's style and tag into account, then advances the pull parser.

def self.parse_scalar(string : String) : Nil | Bool | Int64 | Float64 | String | Time | Bytes #

Parses a string according to the core schema, assuming the string had a plain style.

    require "yaml"

    YAML::Schema::Core.parse_scalar("hello") # => "hello"
    YAML::Schema::Core.parse_scalar("1.2")   # => 1.2
    YAML::Schema::Core.parse_scalar("false") # => false

def self.parse_scalar(node : YAML::Nodes::Scalar) : Nil | Bool | Int64 | Float64 | String | Time | Bytes #

Parses a scalar value from the given node.

def self.reserved_string?(string) : Bool #

Returns whether a string is reserved and must non be output with a plain style, according to the core schema.

    require "yaml"

    YAML::Schema::Core.reserved_string?("hello") # => false
    YAML::Schema::Core.reserved_string?("1.2")   # => true
    YAML::Schema::Core.reserved_string?("false") # => true