Class: Prune::Elements::Base

Inherits:
Object
  • Object
show all
Includes:
Prune::Errors, Functions, PObjects
Defined in:
lib/prune/elements/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Functions

#mm_to_pt, #pt_to_mm

Methods included from PObjects

pa, pd, ph, pl, pn, ps

Constructor Details

#initialize(document) ⇒ Base

Initialize.



13
14
15
16
17
18
19
20
# File 'lib/prune/elements/base.rb', line 13

def initialize(document)
  @document = document
  @element_id = 0
  @revision = 0
  @content = nil
  @stream = nil
  @registered = false
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



10
11
12
# File 'lib/prune/elements/base.rb', line 10

def document
  @document
end

Instance Method Details

#referenceObject

Get reference id of the element.

Raises:

  • (ObjectNotRegisteredError)


33
34
35
36
# File 'lib/prune/elements/base.rb', line 33

def reference
  raise ObjectNotRegisteredError unless @registered
  "#{@element_id} #{@revision} R"
end

#registerObject

Register element to document.



39
40
41
42
43
44
45
# File 'lib/prune/elements/base.rb', line 39

def register
  unless @registered
    @element_id = @document.elements.size + 1
    @document.elements << self
    @registered = true
  end
end

#to_sObject

Convert element to String.



23
24
25
26
27
28
29
30
# File 'lib/prune/elements/base.rb', line 23

def to_s
  raise ElementNotRegisteredError unless @registered
  out = []
  out << "%d %d obj" % [@element_id, @revision]
  out << @content.to_s
  out << "endobj"
  return out.join(LF)
end