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:



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

def initialize *parts # :nodoc:
  super

  @format = nil
end

Instance Attribute Details

#formatObject

Format of this verbatim section



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

def format
  @format
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



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

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

#accept(visitor) ⇒ Object

Calls #accept_verbatim on visitor



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

def accept visitor
  visitor.accept_verbatim self
end

#normalizeObject

Collapses 3+ newlines into two newlines



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rdoc/markup/verbatim.rb', line 31

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:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rdoc/markup/verbatim.rb', line 52

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)


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

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

#textObject

The text of the section



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

def text
  @parts.join
end