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
-
#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, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, 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.
120 121 122 |
# File 'lib/origami/string.rb', line 120 def encoding @encoding end |
Class Method Details
.included(receiver) ⇒ Object
:nodoc:
112 113 114 |
# File 'lib/origami/string.rb', line 112 def self.included(receiver) #:nodoc: receiver.extend(ClassMethods) end |
Instance Method Details
#detect_encoding ⇒ Object
:nodoc:
156 157 158 159 160 161 162 |
# File 'lib/origami/string.rb', line 156 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:
122 123 124 125 126 |
# File 'lib/origami/string.rb', line 122 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.
151 152 153 154 |
# File 'lib/origami/string.rb', line 151 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.
143 144 145 146 |
# File 'lib/origami/string.rb', line 143 def to_utf16be detect_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 |
# File 'lib/origami/string.rb', line 131 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 |