Class: Tocer::Elements::CommentBlock
- Inherits:
-
Object
- Object
- Tocer::Elements::CommentBlock
- 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
- #comments ⇒ Object
- #empty?(lines) ⇒ Boolean
- #finish_index(lines) ⇒ Object
- #finish_tag ⇒ Object
-
#initialize(start_id: "Tocer[start]", finish_id: "Tocer[finish]", message: "Auto-generated, don't remove.") ⇒ CommentBlock
constructor
A new instance of CommentBlock.
- #prependable?(lines) ⇒ Boolean
- #start_index(lines) ⇒ Object
- #start_tag ⇒ Object
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 = 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
#comments ⇒ Object
20 |
# File 'lib/tocer/elements/comment_block.rb', line 20 def comments = "#{start_tag}\n#{finish_tag}\n" |
#empty?(lines) ⇒ 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_tag ⇒ Object
28 |
# File 'lib/tocer/elements/comment_block.rb', line 28 def finish_tag = comment(finish_id, ) |
#prependable?(lines) ⇒ 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_tag ⇒ Object
24 |
# File 'lib/tocer/elements/comment_block.rb', line 24 def start_tag = comment(start_id, ) |