Class: Proselytism::Converters::OpenOffice

Inherits:
Base
  • Object
show all
Defined in:
lib/proselytism/converters/open_office.rb

Defined Under Namespace

Modules: Bridges Classes: Error, Server

Instance Method Summary collapse

Methods inherited from Base

#convert, #destination_file_path, #execute

Instance Method Details

#perform(origin, options = {}) ⇒ Object

Converts documents



24
25
26
27
28
29
# File 'lib/proselytism/converters/open_office.rb', line 24

def perform(origin, options={})
  destination = destination_file_path(origin, options)
  command = "#{Proselytism::Converters::OpenOffice}::Bridges::#{config.oo_server_bridge}".constantize.command + " '#{origin}' '#{destination}' 2>&1"
  server.perform { execute(command) }
  destination
end

#perform_with_ensure_utf8(origin, options = {}) ⇒ Object

For unknown reason sometimes OpenOffice converts in ISO-8859-1, post process to ensure a conversion in UTF-8 when :to => :txt



33
34
35
36
37
38
39
40
41
42
# File 'lib/proselytism/converters/open_office.rb', line 33

def perform_with_ensure_utf8(origin, options={})
  destination = perform_without_ensure_utf8(origin, options)
  if options[:to].to_s == "txt" and `file #{destination}` =~ /ISO/
    #lookup_on = Iconv.new('ASCII//TRANSLIT','UTF-8').iconv(str).upcase.strip.gsub(/'/, " ")
    #log :warn, "***OOO has converted file in "
    tmp_iconv_file = "#{destination}-tmp_iconv.txt"
    execute("iconv --from-code ISO-8859-1 --to-code UTF-8 #{destination} > #{tmp_iconv_file} && mv #{tmp_iconv_file} #{destination}")
  end
  destination
end

#serverObject



46
47
48
# File 'lib/proselytism/converters/open_office.rb', line 46

def server
  Server.instance
end