Sha256: 549e41d3b6f745a9e8d4090a518ad2717544f92f7f4fb1436eab5c9403ebf536

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module Tocer
  # Represents table of contents start and finish comments.
  class Commenter
    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
    end

    def finish
      comment finish_id, message
    end

    def finish_index collection
      index collection, finish
    end

    private

    attr_reader :start_id, :finish_id, :message

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

    def index collection, text
      collection.index { |line| line =~ /#{Regexp.escape text}/ }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tocer-0.1.0 lib/tocer/commenter.rb