Class: ODF::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/odf/converter.rb,
lib/odf/converter/version.rb,
lib/odf/converter/families.rb,
lib/odf/converter/filters/export.rb,
lib/odf/converter/filters/import.rb,
lib/odf/converter/filters/base_filter.rb

Defined Under Namespace

Modules: Families, Filters Classes: DocumentConversionError

Constant Summary collapse

VERSION =
"0.0.3"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConverter

Returns a new instance of Converter.



16
17
18
19
20
21
# File 'lib/odf/converter.rb', line 16

def initialize
  config = ODF.config
  @ctx = Uno::Connector.bootstrap(config.office_bin.to_s, config.connection_type.to_s, config.host.to_s, config.port)
  @smgr = @ctx.getServiceManager
  @desktop = @smgr.createInstanceWithContext("com.sun.star.frame.Desktop", @ctx)
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



14
15
16
# File 'lib/odf/converter.rb', line 14

def ctx
  @ctx
end

#desktopObject (readonly)

Returns the value of attribute desktop.



14
15
16
# File 'lib/odf/converter.rb', line 14

def desktop
  @desktop
end

#documentObject (readonly)

Returns the value of attribute document.



14
15
16
# File 'lib/odf/converter.rb', line 14

def document
  @document
end

#smgrObject (readonly)

Returns the value of attribute smgr.



14
15
16
# File 'lib/odf/converter.rb', line 14

def smgr
  @smgr
end

Class Method Details

.convert(*args) ⇒ Object



42
43
44
# File 'lib/odf/converter.rb', line 42

def self.convert(*args)
  new.convert(*args)
end

Instance Method Details

#convert(infile, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/odf/converter.rb', line 23

def convert(infile, options = {})
  raise ArgumentError, "to option must be provided." unless options[:to]
  
  if options[:to].is_a? Symbol #and Filters::Export[options[:to]]
    outfile = get_output_name(infile, options[:to])
  elsif options[:to].is_a? String
    raise DocumentConversionError, "#{options[:to]} doesn't specify an extension" if File.extname(options[:to]).empty?
    outfile = File.expand_path(options[:to])
  else
    raise DocumentConversionError, "not given a valid destination"
  end
  
  perform_conversion(infile, outfile) && outfile
end

#inspectObject



38
39
40
# File 'lib/odf/converter.rb', line 38

def inspect
  "#<#{self.class.name} #{self.class.config.office_bin}@#{self.class.config.host}:#{self.class.config.port}>"
end