Module: Psychgus::Stylables::NoSymStylable

Includes:
Psychgus::Styler
Included in:
Psychgus::Stylers::NoSymStyler
Defined in:
lib/psychgus/stylables.rb

Overview

A Symbol remover for Scalars.

Examples:

require 'psychgus'

data = {
  :eggs => {
    :styles => ['Fried', 'Scrambled', ['BBQ', 'Ketchup']],
    :colors => ['Brown', 'White', ['Blue', 'Green']]
}}

flow = Psychgus::FlowStyler.new(4)

puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new,flow])

# Output:
# ---
# Eggs:
#   Styles: [Fried, Scrambled, [BBQ, Ketchup]]
#   Colors: [Brown, White, [Blue, Green]]

puts data.to_yaml(stylers: [Psychgus::NoSymStyler.new(cap: false),flow])

# ---
# eggs:
#   styles: [Fried, Scrambled, [BBQ, Ketchup]]
#   colors: [Brown, White, [Blue, Green]]

See Also:

Since:

  • 1.2.0

Constant Summary

Constants included from Psychgus::Styler

Psychgus::Styler::EMPTY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Psychgus::Styler

#style, #style_alias, #style_document, #style_mapping, #style_sequence, #style_stream

Instance Attribute Details

#captrue, false Also known as: cap?

Returns whether to capitalize the symbol.

Returns:

  • (true, false)

    whether to capitalize the symbol

Since:

  • 1.2.0



211
212
213
# File 'lib/psychgus/stylables.rb', line 211

def cap
  @cap
end

Instance Method Details

#initialize(cap: true, **kargs) ⇒ Object

Parameters:

  • cap (true, false) (defaults to: true)

    whether to capitalize the symbol

  • kargs (Hash)

    capture extra keyword args, so no error for undefined args

Since:

  • 1.2.0



217
218
219
# File 'lib/psychgus/stylables.rb', line 217

def initialize(cap: true,**kargs)
  @cap = cap
end

#style_scalar(sniffer, node) ⇒ Object

If node.value is a symbol, change it into a string and capitalize it.

See Also:

Since:

  • 1.2.0



224
225
226
227
228
229
230
# File 'lib/psychgus/stylables.rb', line 224

def style_scalar(sniffer,node)
  return if node.value.nil?() || node.value.empty?()
  return if node.value[0] != ':'
  
  node.value = node.value[1..-1]
  node.value = node.value.capitalize() if @cap
end