class PDF::Reader::Filter::AsciiHex
implementation of the AsciiHex
stream filter
Public Class Methods
new(options = {})
click to toggle source
# File lib/pdf/reader/filter/ascii_hex.rb, line 9 def initialize(options = {}) @options = options end
Public Instance Methods
filter(data)
click to toggle source
Decode the specified data using the AsciiHex
algorithm.
# File lib/pdf/reader/filter/ascii_hex.rb, line 16 def filter(data) data.chop! if data[-1,1] == ">" data = data[1,data.size] if data[0,1] == "<" data.gsub!(/[^A-Fa-f0-9]/,"") data << "0" if data.size % 2 == 1 data.scan(/.{2}/).map { |s| s.hex.chr }.join("") rescue Exception => e # Oops, there was a problem decoding the stream raise MalformedPDFError, "Error occured while decoding an ASCIIHex stream (#{e.class.to_s}: #{e.to_s})" end