Class: RDoc::Markup::Verbatim

Inherits:
Raw
  • Object
show all
Defined in:
lib/rdoc/markup/verbatim.rb

Overview

A section of verbatim text

Instance Attribute Summary collapse

Attributes inherited from Raw

#parts

Instance Method Summary collapse

Methods inherited from Raw

#<<, #merge, #push

Constructor Details

#initialize(*parts) ⇒ Verbatim

:nodoc:



12
13
14
15
16
# File 'lib/rdoc/markup/verbatim.rb', line 12

def initialize *parts # :nodoc:
  super

  @format = nil
end

Instance Attribute Details

#formatObject

Format of this verbatim section



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

def format
  @format
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



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

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

#accept(visitor) ⇒ Object

Calls #accept_verbatim on visitor



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

def accept visitor
  visitor.accept_verbatim self
end

#normalizeObject

Collapses 3+ newlines into two newlines



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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) ⇒ Object

:nodoc:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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

#ruby?Boolean

Is this verbatim section Ruby code?

Returns:

  • (Boolean)


71
72
73
74
# 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

#textObject

The text of the section



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

def text
  @parts.join
end