Class: Wizport::Rtf::Document

Inherits:
Element
  • Object
show all
Defined in:
lib/wizport/document/rtf/document.rb

Instance Method Summary collapse

Methods inherited from Element

#cmd, #group, #txt

Constructor Details

#initialize(file = nil, &block) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
15
16
17
18
19
# File 'lib/wizport/document/rtf/document.rb', line 10

def initialize(file = nil, &block)
  @rtf = StringIO.new
  group do
    cmd :rtf, 1
    cmd :ansi
    cmd :ansicpg, 2052
    block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
  end
  save file if file
end

Instance Method Details

#line_breakObject



33
34
35
# File 'lib/wizport/document/rtf/document.rb', line 33

def line_break
  cmd :par
end

#page_breakObject



37
38
39
# File 'lib/wizport/document/rtf/document.rb', line 37

def page_break
  cmd :page
end

#save(file) ⇒ Object



50
51
52
# File 'lib/wizport/document/rtf/document.rb', line 50

def save(file)
  File.open(file, 'w') { |file| file.write(to_doc) }
end

#table(rows = [], options = {}, &block) ⇒ Object



29
30
31
# File 'lib/wizport/document/rtf/document.rb', line 29

def table(rows = [],options = {}, &block)
  Wizport::Rtf::Table.new(self, rows, options, &block)
end

#text(str, styles = {:align => :left}) ⇒ Object



25
26
27
# File 'lib/wizport/document/rtf/document.rb', line 25

def text(str, styles = {:align => :left})
  Wizport::Rtf::Text.new(self, str, styles)
end

#to_docObject



46
47
48
# File 'lib/wizport/document/rtf/document.rb', line 46

def to_doc
  @rtf.string
end

#to_sObject



42
43
44
# File 'lib/wizport/document/rtf/document.rb', line 42

def to_s

end

#write(txt) ⇒ Object



21
22
23
# File 'lib/wizport/document/rtf/document.rb', line 21

def write(txt)
  @rtf << txt
end