Sha256: c66efe7e1f91615c869a168758476f8aaeb924b4f05c52e3d7f83162724409f1

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

# frozen_string_literal: true

module Tocer
  module Elements
    # Represents a table of contents start and finish comment block.
    class CommentBlock
      def initialize start_id: "Tocer[start]",
                     finish_id: "Tocer[finish]",
                     message: "Auto-generated, don't remove."

        @start_id = start_id
        @finish_id = finish_id
        @message = message
      end

      def start
        comment start_id, message
      end

      def start_index collection
        index collection, start_id
      end

      def finish
        comment finish_id, message
      end

      def finish_index collection
        index collection, finish_id
      end

      private

      attr_reader :start_id, :finish_id, :message

      def comment id, message
        "<!-- #{id}: #{message} -->"
      end

      def index collection, id
        collection.index { |line| line =~ /\<\!\-\-.*#{Regexp.escape id}.*\-\-\>/ }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tocer-4.0.0 lib/tocer/elements/comment_block.rb