123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Markup::ListItem

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Element
Instance Chain:
self, Element
Inherits: RDoc::Markup::Element
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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Element - Inherited

#accept

: (untyped) -> void.

#pretty_print

: (PP) -> void.

Constructor Details

.new(label = nil, *parts) ⇒ ListItem

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

[ GitHub ]

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

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

Instance Attribute Details

#empty? ⇒ Boolean (readonly)

Is the ListItem empty? : () -> bool

[ GitHub ]

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

def empty?
  @parts.empty?
end

#label (rw)

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

[ GitHub ]

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

attr_accessor :label

#parts (readonly)

Parts of the ListItem : Array

[ GitHub ]

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

attr_reader :parts

Instance Method Details

#<<(part)

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

[ GitHub ]

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

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

#==(other)

This method is for internal use only.

: (top) -> bool

[ GitHub ]

  
# 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)

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

[ GitHub ]

  
# 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

#length

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

[ GitHub ]

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

def length
  @parts.length
end

#pretty_print(q)

This method is for internal use only.

: (PP) -> void

[ GitHub ]

  
# 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)

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

[ GitHub ]

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

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