Sha256: 0555d8a4bf25ce1b7c2fc26b463d1666e86f04f53864e61797b7abd907e68366

Contents?: true

Size: 814 Bytes

Versions: 28

Compression:

Stored size: 814 Bytes

Contents

module Description
  class Text < Treetop::Runtime::SyntaxNode
    include Enumerable
    def each
      elements.map { |e| e.to_s }.each { |tag| yield tag }
    end
    
    def join(sep = "\n")
      outdent.join(sep).strip
    end
    
    def to_s
      join
    end
    
    def excerpt
      
    end
    
    def inspect
      text = truncate(15).gsub(/\n/, " ").strip.inspect
      "#<#{self.class} #{text}>"
    end
    
    def truncate(num = 30)
      to_s.length < num ? to_s : to_s.slice(0..num) << "..."
    end
    
    def outdent
      range = tab_length..-1
      map { |l| l.slice(range) }
    end
    
    private
      def tab_length
        reject { |l| l =~ /^\s*$/ }.map do |line|
          line = line.slice(/^\s*/)
          line ? line.length : 0
        end.min || 0
      end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
distil-0.14.4 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.3 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.2 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.2.a vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.1 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.1.a vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.i vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.h vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.g vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.d vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.c vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.14.0.b vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.6 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.5 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.4 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.3 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.2 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.1 vendor/pdoc/lib/pdoc/parser/description_nodes.rb
distil-0.13.0 vendor/pdoc/lib/pdoc/parser/description_nodes.rb