Class: Origami::XRef::Subsection

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

Overview

Class representing a cross-reference subsection. A subsection contains a continute set of XRef.

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, entries = []) ⇒ Subsection

Creates a new XRef subsection.

start

The number of the first object referenced in the subsection.

entries

An array of XRef.



139
140
141
142
143
144
# File 'lib/origami/xreftable.rb', line 139

def initialize(start, entries = [])
  
  @entries = entries.dup
  @range = Range.new(start, start + entries.size - 1)
  
end

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range.



132
133
134
# File 'lib/origami/xreftable.rb', line 132

def range
  @range
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/origami/xreftable.rb', line 146

def self.parse(stream) #:nodoc:
  
  if stream.scan(@@regexp).nil?
    raise InvalidXRefSubsectionError, "Bad subsection format"
  end
  
  start = stream[1].to_i
  size = stream[2].to_i
  
  xrefs = []
  size.times do
    xrefs << XRef.parse(stream)
  end
  
  XRef::Subsection.new(start, xrefs)
end

Instance Method Details

#[](no) ⇒ Object

Returns XRef associated with a given object.

no

The Object number.



175
176
177
# File 'lib/origami/xreftable.rb', line 175

def [](no)
  @entries[no - @range.begin]
end

#each(&b) ⇒ Object

Processes each XRef in the subsection.



182
183
184
# File 'lib/origami/xreftable.rb', line 182

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

#has_object?(no) ⇒ Boolean

Returns whether this subsection contains information about a particular object.

no

The Object number.

Returns:



167
168
169
# File 'lib/origami/xreftable.rb', line 167

def has_object?(no)
  @range.include?(no)
end

#to_sObject

Outputs self into PDF code.



189
190
191
192
193
194
195
196
# File 'lib/origami/xreftable.rb', line 189

def to_s
  section = "#{@range.begin} #{@range.end - @range.begin + 1}" + EOL
  @entries.each { |xref|
    section << xref.to_s
  }
  
  section
end