module Psychgus::Styler

Mix in (include) this module to make a class/module/etc. a styler for YAML.

Although it's unnecessary (because of Duck Typing), it's the recommended practice in case a new method is added in the future, and also so you don't have to define methods that you don't use.

You can either use this as is (see example) or inside of a class (see {Blueberry}).

@example

class MyStyler
  include Psychgus::Styler

  def style_sequence(sniffer,node)
    node.style = Psychgus::SEQUENCE_FLOW if sniffer.level == 3
  end
end

hash = {'Coffee'=>{
          'Roast'=>['Light','Medium','Dark','Extra Dark'],
          'Style'=>['Cappuccino','Espresso','Latte','Mocha']
       }}
puts hash.to_yaml(stylers: MyStyler.new())

# Output:
# ---
# Coffee:
#   Roast: [Light, Medium, Dark, Extra Dark]
#   Style: [Cappuccino, Espresso, Latte, Mocha]

@author Jonathan Bradley Whited @since 1.0.0

@see Psychgus @see Ext::ObjectExt#to_yaml @see Blueberry @see StyledTreeBuilder#initialize @see StyledDocumentStream#initialize @see Ext::YAMLTreeExt#accept

Constants

EMPTY

Public Instance Methods

style(sniffer,node) click to toggle source

Style a node of any type.

You can use {Ext::NodeExt#node_of?} to determine its type:

puts node.value if node.node_of?(:scalar)

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Node] passed in from {StyledTreeBuilder}

@see Ext::NodeExt#node_of?

# File lib/psychgus/styler.rb, line 78
def style(sniffer,node) end
style_alias(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Alias, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Alias] of type Alias passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 84
def style_alias(sniffer,node) end
style_document(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Document, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Document] of type Document passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 90
def style_document(sniffer,node) end
style_mapping(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Mapping, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Mapping] of type Mapping passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 96
def style_mapping(sniffer,node) end
style_scalar(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Scalar, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Scalar] of type Scalar passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 102
def style_scalar(sniffer,node) end
style_sequence(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Sequence, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Sequence] of type Sequence passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 108
def style_sequence(sniffer,node) end
style_stream(sniffer,node) click to toggle source

Style a node guaranteed to be of type Psych::Nodes::Stream, to avoid if statements.

@param sniffer [SuperSniffer] passed in from {StyledTreeBuilder} @param node [Psych::Nodes::Stream] of type Stream passed in from {StyledTreeBuilder}

# File lib/psychgus/styler.rb, line 114
def style_stream(sniffer,node) end