Class: Tocer::Writer
- Inherits:
-
Object
- Object
- Tocer::Writer
- Defined in:
- lib/tocer/writer.rb
Overview
Writes table of contents to a Markdown document.
Instance Method Summary collapse
-
#initialize(file_path, label: "# Table of Contents", builder: Builder, comment_block: Elements::CommentBlock) ⇒ Writer
constructor
rubocop:disable Metrics/ParameterLists.
- #write ⇒ Object
Constructor Details
#initialize(file_path, label: "# Table of Contents", builder: Builder, comment_block: Elements::CommentBlock) ⇒ Writer
rubocop:disable Metrics/ParameterLists
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tocer/writer.rb', line 7 def initialize file_path, label: "# Table of Contents", builder: Builder, comment_block: Elements::CommentBlock @file_path = file_path @file_lines = File.open(file_path).to_a @label = label @builder = builder setup_indexes comment_block.new, @file_lines end |
Instance Method Details
#write ⇒ Object
19 20 21 22 |
# File 'lib/tocer/writer.rb', line 19 def write body = start_index ? replace_toc : prepend_toc File.open(file_path, "w") { |file| file.write body } end |