Sha256: c7b8f53e7cf04e137cd4b7930115ab1f32a065abbcb7d3cefc9b0ed352f24bfe

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

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
      end

      def start_tag
        comment start_id, message
      end

      def finish_index lines
        self.class.index lines, finish_id
      end

      def finish_tag
        comment finish_id, message
      end

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

      private

      attr_reader :start_id, :finish_id, :message

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tocer-10.1.1 lib/tocer/elements/comment_block.rb
tocer-10.1.0 lib/tocer/elements/comment_block.rb
tocer-10.0.1 lib/tocer/elements/comment_block.rb
tocer-10.0.0 lib/tocer/elements/comment_block.rb
tocer-9.1.2 lib/tocer/elements/comment_block.rb
tocer-9.1.1 lib/tocer/elements/comment_block.rb
tocer-9.1.0 lib/tocer/elements/comment_block.rb
tocer-9.0.0 lib/tocer/elements/comment_block.rb
tocer-8.2.1 lib/tocer/elements/comment_block.rb
tocer-8.2.0 lib/tocer/elements/comment_block.rb
tocer-8.1.0 lib/tocer/elements/comment_block.rb
tocer-8.0.0 lib/tocer/elements/comment_block.rb
tocer-7.2.0 lib/tocer/elements/comment_block.rb
tocer-7.1.0 lib/tocer/elements/comment_block.rb
tocer-7.0.2 lib/tocer/elements/comment_block.rb
tocer-7.0.1 lib/tocer/elements/comment_block.rb
tocer-7.0.0 lib/tocer/elements/comment_block.rb
tocer-6.3.1 lib/tocer/elements/comment_block.rb
tocer-6.3.0 lib/tocer/elements/comment_block.rb
tocer-6.2.0 lib/tocer/elements/comment_block.rb