Class: RPDF::PDFString

Inherits:
PDFObject show all
Defined in:
lib/rpdf/pdfstring.rb

Overview

String Object

PDFRef15 p29

Instance Attribute Summary collapse

Attributes inherited from PDFObject

#generation_number, #object_number

Instance Method Summary collapse

Methods inherited from PDFObject

#indirect?, #invalidate, #invalidated?, #to_pdf, #to_ref

Constructor Details

#initialize(value, document = nil) ⇒ PDFString

Returns a new instance of PDFString.

Raises:

  • (Exception)


12
13
14
15
16
17
# File 'lib/rpdf/pdfstring.rb', line 12

def initialize(value, document=nil)
  raise Exception.new("PDFString is not a string") unless value.kind_of?(String)
  @value = value
  @hexadecimal = false
  super(document)
end

Instance Attribute Details

#hexadecimalObject

Returns the value of attribute hexadecimal.



10
11
12
# File 'lib/rpdf/pdfstring.rb', line 10

def hexadecimal
  @hexadecimal
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/rpdf/pdfstring.rb', line 8

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
# File 'lib/rpdf/pdfstring.rb', line 19

def ==(other)
  @value == other.value
end

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpdf/pdfstring.rb', line 23

def to_s
  if @hexadecimal
    # [PDFRef15 p32]
    hexval = String.new
    @value.each_byte { |byte|
      hexval << "%02X" % byte
    }
    "<#{hexval}>"
  else
    "(#{@value.dump})" # nonprinting characters should be replaced by \nnn and special characters escaped
  end
end