class EpubForge::Utils::Converter
TODO: Starting to get the feeling that an HtmlTranslator
is just a subtype of Converter
.
Public Class Methods
all()
click to toggle source
# File lib/epubforge/utils/converter.rb, line 13 def self.all self.loader_pattern_registry end
converts( input_format, output_format = :any )
click to toggle source
# File lib/epubforge/utils/converter.rb, line 17 def self.converts( input_format, output_format = :any ) self.all.select{ |k,v| if v.input_format == input_format output_format == :any || v.output_format == output_format else false end }.values end
new( &block )
click to toggle source
# File lib/epubforge/utils/converter.rb, line 27 def initialize( &block ) instance_exec( &block ) @command ||= "{{x}} {{o}} '{{src}}' '{{dst}}'" # default self end
Public Instance Methods
convert( src, opts = {} )
click to toggle source
opts {
:dest => Destination (output) file, :command_line_options => Arguments to feed to the executable. Just a string, replaces the {{o}} in @command
}
# File lib/epubforge/utils/converter.rb, line 67 def convert( src, opts = {} ) src = src.fwf_filepath dst = opts[:dest].is_a?(String) ? opts[:dest].fwf_filepath : opts[:dest] if dst.nil? dst = src.gsub( /#{@input_format}$/, @output_format.to_s ) end if is_executable_installed? if src.file? cmd = command.gsub("{{x}}", executable.to_s).gsub("{{o}}", opts[:command_line_options]).gsub("{{src}}", src).gsub("{{dst}}", dst) puts "running command : #{cmd}" `#{cmd}` $?.success? else warn( "Source file #{src} does not exist.".paint(:red,:bold)) false end else false end end
is_executable_installed?()
click to toggle source
def label( lbl = nil )
@label = lbl unless lbl.nil? @label
end
def from( fmt = nil)
@src_format = fmt unless fmt.nil? @src_format
end
def to( fmt = nil)
@dst_format = fmt unless fmt.nil? @dst_format
end
def executable( executable_name = nil )
@executable_name = executable_name unless executable_name.nil? @executable_name
end
# File lib/epubforge/utils/converter.rb, line 53 def is_executable_installed? @executable && `which #{executable}`.strip.fwf_blank? == false end