Class: WritersRoom::Formatters::NovelFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- WritersRoom::Formatters::NovelFormatter
- Defined in:
- lib/writers_room/formatters/novel_formatter.rb
Overview
Formats a novel project into a manuscript-style document.
Instance Attribute Summary
Attributes inherited from BaseFormatter
#medium, #metadata, #project_path
Instance Method Summary collapse
Methods inherited from BaseFormatter
Constructor Details
This class inherits a constructor from WritersRoom::Formatters::BaseFormatter
Instance Method Details
#body_sections ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/writers_room/formatters/novel_formatter.rb', line 18 def body_sections sections = [] # Characters section characters = load_elements("characters") if characters.any? sections << format_characters(characters) end # Chapters chapters = load_elements("chapters") chapters.sort_by { |c| c.[:chapter_number] || c.["chapter_number"] || 0 }.each do |ch| sections << format_chapter(ch) end sections end |
#table_of_contents ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/writers_room/formatters/novel_formatter.rb', line 7 def table_of_contents chapters = load_elements("chapters") return nil if chapters.empty? lines = ["## Table of Contents\n"] chapters.sort_by { |c| c.[:chapter_number] || c.["chapter_number"] || 0 }.each_with_index do |ch, i| lines << "#{i + 1}. #{ch.name}" end lines.join("\n") end |