class Origami::XRef::Subsection
A subsection contains a continute set of XRef.
Class representing a cross-reference subsection.
def self.parse(stream) #:nodoc:
def self.parse(stream) #:nodoc: scanner = Parser.init_scanner(stream) if scanner.scan(@@regexp).nil? raise InvalidXRefSubsectionError, "Bad subsection format" end start = scanner['start'].to_i size = scanner['size'].to_i xrefs = [] size.times do xrefs << XRef.parse(scanner) end XRef::Subsection.new(start, xrefs) end
def [](no)
_no_:: The Object number.
Returns XRef associated with a given object.
def [](no) @entries[no - @range.begin] end
def each(&b)
Processes each XRef in the subsection.
def each(&b) @entries.each(&b) end
def each_with_number
Processes each XRef in the subsection, passing the XRef and the object number to the block.
def each_with_number return enum_for(__method__) { self.size } unless block_given? counter = @range.to_enum @entries.each do |entry| yield(entry, counter.next) end end
def has_object?(no)
_no_:: The Object number.
Returns whether this subsection contains information about a particular object.
def has_object?(no) @range.include?(no) end
def initialize(start, entries = [])
_entries_:: An array of XRef.
_start_:: The number of the first object referenced in the subsection.
Creates a new XRef subsection.
def initialize(start, entries = []) @entries = entries.dup @range = Range.new(start, start + entries.size - 1) end
def size
The number of entries in the subsection.
def size @entries.size end
def to_s(eol: $/)
Outputs self into PDF code.
def to_s(eol: $/) section = "#{@range.begin} #{@range.end - @range.begin + 1}" + eol @entries.each do |xref| section << xref.to_s(eol: eol) end section end