Class: Psychgus::Stylers::CapStyler

Inherits:
Object
  • Object
show all
Includes:
Psychgus::Stylables::CapStylable
Defined in:
lib/psychgus/stylers.rb

Overview

A Capitalizer for Scalars.

Examples:

require 'psychgus'

data = {
  'eggs' => [
    'omelette',
    'BBQ eggs',
    'hard-boiled eggs',
    'soft_boiled eggs',
    'fried@eggs'
]}

seq_flow = Psychgus::SeqFlowStyler.new

puts data.to_yaml(stylers: [Psychgus::CapStyler.new,seq_flow])

# Output:
# ---
# Eggs: [Omelette, BBQ Eggs, Hard-Boiled Eggs, Soft_Boiled Eggs, Fried@eggs]

puts data.to_yaml(stylers: [Psychgus::CapStyler.new(each_word: false),seq_flow])

# Output:
# ---
# Eggs: [Omelette, BBQ eggs, Hard-boiled eggs, Soft_boiled eggs, Fried@eggs]

puts data.to_yaml(stylers: [Psychgus::CapStyler.new(new_delim: '(o)'),seq_flow])

# Output:
# ---
# Eggs: [Omelette, BBQ(o)Eggs, Hard(o)Boiled(o)Eggs, Soft(o)Boiled(o)Eggs, Fried@eggs]

class Cappie
  include Psychgus::CapStylable

  def cap_word(word)
    return 'bbq' if word.casecmp('BBQ') == 0

    super(word)
  end
end

puts data.to_yaml(stylers: [Cappie.new(new_delim: '*',delim: /[\s@]/),seq_flow])

# Output:
# ---
# Eggs: [Omelette, bbq*Eggs, Hard-boiled*Eggs, Soft_boiled*Eggs, Fried*Eggs]

See Also:

Since:

  • 1.2.0

Constant Summary

Constants included from Psychgus::Styler

Psychgus::Styler::EMPTY

Instance Attribute Summary

Attributes included from Psychgus::Stylables::CapStylable

#delim, #each_word, #new_delim

Method Summary

Methods included from Psychgus::Stylables::CapStylable

#cap_word, #initialize, #style_scalar

Methods included from Psychgus::Styler

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