class GhostWriter::Document attr_reader :title, :description, :location, :url_example, :param_example, :status_example, :response_example, :output, :relative_path def initialize(output, attrs) format_module = "GhostWriter::Format::#{attrs[:format].to_s.classify}" extend(format_module.constantize) @output = output @relative_path = Pathname.new(output).relative_path_from(GhostWriter.output_path) @title = attrs[:title] @description = attrs[:description] @location = attrs[:location] @url_example = attrs[:url_example] @param_example = attrs[:param_example] @status_example = attrs[:status_example] @response_example = attrs[:response_example] end def write_file(overwrite = false) unless File.exist?(File.dirname(output)) FileUtils.mkdir_p(File.dirname(output)) end mode = overwrite ? "w" : "a" doc = File.open(output, mode) if overwrite doc.write paragraph(document_header) end doc.write(document_body) doc.close end def document_header <