Module: Origami::String
Overview
Module common to String objects.
Defined Under Namespace
Modules: ClassMethods, 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
Class Method Summary collapse
-
.included(receiver) ⇒ Object
:nodoc:.
-
.native_type ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#infer_encoding ⇒ Object
:nodoc:.
-
#initialize(str) ⇒ Object
:nodoc:.
-
#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
#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, #native_type, 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.
129 130 131 |
# File 'lib/origami/string.rb', line 129 def encoding @encoding end |
Class Method Details
.included(receiver) ⇒ Object
:nodoc:
121 122 123 |
# File 'lib/origami/string.rb', line 121 def self.included(receiver) #:nodoc: receiver.extend(ClassMethods) end |
Instance Method Details
#infer_encoding ⇒ Object
:nodoc:
170 171 172 173 174 175 176 177 |
# File 'lib/origami/string.rb', line 170 def infer_encoding #:nodoc: @encoding = if self.value[0,2] == Encoding::UTF16BE::MAGIC Encoding::UTF16BE else Encoding::PDFDocEncoding end end |
#initialize(str) ⇒ Object
:nodoc:
131 132 133 134 |
# File 'lib/origami/string.rb', line 131 def initialize(str) #:nodoc: infer_encoding super(str) end |
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded Ruby string.
165 166 167 168 |
# File 'lib/origami/string.rb', line 165 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.
157 158 159 160 |
# File 'lib/origami/string.rb', line 157 def to_utf16be infer_encoding self.encoding.to_utf16be(self.value) end |
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/origami/string.rb', line 139 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 |