Sha256: 07b5c64abd2412f31caf1194affb28e8272942bd0ee163da88006852ed22d6f2

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true
##
# We manage a set of attributes.  Each attribute has a symbol name and a bit
# value.

class RDoc::Markup::Attributes

  ##
  # The regexp handling attribute type. See RDoc::Markup#add_regexp_handling

  attr_reader :regexp_handling

  ##
  # Creates a new attributes set.

  def initialize
    @regexp_handling = 1

    @name_to_bitmap = [
      [:_REGEXP_HANDLING_, @regexp_handling],
    ]

    @next_bitmap = @regexp_handling << 1
  end

  ##
  # Returns a unique bit for +name+

  def bitmap_for name
    bitmap = @name_to_bitmap.assoc name

    unless bitmap then
      bitmap = @next_bitmap
      @next_bitmap <<= 1
      @name_to_bitmap << [name, bitmap]
    else
      bitmap = bitmap.last
    end

    bitmap
  end

  ##
  # Returns a string representation of +bitmap+

  def as_string bitmap
    return 'none' if bitmap.zero?
    res = []

    @name_to_bitmap.each do |name, bit|
      res << name if (bitmap & bit) != 0
    end

    res.join ','
  end

  ##
  # yields each attribute name in +bitmap+

  def each_name_of bitmap
    return enum_for __method__, bitmap unless block_given?

    @name_to_bitmap.each do |name, bit|
      next if bit == @regexp_handling

      yield name.to_s if (bitmap & bit) != 0
    end
  end

end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
rdoc-6.8.1 lib/rdoc/markup/attributes.rb
rdoc-6.8.0 lib/rdoc/markup/attributes.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rdoc-6.7.0/lib/rdoc/markup/attributes.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rdoc-6.7.0/lib/rdoc/markup/attributes.rb
rdoc-6.6.3.1 lib/rdoc/markup/attributes.rb
rdoc-6.6.2 lib/rdoc/markup/attributes.rb
rdoc-6.6.1 lib/rdoc/markup/attributes.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/rdoc-6.6.0/lib/rdoc/markup/attributes.rb
rdoc-6.6.0 lib/rdoc/markup/attributes.rb