class Origami::XRef::Section


A section contains a set of XRef::Subsection.
Class representing a Cross-reference table.

def self.parse(stream) #:nodoc:

:nodoc:
def self.parse(stream) #:nodoc:
    scanner = Parser.init_scanner(stream)
    if scanner.skip(@@regexp_open).nil?
        raise InvalidXRefSectionError, "No xref token found"
    end
    subsections = []
    while scanner.match?(@@regexp_sub) do
        subsections << XRef::Subsection.parse(scanner)
    end
    XRef::Section.new(subsections)
end

def <<(subsection)


_subsection_:: A XRefSubsection.
Appends a new subsection.
def <<(subsection)
    @subsections << subsection
end

def [](no)


_no_:: The Object number.
Returns a XRef associated with a given object.
def [](no)
    @subsections.each do |s|
        return s[no] if s.has_object?(no)
    end
    nil
end

def clear


Clear all the entries.
def clear
    @subsections.clear
end

def each(&b)


Processes each XRef in each Subsection.
def each(&b)
    return enum_for(__method__) { self.size } unless block_given?
    @subsections.each do |subsection|
        subsection.each(&b)
    end
end

def each_subsection(&b)


Processes each Subsection in this table.
def each_subsection(&b)
    @subsections.each(&b)
end

def each_with_number(&b)


Processes each XRef in each Subsection, passing the XRef and the object number.
def each_with_number(&b)
    return enum_for(__method__) { self.size } unless block_given?
    @subsections.each do |subsection|
        subsection.each_with_number(&b)
    end
end

def initialize(subsections = [])


_subsections_:: An array of XRefSubsection.
Creates a new XRef section.
def initialize(subsections = [])
    @subsections = subsections
end

def size


The number of XRef entries in the Section.
def size
    @subsections.reduce(0) { |total, subsection| total + subsection.size }
end

def subsections


Returns an Array of Subsection.
def subsections
    @subsections
end

def to_s(eol: $/)


Outputs self into PDF code.
def to_s(eol: $/)
    "xref".dup << eol << @subsections.map{|sub| sub.to_s(eol: eol)}.join
end