Class: Wizport::Rtf::Element
- Inherits:
-
Object
- Object
- Wizport::Rtf::Element
show all
- Defined in:
- lib/wizport/document/rtf/element.rb
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
17
18
19
20
21
|
# File 'lib/wizport/document/rtf/element.rb', line 17
def cmd(name, value = nil)
@rtf.write '\\'
@rtf.write name
@rtf.write value if value
end
|
#delimit ⇒ Object
37
38
39
40
|
# File 'lib/wizport/document/rtf/element.rb', line 37
def delimit
yield if block_given?
@rtf.write ';'
end
|
#group ⇒ Object
31
32
33
34
35
|
# File 'lib/wizport/document/rtf/element.rb', line 31
def group
@rtf.write '{'
yield if block_given?
@rtf.write '}'
end
|
#txt(str) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/wizport/document/rtf/element.rb', line 23
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
|
#write(txt) ⇒ Object
13
14
15
|
# File 'lib/wizport/document/rtf/element.rb', line 13
def write(txt)
@rtf.write txt
end
|