Sha256: 3d4822d4368d64dc76da9654c00a705536eb7b633a6b8102ad884af3c9677b99

Contents?: true

Size: 1001 Bytes

Versions: 7

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

module Tocer
  module Elements
    # Represents a table of contents start and finish comment block.
    class CommentBlock
      def self.index lines, id
        (lines.index { |line| line =~ /<!--.*#{Regexp.escape id}.*-->/ }).to_i
      end

      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_index(lines) = self.class.index(lines, start_id)

      def start_tag = comment(start_id, message)

      def finish_index(lines) = self.class.index(lines, finish_id)

      def finish_tag = comment(finish_id, message)

      def prependable?(lines) = start_index(lines).zero? && finish_index(lines).zero?

      private

      attr_reader :start_id, :finish_id, :message

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tocer-12.2.0 lib/tocer/elements/comment_block.rb
tocer-12.1.0 lib/tocer/elements/comment_block.rb
tocer-12.0.4 lib/tocer/elements/comment_block.rb
tocer-12.0.3 lib/tocer/elements/comment_block.rb
tocer-12.0.2 lib/tocer/elements/comment_block.rb
tocer-12.0.1 lib/tocer/elements/comment_block.rb
tocer-12.0.0 lib/tocer/elements/comment_block.rb