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
climine-0.0.2 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
climine-0.0.1 vendor/bundle/ruby/2.0.0/gems/yard-0.8.7.3/lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.3 lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.2 lib/yard/serializers/stdout_serializer.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/yard-0.8.7/lib/yard/serializers/stdout_serializer.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/yard-0.8.7/lib/yard/serializers/stdout_serializer.rb
candlepin-api-0.4.0 bundle/ruby/gems/yard-0.8.7/lib/yard/serializers/stdout_serializer.rb
yard-0.8.7.1 lib/yard/serializers/stdout_serializer.rb
yard-0.8.7 lib/yard/serializers/stdout_serializer.rb
challah-1.0.0 vendor/bundle/gems/yard-0.8.6.1/lib/yard/serializers/stdout_serializer.rb
yard-0.8.6.2 lib/yard/serializers/stdout_serializer.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.5.2/lib/yard/serializers/stdout_serializer.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6/lib/yard/serializers/stdout_serializer.rb
challah-1.0.0.beta3 vendor/bundle/gems/yard-0.8.6.1/lib/yard/serializers/stdout_serializer.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/serializers/stdout_serializer.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/serializers/stdout_serializer.rb
yard-0.8.6.1 lib/yard/serializers/stdout_serializer.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.5.2/lib/yard/serializers/stdout_serializer.rb
challah-1.0.0.beta2 vendor/bundle/gems/yard-0.8.6/lib/yard/serializers/stdout_serializer.rb
yard-0.8.6 lib/yard/serializers/stdout_serializer.rb