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.
108 109 110 |
# File 'lib/origami/string.rb', line 108 def encoding @encoding end |
Instance Method Details
#detect_encoding ⇒ Object
:nodoc:
145 146 147 148 149 150 151 |
# File 'lib/origami/string.rb', line 145 def detect_encoding # :nodoc: @encoding = if value[0, 2] == Encoding::UTF16BE::BOM Encoding::UTF16BE else Encoding::PDFDocEncoding end end |
#initialize(str) ⇒ Object
:nodoc:
110 111 112 113 114 115 |
# File 'lib/origami/string.rb', line 110 def initialize(str) # :nodoc: mutable_str = +str.dup # Create a mutable copy super(mutable_str.force_encoding('binary')) detect_encoding end |
#to_pdfdoc ⇒ Object
Convert String object to a PDFDocEncoding encoded binary Ruby string.
140 141 142 143 |
# File 'lib/origami/string.rb', line 140 def to_pdfdoc detect_encoding encoding.to_pdfdoc(value) end |
#to_utf16be ⇒ Object
Convert String object to an UTF16-BE encoded binary Ruby string.
132 133 134 135 |
# File 'lib/origami/string.rb', line 132 def to_utf16be detect_encoding encoding.to_utf16be(value) end |
#to_utf8 ⇒ Object
Convert String object to an UTF8 encoded Ruby string.
120 121 122 123 124 125 126 127 |
# File 'lib/origami/string.rb', line 120 def to_utf8 detect_encoding utf16 = encoding.to_utf16be(value) utf16.slice!(0, Encoding::UTF16BE::BOM.size) utf16.encode("utf-8", "utf-16be") end |