123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::Verbatim

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Raw
Instance Chain:
self, Raw
Inherits: RDoc::Markup::Raw
Defined in: lib/rdoc/markup/verbatim.rb

Overview

A section of verbatim text

Class Method Summary

Raw - Inherited

.new

Creates a new Raw containing parts

Instance Attribute Summary

Raw - Inherited

#parts

The component parts of the list.

Instance Method Summary

Raw - Inherited

#<<

Appends #text

#accept

Calls #accept_raw+ on visitor

#merge

Appends other‘s parts.

#push

Appends texts onto this Paragraph.

#text

The raw text.

#==, #pretty_print

Constructor Details

.new(*parts) ⇒ Verbatim

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 12

def initialize *parts # :nodoc:
  super

  @format = nil
end

Instance Attribute Details

#format (rw)

Format of this verbatim section

[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 10

attr_accessor :format

#ruby?Boolean (readonly)

Is this verbatim section Ruby code?

[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 71

def ruby?
  @format ||= nil # TODO for older ri data, switch the tree to marshal_dump
  @format == :ruby
end

Instance Method Details

#==(other)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 18

def == other # :nodoc:
  super and @format == other.format
end

#accept(visitor)

Calls #accept_verbatim on visitor

[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 25

def accept visitor
  visitor.accept_verbatim self
end

#normalize

Collapses 3+ newlines into two newlines

[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 32

def normalize
  parts = []

  newlines = 0

  @parts.each do |part|
    case part
    when /^\s*\n/ then
      newlines += 1
      parts << part if newlines == 1
    else
      newlines = 0
      parts << part
    end
  end

  parts.pop if parts.last =~ /\A\r?\n\z/

  @parts = parts
end

#pretty_print(q)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 53

def pretty_print q # :nodoc:
  self.class.name =~ /.*::(\w{1,4})/i

  q.group 2, "[#{$1.downcase}: ", ']' do
    if @format then
      q.text "format: #{@format}"
      q.breakable
    end

    q.seplist @parts do |part|
      q.pp part
    end
  end
end

#text

The text of the section

[ GitHub ]

  
# File 'lib/rdoc/markup/verbatim.rb', line 79

def text
  @parts.join
end