Class: WritersRoom::Formatters::BaseFormatter
- Inherits:
-
Object
- Object
- WritersRoom::Formatters::BaseFormatter
- Defined in:
- lib/writers_room/formatters/base_formatter.rb
Overview
Base class for medium-specific output formatters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#medium ⇒ Object
readonly
Returns the value of attribute medium.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Instance Method Summary collapse
- #export(output_path) ⇒ Object
- #format ⇒ Object
-
#initialize(project_path) ⇒ BaseFormatter
constructor
A new instance of BaseFormatter.
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.(project_path) = ProjectMetadata.new(@project_path) @medium = MediumRegistry.find(.medium.to_sym) rescue MediumRegistry.find(:dialog) end |
Instance Attribute Details
#medium ⇒ Object (readonly)
Returns the value of attribute medium.
7 8 9 |
# File 'lib/writers_room/formatters/base_formatter.rb', line 7 def medium @medium end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/writers_room/formatters/base_formatter.rb', line 7 def end |
#project_path ⇒ Object (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 |
#format ⇒ Object
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 |