Module: Origami::String
Overview
Module common to String objects.
Defined Under Namespace
Modules: Encoding
Constant Summary
Constants included from Object
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Instance Method Summary collapse
-
#infer_encoding ⇒ Object
:nodoc:.
-
#initialize(str) ⇒ Object
:nodoc:.
- #real_type ⇒ Object
-
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded Ruby string.
-
#to_utf16be ⇒ Object
Convert String object to an UTF16-BE encoded Ruby string.
-
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
Methods included from Object
#<=>, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, parse, #pdf, #pdf_version_required, #post_build, #pre_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
119 120 121 |
# File 'lib/origami/string.rb', line 119 def encoding @encoding end |
Instance Method Details
#infer_encoding ⇒ Object
:nodoc:
162 163 164 165 166 167 168 169 |
# File 'lib/origami/string.rb', line 162 def infer_encoding #:nodoc: @encoding = if self.value[0,2] == Encoding::UTF16BE::MAGIC Encoding::UTF16BE else Encoding::PDFDocEncoding end end |
#initialize(str) ⇒ Object
:nodoc:
123 124 125 126 |
# File 'lib/origami/string.rb', line 123 def initialize(str) #:nodoc: infer_encoding super(str) end |
#real_type ⇒ Object
121 |
# File 'lib/origami/string.rb', line 121 def real_type ; Origami::String end |
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded Ruby string.
157 158 159 160 |
# File 'lib/origami/string.rb', line 157 def to_pdfdoc infer_encoding self.encoding.to_pdfdoc(self.value) end |
#to_utf16be ⇒ Object
Convert String object to an UTF16-BE encoded Ruby string.
149 150 151 152 |
# File 'lib/origami/string.rb', line 149 def to_utf16be infer_encoding self.encoding.to_utf16be(self.value) end |
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/origami/string.rb', line 131 def to_utf8 infer_encoding if RUBY_VERSION < '1.9' require 'iconv' i = Iconv.new("UTF-8", "UTF-16") utf8str = i.iconv(self.encoding.to_utf16be(self.value)) i.close else utf8str = self.encoding.to_utf16be(self.value).encode("utf-8", "utf-16") end utf8str end |