Class: WritersRoom::Formatters::BaseFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/writers_room/formatters/base_formatter.rb

Overview

Base class for medium-specific output formatters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path) ⇒ BaseFormatter

Returns a new instance of BaseFormatter.



9
10
11
12
13
# File 'lib/writers_room/formatters/base_formatter.rb', line 9

def initialize(project_path)
  @project_path = File.expand_path(project_path)
       = .new(@project_path)
  @medium       = MediumRegistry.find(.medium.to_sym) rescue MediumRegistry.find(:dialog)
end

Instance Attribute Details

#mediumObject (readonly)

Returns the value of attribute medium.



7
8
9
# File 'lib/writers_room/formatters/base_formatter.rb', line 7

def medium
  @medium
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/writers_room/formatters/base_formatter.rb', line 7

def 
  
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



7
8
9
# File 'lib/writers_room/formatters/base_formatter.rb', line 7

def project_path
  @project_path
end

Instance Method Details

#export(output_path) ⇒ Object



23
24
25
26
27
# File 'lib/writers_room/formatters/base_formatter.rb', line 23

def export(output_path)
  content = format
  File.write(output_path, content)
  output_path
end

#formatObject



15
16
17
18
19
20
21
# File 'lib/writers_room/formatters/base_formatter.rb', line 15

def format
  sections = []
  sections << title_page
  sections << table_of_contents
  sections.concat(body_sections)
  sections.compact.join("\n\n---\n\n")
end