Sha256: 64163362ef777fb2e506892fbbf67f7f0ba6a30649475f644ddea1e77a42bd97

Contents?: true

Size: 1.71 KB

Versions: 19

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true
##
# 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 RDoc::Markup::ListItem

  ##
  # The label for the ListItem

  attr_accessor :label

  ##
  # Parts of the ListItem

  attr_reader :parts

  ##
  # Creates a new ListItem with an optional +label+ containing +parts+

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

  ##
  # Appends +part+ to the ListItem

  def << part
    @parts << part
  end

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

  ##
  # Runs this list item and all its #parts through +visitor+

  def accept visitor
    visitor.accept_list_item_start self

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

    visitor.accept_list_item_end self
  end

  ##
  # Is the ListItem empty?

  def empty?
    @parts.empty?
  end

  ##
  # Length of parts in the ListItem

  def length
    @parts.length
  end

  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

  ##
  # Adds +parts+ to the ListItem

  def push *parts
    @parts.concat parts
  end

end

Version data entries

19 entries across 17 versions & 7 rubygems

Version Path
rdoc-6.12.0 lib/rdoc/markup/list_item.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rdoc-6.11.0/lib/rdoc/markup/list_item.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.10.0/lib/rdoc/markup/list_item.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/rdoc-6.8.1/lib/rdoc/markup/list_item.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/rdoc-6.7.0/lib/rdoc/markup/list_item.rb
rdoc-6.11.0 lib/rdoc/markup/list_item.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/markup/list_item.rb
rdoc-6.10.0 lib/rdoc/markup/list_item.rb
rdoc-6.9.1 lib/rdoc/markup/list_item.rb
rdoc-6.9.0 lib/rdoc/markup/list_item.rb
rdoc-6.8.1 lib/rdoc/markup/list_item.rb
rdoc-6.8.0 lib/rdoc/markup/list_item.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/markup/list_item.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rdoc-6.7.0/lib/rdoc/markup/list_item.rb
rdoc-6.6.3.1 lib/rdoc/markup/list_item.rb
rdoc-6.6.2 lib/rdoc/markup/list_item.rb
rdoc-6.6.1 lib/rdoc/markup/list_item.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/rdoc-6.6.0/lib/rdoc/markup/list_item.rb
rdoc-6.6.0 lib/rdoc/markup/list_item.rb