Class: Origami::XRef::Section
- Inherits:
-
Object
- Object
- Origami::XRef::Section
- Includes:
- Enumerable
- Defined in:
- lib/origami/xreftable.rb
Overview
Class representing a Cross-reference table. A section contains a set of XRefSubsection.
Constant Summary collapse
- TOKEN =
"xref"
- @@regexp_open =
Regexp.new(WHITESPACES + TOKEN + WHITESPACES + "(\\r?\\n|\\r\\n?)")
- @@regexp_sub =
Regexp.new("(\\d+) (\\d+)" + WHITESPACES + "(\\r?\\n|\\r\\n?)")
Class Method Summary collapse
-
.parse(stream) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#<<(subsection) ⇒ Object
Appends a new subsection.
-
#[](no) ⇒ Object
(also: #find)
Returns a XRef associated with a given object.
-
#clear ⇒ Object
Clear all the entries.
-
#each(&b) ⇒ Object
Processes each XRef in each Subsection.
-
#each_subsection(&b) ⇒ Object
Processes each Subsection in this table.
-
#each_with_number(&b) ⇒ Object
Processes each XRef in each Subsection, passing the XRef and the object number.
-
#initialize(subsections = []) ⇒ Section
constructor
Creates a new XRef section.
-
#size ⇒ Object
The number of XRef entries in the Section.
-
#subsections ⇒ Object
Returns an Array of Subsection.
-
#to_s ⇒ Object
Outputs self into PDF code.
Constructor Details
#initialize(subsections = []) ⇒ Section
Creates a new XRef section.
- subsections
-
An array of XRefSubsection.
233 234 235 |
# File 'lib/origami/xreftable.rb', line 233 def initialize(subsections = []) @subsections = subsections end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/origami/xreftable.rb', line 237 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.
254 255 256 |
# File 'lib/origami/xreftable.rb', line 254 def <<(subsection) @subsections << subsection end |
#[](no) ⇒ Object Also known as: find
Returns a XRef associated with a given object.
- no
-
The Object number.
262 263 264 265 266 267 268 |
# File 'lib/origami/xreftable.rb', line 262 def [](no) @subsections.each do |s| return s[no] if s.has_object?(no) end nil end |
#clear ⇒ Object
Clear all the entries.
310 311 312 |
# File 'lib/origami/xreftable.rb', line 310 def clear @subsections.clear end |
#each(&b) ⇒ Object
Processes each XRef in each Subsection.
274 275 276 277 278 279 280 |
# File 'lib/origami/xreftable.rb', line 274 def each(&b) return enum_for(__method__) { self.size } unless block_given? @subsections.each do |subsection| subsection.each(&b) end end |
#each_subsection(&b) ⇒ Object
Processes each Subsection in this table.
296 297 298 |
# File 'lib/origami/xreftable.rb', line 296 def each_subsection(&b) @subsections.each(&b) end |
#each_with_number(&b) ⇒ Object
Processes each XRef in each Subsection, passing the XRef and the object number.
285 286 287 288 289 290 291 |
# File 'lib/origami/xreftable.rb', line 285 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 |
#size ⇒ Object
The number of XRef entries in the Section.
317 318 319 |
# File 'lib/origami/xreftable.rb', line 317 def size @subsections.reduce(0) { |total, subsection| total + subsection.size } end |
#subsections ⇒ Object
Returns an Array of Subsection.
303 304 305 |
# File 'lib/origami/xreftable.rb', line 303 def subsections @subsections end |