class Fyodor::OutputWriter
Public Class Methods
new(book, output_dir, config)
click to toggle source
# File lib/fyodor/output_writer.rb, line 9 def initialize(book, output_dir, config) @book = book @output_dir = output_dir @config = config end
Public Instance Methods
write()
click to toggle source
# File lib/fyodor/output_writer.rb, line 15 def write output = OutputGenerator.new(@book, @config).output File.open(path, "w") { |f| f.puts(output) } end
Private Instance Methods
filename()
click to toggle source
# File lib/fyodor/output_writer.rb, line 23 def filename return @filename if defined?(@filename) filename = @config["filename"] % { author: @book.author, author_fill: @book.author.empty? ? SINGULAR[:AUTHOR_NA] : @book.author, title: @book.title } filename = filename.gsub(/[?*:|\/"<>]/,"_") Pathname.new(filename) end
path()
click to toggle source
# File lib/fyodor/output_writer.rb, line 36 def path result = @output_dir + filename i = 2 while(result.exist?) result = @output_dir + "#{filename.basename} - #{i}#{filename.extname}" i += 1 end result end