Class: Wizport::Rtf::Element
- Inherits:
-
Object
- Object
- Wizport::Rtf::Element
- Defined in:
- lib/wizport/document/rtf/element.rb
Instance Method Summary collapse
- #cmd(name, value = nil) ⇒ Object
- #delimit ⇒ Object
- #group ⇒ Object
-
#initialize(rtf = nil) ⇒ Element
constructor
A new instance of Element.
- #txt(str) ⇒ Object
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 |
#delimit ⇒ Object
33 34 35 36 |
# File 'lib/wizport/document/rtf/element.rb', line 33 def delimit yield if block_given? @rtf.write ';' end |
#group ⇒ Object
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 |