Class: Pandoku::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/pandoku/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format, text) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
14
15
# File 'lib/pandoku/document.rb', line 9

def initialize(format, text)
  unless format.is_a?(InputFormat)
    raise TypeError, 'format must be InputFormat'
  end
  @format = format
  @text = text
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



7
8
9
# File 'lib/pandoku/document.rb', line 7

def format
  @format
end

#textObject (readonly)

Returns the value of attribute text.



7
8
9
# File 'lib/pandoku/document.rb', line 7

def text
  @text
end

Instance Method Details

#command_for(format) ⇒ Object

Makes a command string to execute Pandoc.



18
19
20
21
22
23
24
25
# File 'lib/pandoku/document.rb', line 18

def command_for(format)
  <<-CMD
    #{PANDOC_PATH} -f #{self.format.class.name}
                   -t #{format.class.name}
                   #{self.format.cliopts}
                   #{format.cliopts}
  CMD
end

#compile(format, io = false) ⇒ Object

Compiles the document to given format. If a second argument io is true, returns IO instead of String.



29
30
31
32
33
34
# File 'lib/pandoku/document.rb', line 29

def compile(format, io = false)
  unless format.is_a?(OutputFormat)
    raise TypeError, 'format must be OutputFormat'
  end
  format.compile(self, io)
end