Class: RDoc::Markup::ListItem

Inherits:
Element
  • Object
show all
Defined in:
lib/rdoc/markup/list_item.rb

Overview

An item within a List that contains paragraphs, headings, etc.

For BULLET, NUMBER, LALPHA and UALPHA lists, the label will always be nil. For NOTE and LABEL lists, the list label may contain:

  • a single String for a single label
  • an Array of Strings for a list item with multiple terms
  • nil for an extra description attached to a previously labeled list item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = nil, *parts) ⇒ ListItem

Creates a new ListItem with an optional label containing parts : ((Array | String)?, *untyped) -> void



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

def initialize(label = nil, *parts)
  @label = label
  @parts = parts
end

Instance Attribute Details

#label ⇒ Object

The label for the ListItem : (Array | String)?



16
17
18
# File 'lib/rdoc/markup/list_item.rb', line 16

def label
  @label
end

#parts ⇒ Object (readonly)

Parts of the ListItem : Array



20
21
22
# File 'lib/rdoc/markup/list_item.rb', line 20

def parts
  @parts
end

Instance Method Details

#<<(part) ⇒ Object

Appends part to the ListItem : (untyped) -> void



31
32
33
# File 'lib/rdoc/markup/list_item.rb', line 31

def <<(part)
  @parts << part
end

#==(other) ⇒ Object

: (top) -> bool



36
37
38
39
40
# File 'lib/rdoc/markup/list_item.rb', line 36

def ==(other) # :nodoc:
  self.class == other.class &&
    @label == other.label &&
    @parts == other.parts
end

#accept(visitor) ⇒ Object

Runs this list item and all its #parts through visitor : (untyped) -> void



45
46
47
48
49
# File 'lib/rdoc/markup/list_item.rb', line 45

def accept(visitor)
  visitor.accept_list_item_start(self)
  @parts.each { |part| part.accept(visitor) }
  visitor.accept_list_item_end(self)
end

#empty? ⇒ Boolean

Is the ListItem empty? : () -> bool

Returns:

  • (Boolean)


53
54
55
# File 'lib/rdoc/markup/list_item.rb', line 53

def empty?
  @parts.empty?
end

#length ⇒ Object

Length of parts in the ListItem : () -> Integer



59
60
61
# File 'lib/rdoc/markup/list_item.rb', line 59

def length
  @parts.length
end

#pretty_print(q) ⇒ Object

: (PP) -> void



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/rdoc/markup/list_item.rb', line 65

def pretty_print(q) # :nodoc:
  q.group(2, '[item: ', ']') do
    case @label
    when Array, String
      q.pp(@label)
      q.text(';')
      q.breakable
    end

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

#push(*parts) ⇒ Object

Adds parts to the ListItem : (*untyped) -> void



82
83
84
# File 'lib/rdoc/markup/list_item.rb', line 82

def push(*parts)
  @parts.concat(parts)
end