Sha256: 9f0ffa28c164b4fd2934c8959b4afe5a62a5c693c006552b8fdc706736315e39

Contents?: true

Size: 920 Bytes

Versions: 6

Compression:

Stored size: 920 Bytes

Contents

# encoding: utf-8

# WizRft:  A gem for exporting Word Documents in ruby
# using the Microsoft Rich Text Format (RTF) Specification
# Copyright (C) 2015 by sgzhe@163.com

module WizRtf
  class RtfIO
    def initialize(io = nil)
      @io = io || StringIO.new
    end

    def write(txt)
      @io.write txt
    end

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

    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('')
      @io.write ' '
      @io.write str
    end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wiz_rtf-0.6.9 lib/wiz_rtf/rtf_io.rb
wiz_rtf-0.6.8 lib/wiz_rtf/rtf_io.rb
wiz_rtf-0.6.7 lib/wiz_rtf/rtf_io.rb
wiz_rtf-0.6.0 lib/wiz_rtf/rtf_io.rb
wiz_rtf-0.5.5 lib/wiz_rtf/rtf_io.rb
wiz_rtf-0.5.0 lib/wiz_rtf/rtf_io.rb