Sha256: 127c74fd018f6b574b84f5301674ed62438df320711cad40e3200a1d77198547

Contents?: true

Size: 996 Bytes

Versions: 106

Compression:

Stored size: 996 Bytes

Contents

module YARD
  module Serializers
    # A serializer that writes data to standard output.
    class StdoutSerializer < Base
      # 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.
      def initialize(wrap = nil)
        @wrap = wrap
      end

      # Overrides serialize behaviour to write data to standard output
      def serialize(object, data)
        print(@wrap ? word_wrap(data, @wrap) : data)
      end

      private

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

Version data entries

106 entries across 86 versions & 10 rubygems

Version Path
abaci-0.3.0 vendor/bundle/gems/yard-0.9.2/lib/yard/serializers/stdout_serializer.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.1/lib/yard/serializers/stdout_serializer.rb
yard-0.9.5 lib/yard/serializers/stdout_serializer.rb
yard-0.9.4 lib/yard/serializers/stdout_serializer.rb
yard-0.9.3 lib/yard/serializers/stdout_serializer.rb
yard-0.9.2 lib/yard/serializers/stdout_serializer.rb
yard-0.9.1 lib/yard/serializers/stdout_serializer.rb
yard-0.9.0 lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.6 lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.5 lib/yard/serializers/stdout_serializer.rb
climine-0.0.7 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
climine-0.0.7 vendor/bundle/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
climine-0.0.6 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
climine-0.0.5 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.4 lib/yard/serializers/stdout_serializer.rb
climine-0.0.4 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
climine-0.0.3 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb