Class: Origami::XRef::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/xreftable.rb

Overview

Class representing a Cross-reference table. A section contains a set of XRefSubsection.

Constant Summary collapse

@@regexp_open =
Regexp.new(WHITESPACES + "xref" + WHITESPACES + "(\\r?\\n|\\r\\n?)")
@@regexp_sub =
Regexp.new("(\\d+) (\\d+)" + WHITESPACES + "(\\r?\\n|\\r\\n?)")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subsections = []) ⇒ Section

Creates a new XRef section.

subsections

An array of XRefSubsection.



216
217
218
# File 'lib/origami/xreftable.rb', line 216

def initialize(subsections = [])
  @subsections = subsections
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/origami/xreftable.rb', line 220

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

  XRef::Section.new(subsections)
end

Instance Method Details

#<<(subsection) ⇒ Object

Appends a new subsection.

subsection

A XRefSubsection.



238
239
240
# File 'lib/origami/xreftable.rb', line 238

def <<(subsection)
  @subsections << subsection
end

#[](no) ⇒ Object Also known as: find

Returns a XRef associated with a given object.

no

The Object number.



246
247
248
249
250
251
# File 'lib/origami/xreftable.rb', line 246

def [](no)
  @subsections.each { |s|
    return s[no] if s.has_object?(no)
  }
  nil
end

#each(&b) ⇒ Object

Processes each XRefSubsection.



258
259
260
# File 'lib/origami/xreftable.rb', line 258

def each(&b)
  @subsections.each(&b)
end

#to_sObject

Outputs self into PDF code.



265
266
267
# File 'lib/origami/xreftable.rb', line 265

def to_s
  "xref" << EOL << @subsections.join
end