lib/fukuzatsu/formatters/base.rb in fukuzatsu-1.0.6 vs lib/fukuzatsu/formatters/base.rb in fukuzatsu-2.1.1
- old
+ new
@@ -1,32 +1,71 @@
-module Formatters
+module Fukuzatsu
- module Base
+ module Formatters
- def self.included(klass)
- klass.send(:attr_accessor, :file)
- klass.send(:attr_accessor, :source)
- klass.send(:attr_accessor, :output_directory)
- end
+ module Base
- def initialize(file, output_directory=nil, source="")
- self.file = file
- self.source = source
- self.output_directory = output_directory
- end
+ BASE_OUTPUT_DIRECTORY = "doc/fukuzatsu/"
- def filename
- File.basename(self.file.path_to_file) + file_extension
- end
+ def self.included(klass)
+ klass.send(:attr_accessor, :summary)
+ klass.send(:attr_accessor, :source)
+ klass.extend(ClassMethods)
+ end
- def output_path
- output_path = File.dirname(File.join(self.output_directory, self.file.path_to_file))
- FileUtils.mkpath(output_path)
- output_path
- end
+ def initialize(source: nil, summary:nil)
+ self.source = source
+ self.summary = summary
+ end
- def path_to_results
- File.join(output_path, filename)
+ def export
+ begin
+ File.open(path_to_results, 'w') {|outfile| outfile.write(content)}
+ rescue Exception => e
+ puts "Unable to write output: #{e} #{e.backtrace}"
+ end
+ end
+
+ def filename
+ File.basename(self.summary.source_file) + file_extension
+ end
+
+ def output_directory
+ BASE_OUTPUT_DIRECTORY + file_extension.gsub(".","")
+ end
+
+ def output_path
+ if self.summary
+ output_path = output_directory + "/" + File.dirname(self.summary.source_file)
+ FileUtils.mkpath(output_path)
+ else
+ output_path = File.dirname(output_directory)
+ end
+ output_path
+ end
+
+ def path_to_results
+ File.join(output_path, filename)
+ end
+
+ module ClassMethods
+
+ def index(summaries)
+ end
+
+ def reset_output_directory
+ directory = new.output_directory
+ begin
+ FileUtils.remove_dir(directory)
+ rescue Errno::ENOENT
+ end
+ FileUtils.mkpath(directory)
+ end
+
+ def explain(count)
+ puts "Processed #{count} file(s). Results written to #{new.output_directory}."
+ end
+ end
end
end
end