Class: Podoff::Obj
- Inherits:
-
Object
- Object
- Podoff::Obj
- Defined in:
- lib/podoff.rb
Constant Summary collapse
- ATTRIBUTES =
{ type: 'Type', contents: 'Contents', kids: 'Kids' }
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Class Method Summary collapse
Instance Method Summary collapse
- #dup(new_doc) ⇒ Object
-
#initialize(doc, ref, opts = {}) ⇒ Obj
constructor
A new instance of Obj.
- #insert_contents(obj_or_ref) ⇒ Object (also: #insert_content)
- #insert_font(nick, obj_or_ref) ⇒ Object
- #replica? ⇒ Boolean
-
#replicate ⇒ Object
def self.create(doc, ref, source) self.new(doc, ref, nil, nil, nil, source) end.
- #source ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(doc, ref, opts = {}) ⇒ Obj
Returns a new instance of Obj.
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/podoff.rb', line 383 def initialize(doc, ref, opts={}) @document = doc @ref = ref @start_index = opts[:start_index] @end_index = opts[:end_index] @attributes = nil @source = opts[:source] @stream = opts[:stream] @stream.obj = self if @stream recompute_attributes #@source.obj = self if @source.is_a?(Podoff::Stream) @document.scanner.pos = @end_index if @document.scanner && @end_index end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
381 382 383 |
# File 'lib/podoff.rb', line 381 def attributes @attributes end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
377 378 379 |
# File 'lib/podoff.rb', line 377 def document @document end |
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index.
379 380 381 |
# File 'lib/podoff.rb', line 379 def end_index @end_index end |
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
378 379 380 |
# File 'lib/podoff.rb', line 378 def ref @ref end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index.
379 380 381 |
# File 'lib/podoff.rb', line 379 def start_index @start_index end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
380 381 382 |
# File 'lib/podoff.rb', line 380 def stream @stream end |
Class Method Details
.extract(doc) ⇒ Object
364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/podoff.rb', line 364 def self.extract(doc) sca = doc.scanner re = sca.matched[0..-4].strip st = sca.pos - sca.matched.length i = sca.skip_until(/endobj/); return nil unless i en = sca.pos - 1 Podoff::Obj.new(doc, re, start_index: st, end_index: en) end |
Instance Method Details
#dup(new_doc) ⇒ Object
402 403 404 405 406 407 |
# File 'lib/podoff.rb', line 402 def dup(new_doc) self.class.new( new_doc, ref, start_index: start_index, end_index: end_index) end |
#insert_contents(obj_or_ref) ⇒ Object Also known as: insert_content
451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/podoff.rb', line 451 def insert_contents(obj_or_ref) fail ArgumentError.new("target '#{ref}' not a replica") \ unless @source fail ArgumentError.new("target '#{ref}' doesn't have /Contents") \ unless @attributes[:contents] re = obj_or_ref re = re.obj if re.respond_to?(:obj) # Stream re = re.ref if re.respond_to?(:ref) add_to_attribute(:contents, re) end |
#insert_font(nick, obj_or_ref) ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/podoff.rb', line 438 def insert_font(nick, obj_or_ref) fail ArgumentError.new("target '#{ref}' not a replica") \ unless @source nick = nick[1..-1] if nick[0] == '/' re = obj_or_ref re = re.ref if re.respond_to?(:ref) @source = @source.gsub(/\/Font\s*<</, "/Font\n<<\n/#{nick} #{re} R") end |
#replica? ⇒ Boolean
428 429 430 431 |
# File 'lib/podoff.rb', line 428 def replica? @source != nil end |
#replicate ⇒ Object
def self.create(doc, ref, source)
self.new(doc, ref, nil, nil, nil, source)
end
413 414 415 416 |
# File 'lib/podoff.rb', line 413 def replicate self.class.new(document, ref, source: source.dup) end |
#source ⇒ Object
423 424 425 426 |
# File 'lib/podoff.rb', line 423 def source @source || (@start_index && @document.source[@start_index..@end_index]) end |
#to_a ⇒ Object
418 419 420 421 |
# File 'lib/podoff.rb', line 418 def to_a [ @ref, @start_index, @end_index, @attributes ] end |
#to_s ⇒ Object
466 467 468 469 |
# File 'lib/podoff.rb', line 466 def to_s source || stream.to_s end |
#type ⇒ Object
433 434 435 436 |
# File 'lib/podoff.rb', line 433 def type @attributes && @attributes[:type] end |