class Rabbit::ImageManipulable::Dia

Constants

DIA_COMMANDS

Public Class Methods

new(filename, keep_ratio) click to toggle source
Calls superclass method Rabbit::ImageManipulable::Base.new
# File lib/rabbit/image/dia.rb, line 38
def initialize(filename, keep_ratio)
  init_svg_loader(filename, keep_ratio)
  super
end

Public Instance Methods

match?(filename) click to toggle source
# File lib/rabbit/image/dia.rb, line 18
def match?(filename)
  return true if File.extname(filename).downcase.end_with?(".dia")
  File.open(filename) do |f|
    first_line = f.gets
    second_line = f.gets
    return false unless second_line
    return false unless first_line.start_with?("<?xml")
    return false unless second_line.start_with?("<dia:diagram")
    true
  end
end

Private Instance Methods

init_svg_loader(filename, keep_ratio) click to toggle source
# File lib/rabbit/image/dia.rb, line 44
def init_svg_loader(filename, keep_ratio)
  @svg_file = Tempfile.new(["rabbit-loader-dia", ".svg"])
  args = ["--export=#{@svg_file.path}"]
  args << "--filter=svg"
  args << filename
  if DIA_COMMANDS.any? {|dia| run(dia, *args)}
    @svg_loader = SVG.new(@svg_file.path, keep_ratio)
  else
    raise DiaCanNotHandleError.new("dia #{args.join(' ')}",
                                   DIA_COMMANDS)
  end
end
load_image() click to toggle source
# File lib/rabbit/image/dia.rb, line 57
def load_image
  # do nothing
end