Class: Tocer::Elements::CommentBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/tocer/elements/comment_block.rb

Overview

Represents a table of contents start and finish comment block.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_id: "Tocer[start]", finish_id: "Tocer[finish]", message: "Auto-generated, don't remove.") ⇒ CommentBlock

Returns a new instance of CommentBlock.



11
12
13
14
15
16
17
18
# File 'lib/tocer/elements/comment_block.rb', line 11

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

Class Method Details

.index(lines, id) ⇒ Object



7
8
9
# File 'lib/tocer/elements/comment_block.rb', line 7

def self.index lines, id
  (lines.index { |line| line =~ /<!--.*#{Regexp.escape id}.*-->/ }).to_i
end

Instance Method Details

#commentsObject



20
# File 'lib/tocer/elements/comment_block.rb', line 20

def comments = "#{start_tag}\n#{finish_tag}\n"

#empty?(lines) ⇒ Boolean

Returns:

  • (Boolean)


30
# File 'lib/tocer/elements/comment_block.rb', line 30

def empty?(lines) = (finish_index(lines) - start_index(lines)) == 1

#finish_index(lines) ⇒ Object



26
# File 'lib/tocer/elements/comment_block.rb', line 26

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

#finish_tagObject



28
# File 'lib/tocer/elements/comment_block.rb', line 28

def finish_tag = comment(finish_id, message)

#prependable?(lines) ⇒ Boolean

Returns:

  • (Boolean)


32
# File 'lib/tocer/elements/comment_block.rb', line 32

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

#start_index(lines) ⇒ Object



22
# File 'lib/tocer/elements/comment_block.rb', line 22

def start_index(lines) = self.class.index(lines, start_id)

#start_tagObject



24
# File 'lib/tocer/elements/comment_block.rb', line 24

def start_tag = comment(start_id, message)