class YARD::Serializers::StdoutSerializer

A serializer that writes data to standard output.

Public Class Methods

new(wrap = nil) click to toggle source

Creates a serializer to print text to stdout

@param [Fixnum, nil] wrap if wrap is a number, wraps text to wrap

columns, otherwise no wrapping is done.
# File lib/yard/serializers/stdout_serializer.rb, line 10
def initialize(wrap = nil)
  @wrap = wrap
end

Public Instance Methods

serialize(_object, data) click to toggle source

Overrides serialize behaviour to write data to standard output

# File lib/yard/serializers/stdout_serializer.rb, line 15
def serialize(_object, data)
  print(@wrap ? word_wrap(data, @wrap) : data)
end

Private Instance Methods

word_wrap(text, _length = 80) click to toggle source

Wraps text to a specific column length

@param [String] text the text to wrap @param [Fixnum] _length the column length to wrap to @return [String] the wrapped text

# 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