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, #delimit, #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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wizport/document/rtf/document.rb', line 10

def initialize(file = nil, &block)
  super
  group do
    cmd :rtf, 1
    cmd :ansi
    cmd :ansicpg, 2052
    cmd :deff, 0
    group do
      cmd :fonttbl
      group do
        delimit do
          cmd :f, 0
          cmd :fcharset, 0
          write " Courier"
        end
      end
    end
    group do
      cmd :colortbl
      delimit
      delimit do
        cmd :red, 0
        cmd :green, 0
        cmd :blue, 0
      end
      delimit do
        cmd :red, 255
        cmd :green, 0
        cmd :blue,0
      end
    end
    block.arity<1 ? self.instance_eval(&block) : block.call(self) if block_given?
  end
  save file if file
end

Instance Method Details

#imageObject



59
60
61
# File 'lib/wizport/document/rtf/document.rb', line 59

def image

end

#line_breakObject



63
64
65
# File 'lib/wizport/document/rtf/document.rb', line 63

def line_break
  cmd :par
end

#page_breakObject

writes a page interruption (new page)



68
69
70
# File 'lib/wizport/document/rtf/document.rb', line 68

def page_break
  cmd :page
end

#save(file) ⇒ Object



81
82
83
# File 'lib/wizport/document/rtf/document.rb', line 81

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

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

creates a new table.



55
56
57
# File 'lib/wizport/document/rtf/document.rb', line 55

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

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



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

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

#to_docObject



77
78
79
# File 'lib/wizport/document/rtf/document.rb', line 77

def to_doc
  @rtf.string
end

#to_sObject



73
74
75
# File 'lib/wizport/document/rtf/document.rb', line 73

def to_s

end

#write(txt) ⇒ Object



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

def write(txt)
  @rtf << txt
end