Sha256: ad88055916b708a151a4763705a6b0254a154913bf1bbe9efabf5ccaa44ef878

Contents?: true

Size: 694 Bytes

Versions: 11

Compression:

Stored size: 694 Bytes

Contents

# frozen_string_literal: true

class String
  def pred
    # integers
    ((Integer self) - 1).to_s
  rescue ::ArgumentError
    # chars (upper alpha, lower alpha, lower greek)
    ([65, 97, 945].include? ord) ? '0' : ([ord - 1].pack 'U1')
  end unless method_defined? :pred

  # If the string is ASCII only, convert it to a PDF LiteralString object. Otherwise, return self.
  def as_pdf
    ascii_only? ? (::PDF::Core::LiteralString.new encode ::Encoding::ASCII_8BIT) : self
  end

  # Convert the string to a serialized PDF object. If the string can be encoded as ASCII-8BIT, first convert it to a PDF
  # LiteralString object.
  def to_pdf_object
    ::PDF::Core.pdf_object as_pdf
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
asciidoctor-pdf-1.6.2 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.6.1 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.6.0 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.4 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.3 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.2 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.1 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0.rc.3 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0.rc.2 lib/asciidoctor/pdf/ext/core/string.rb
asciidoctor-pdf-1.5.0.rc.1 lib/asciidoctor/pdf/ext/core/string.rb