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
challah-rolls-0.1.0 vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.8.0.pre vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.7.1 vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.7.0 vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.7.0.pre2 vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.7.0.pre vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.6.2 vendor/bundle/gems/yard-0.8.2.1/lib/yard/serializers/stdout_serializer.rb
challah-0.6.2 vendor/bundle/gems/yard-0.8.2/lib/yard/serializers/stdout_serializer.rb
challah-0.6.2 vendor/bundle/gems/yard-0.8.1/lib/yard/serializers/stdout_serializer.rb
challah-0.6.2 vendor/bundle/gems/yard-0.7.5/lib/yard/serializers/stdout_serializer.rb
yard-0.8.2.1 lib/yard/serializers/stdout_serializer.rb
challah-0.6.1 vendor/bundle/gems/yard-0.8.2/lib/yard/serializers/stdout_serializer.rb
challah-0.6.1 vendor/bundle/gems/yard-0.7.5/lib/yard/serializers/stdout_serializer.rb
challah-0.6.1 vendor/bundle/gems/yard-0.8.1/lib/yard/serializers/stdout_serializer.rb
yard-0.8.2 lib/yard/serializers/stdout_serializer.rb
challah-0.6.0 vendor/bundle/gems/yard-0.7.5/lib/yard/serializers/stdout_serializer.rb
challah-0.6.0 vendor/bundle/gems/yard-0.8.1/lib/yard/serializers/stdout_serializer.rb
yard-0.8.1 lib/yard/serializers/stdout_serializer.rb
yard-0.8.0 lib/yard/serializers/stdout_serializer.rb
challah-0.5.4 vendor/bundle/gems/yard-0.7.5/lib/yard/serializers/stdout_serializer.rb