123456789_123456789_123456789_123456789_123456789_

Class: YARD::Serializers::StdoutSerializer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base
Inherits: YARD::Serializers::Base
Defined in: lib/yard/serializers/stdout_serializer.rb

Overview

A serializer that writes data to standard output.

Class Method Summary

Base - Inherited

.new

Creates a new serializer with options.

Instance Attribute Summary

Base - Inherited

#options

All serializer options are saved so they can be passed to other serializers.

Instance Method Summary

Base - Inherited

#after_serialize

Called after serialization.

#before_serialize

Called before serialization.

#exists?

Returns whether an object has been serialized.

#serialize

Serializes an object.

#serialized_path

The serialized path of an object.

Constructor Details

.new(wrap = nil) ⇒ StdoutSerializer

Creates a serializer to print text to stdout

Parameters:

  • wrap (Fixnum, nil) (defaults to: nil)

    if wrap is a number, wraps text to wrap columns, otherwise no wrapping is done.

[ GitHub ]

  
# File 'lib/yard/serializers/stdout_serializer.rb', line 10

def initialize(wrap = nil)
  @wrap = wrap
end

Instance Method Details

#serialize(_object, data)

Overrides serialize behaviour to write data to standard output

[ GitHub ]

  
# File 'lib/yard/serializers/stdout_serializer.rb', line 15

def serialize(_object, data)
  print(@wrap ? word_wrap(data, @wrap) : data)
end

#word_wrap(text, _length = 80) ⇒ String (private)

Wraps text to a specific column length

Parameters:

  • text (String)

    the text to wrap

  • _length (Fixnum) (defaults to: 80)

    the column length to wrap to

Returns:

  • (String)

    the wrapped text

[ GitHub ]

  
# File 'lib/yard/serializers/stdout_serializer.rb', line 26

def word_wrap(text, _length = 80)
  # See ruby-talk/10655 / Ernest Ellingson
  text.gsub(/\t/, "     ").gsub(/.{1,50}(?:\s|\Z)/) do
    ($& + 5.chr).gsub(/\n\005/, "\n").gsub(/\005/, "\n")
  end
end