Class: RDoc::Markup::ListItem

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

Overview

frozen_string_literal: false

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



27
28
29
30
31
# File 'lib/rdoc/markup/list_item.rb', line 27

def initialize label = nil, *parts
  @label = label
  @parts = []
  @parts.concat parts
end

Instance Attribute Details

#labelObject

The label for the ListItem



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

def label
  @label
end

#partsObject (readonly)

Parts of the ListItem



22
23
24
# File 'lib/rdoc/markup/list_item.rb', line 22

def parts
  @parts
end

Instance Method Details

#<<(part) ⇒ Object

Appends part to the ListItem



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

def << part
  @parts << part
end

#==(other) ⇒ Object

:nodoc:



40
41
42
43
44
# File 'lib/rdoc/markup/list_item.rb', line 40

def == other # :nodoc:
  self.class == other.class and
    @label == other.label and
    @parts == other.parts
end

#accept(visitor) ⇒ Object

Runs this list item and all its #parts through visitor



49
50
51
52
53
54
55
56
57
# File 'lib/rdoc/markup/list_item.rb', line 49

def accept visitor
  visitor.accept_list_item_start self

  @parts.each do |part|
    part.accept visitor
  end

  visitor.accept_list_item_end self
end

#empty?Boolean

Is the ListItem empty?

Returns:

  • (Boolean)


62
63
64
# File 'lib/rdoc/markup/list_item.rb', line 62

def empty?
  @parts.empty?
end

#lengthObject

Length of parts in the ListItem



69
70
71
# File 'lib/rdoc/markup/list_item.rb', line 69

def length
  @parts.length
end

#pretty_print(q) ⇒ Object

:nodoc:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rdoc/markup/list_item.rb', line 73

def pretty_print q # :nodoc:
  q.group 2, '[item: ', ']' do
    case @label
    when Array then
      q.pp @label
      q.text ';'
      q.breakable
    when String then
      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



95
96
97
# File 'lib/rdoc/markup/list_item.rb', line 95

def push *parts
  @parts.concat parts
end