Class: Wizport::Rtf::Element

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

Direct Known Subclasses

Document, Table, Text

Instance Method Summary collapse

Constructor Details

#initialize(rtf = nil) ⇒ Element

Returns a new instance of Element.



9
10
11
# File 'lib/wizport/document/rtf/element.rb', line 9

def initialize(rtf = nil)
  @rtf = rtf || StringIO.new
end

Instance Method Details

#cmd(name, value = nil) ⇒ Object



13
14
15
16
17
# File 'lib/wizport/document/rtf/element.rb', line 13

def cmd(name, value = nil)
  @rtf.write '\\'
  @rtf.write name
  @rtf.write value if value
end

#delimitObject



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

def delimit
  yield if block_given?
  @rtf.write ';'
end

#groupObject



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

def group
  @rtf.write '{'
  yield if block_given?
  @rtf.write '}'
end

#txt(str) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/wizport/document/rtf/element.rb', line 19

def txt(str)
  str = str.to_s
  str = str.gsub("{", "\\{").gsub("}", "\\}").gsub("\\", "\\\\")
  str = str.encode("UTF-16LE", :undef=>:replace).each_codepoint.map {|n| n < 128 ? n.chr : "\\u#{n}\\'3f"}.join('')
  @rtf.write ' '
  @rtf.write str
end