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
-
#detect_encoding ⇒ Object
:nodoc:.
-
#initialize(str) ⇒ Object
:nodoc:.
-
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded binary Ruby string.
-
#to_utf16be ⇒ Object
Convert String object to an UTF16-BE encoded binary Ruby string.
-
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
Methods included from Object
#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #pre_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
110 111 112 |
# File 'lib/origami/string.rb', line 110 def encoding @encoding end |
Instance Method Details
#detect_encoding ⇒ Object
:nodoc:
146 147 148 149 150 151 152 |
# File 'lib/origami/string.rb', line 146 def detect_encoding #:nodoc: if self.value[0,2] == Encoding::UTF16BE::BOM @encoding = Encoding::UTF16BE else @encoding = Encoding::PDFDocEncoding end end |
#initialize(str) ⇒ Object
:nodoc:
112 113 114 115 116 |
# File 'lib/origami/string.rb', line 112 def initialize(str) #:nodoc: super(str.force_encoding('binary')) detect_encoding end |
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded binary Ruby string.
141 142 143 144 |
# File 'lib/origami/string.rb', line 141 def to_pdfdoc detect_encoding self.encoding.to_pdfdoc(self.value) end |
#to_utf16be ⇒ Object
Convert String object to an UTF16-BE encoded binary Ruby string.
133 134 135 136 |
# File 'lib/origami/string.rb', line 133 def to_utf16be detect_encoding self.encoding.to_utf16be(self.value) end |
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
121 122 123 124 125 126 127 128 |
# File 'lib/origami/string.rb', line 121 def to_utf8 detect_encoding utf16 = self.encoding.to_utf16be(self.value) utf16.slice!(0, Encoding::UTF16BE::BOM.size) utf16.encode("utf-8", "utf-16be") end |