Class: DocverterServer::ConversionTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/docverter-server/conversion_types.rb

Constant Summary collapse

TYPES =
[
  # file extension, pandoc name, visible name, mime type, input, output
  ['asciidoc', 'asciidoc', 'AsciiDoc', 'application/octet-stream', false, true],
  ['docx', 'docx', 'Docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', false, true],
  ['doc', 'doc', 'Doc', 'application/msword', true, false],
  ['epub', 'epub', 'ePub', 'application/epub+zip',  false, true],
  ['groff', 'groff', 'Groff', 'application/x-troff', false, true],
  ['html', 'html', 'HTML', 'text/html', true, true],
  ['md', 'markdown', 'Markdown', 'application/octet-stream', true, true],
  ['org', 'orgmode', 'Emacs Org-Mode', 'application/octet-stream', false, true],
  ['mobi', 'mobi', 'Mobi', 'application/octet-stream', false, true],
  ['pdf', 'pdf', 'PDF', 'application/pdf', false, true],
  ['rtf', 'rtf', 'RTF', 'text/rtf', false, true],
  ['rst', 'rst', 'reStructured Text', 'application/octet-stream', true, true],
  ['tex', 'context', 'ConTeXt', 'application/octet-stream', false, true],
  ['tex', 'latex', 'LaTeX', 'application/octet-stream', true, true],
  ['texi', 'texinfo', 'TexInfo', 'application/octet-stream', false, true],
  ['textile', 'textile', 'Textile', 'application/octet-stream', true, true],
  ['wiki', 'mediawiki', 'MediaWiki', 'application/octet-stream', false, true],
  ['xml', 'docbook', 'DocBook', 'application/docbook+xml', false, true],
]

Class Method Summary collapse

Class Method Details

.extension(pandoc_name) ⇒ Object



25
26
27
# File 'lib/docverter-server/conversion_types.rb', line 25

def self.extension(pandoc_name)
  for_pandoc(pandoc_name)[0]
end

.for_extension(extension) ⇒ Object



37
38
39
# File 'lib/docverter-server/conversion_types.rb', line 37

def self.for_extension(extension)
  TYPES.find { |t| t[0].downcase == extension.downcase }
end

.for_pandoc(pandoc_name) ⇒ Object



33
34
35
# File 'lib/docverter-server/conversion_types.rb', line 33

def self.for_pandoc(pandoc_name)
  TYPES.find { |t| t[1].downcase == pandoc_name.downcase }
end

.inputsObject



41
42
43
# File 'lib/docverter-server/conversion_types.rb', line 41

def self.inputs
  TYPES.find_all { |t| t[4] == true }
end

.mime_type(pandoc_name) ⇒ Object



29
30
31
# File 'lib/docverter-server/conversion_types.rb', line 29

def self.mime_type(pandoc_name)
  for_pandoc(pandoc_name)[3]
end

.outputsObject



45
46
47
# File 'lib/docverter-server/conversion_types.rb', line 45

def self.outputs
  TYPES.find_all { |t| t[5] == true }
end

.valid_input?(input) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/docverter-server/conversion_types.rb', line 49

def self.valid_input?(input)
  type = for_pandoc(input)
  return type && type[4]
end

.valid_output?(output) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/docverter-server/conversion_types.rb', line 54

def self.valid_output?(output)
  type = for_pandoc(output)
  return type && type[5]
end