Class: StyledYAML::TreeBuilder

Inherits:
Psych::TreeBuilder
  • Object
show all
Defined in:
lib/styled_yaml.rb

Overview

Custom tree builder class to recognize scalars tagged with ‘yaml_style`

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#next_seq_or_map_style(default_style) ⇒ Object



68
69
70
71
72
# File 'lib/styled_yaml.rb', line 68

def next_seq_or_map_style(default_style)
  style = @next_seq_or_map_style || default_style
  @next_seq_or_map_style = nil
  style
end

Instance Method Details

#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/styled_yaml.rb', line 74

def scalar(value, anchor, tag, plain, quoted, style)
  if value.respond_to?(:yaml_style)
    if style_literal_or_folded? value.yaml_style
      plain = false
      quoted = true
    end
    style = value.yaml_style
  end
  super
end

#style_literal_or_folded?(style) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/styled_yaml.rb', line 85

def style_literal_or_folded?(style)
  [Psych::Nodes::Scalar::LITERAL, Psych::Nodes::Scalar::FOLDED].include?(style)
end