Class: RGhost::PsObject

Inherits:
Object
  • Object
show all
Defined in:
lib/rghost/ps_object.rb

Overview

Postscript wrapper class

Instance Method Summary collapse

Constructor Details

#initialize(body = "", &block) ⇒ PsObject

Creates new instance of PsObject. Example

PsObject.new("/my_proc { 33 45 2 10 sub mul div} bind def")

Or by block code

PsObject.new do
  set PsObject.new("(A test) show")
  raw "(Other Test in raw) show "
end


11
12
13
14
15
16
17
18
19
20
# File 'lib/rghost/ps_object.rb', line 11

def initialize(body="",&block)
  @body=if body.is_a? RGhost::PsObject
    body.ps
  else
    "#{body} "
  end
  
  instance_eval(&block) if block
  
end

Instance Method Details

#<<(value) ⇒ Object

Alias for set



45
46
47
48
# File 'lib/rghost/ps_object.rb', line 45

def <<(value)
  set value
 
end

#call(name) ⇒ Object

Call operator in the stack



51
52
53
# File 'lib/rghost/ps_object.rb', line 51

def call(name)
  set RGhost::PsObject.new(name)
end

#graphic_scopeObject

Freezes graphic state



34
35
36
# File 'lib/rghost/ps_object.rb', line 34

def graphic_scope
  "beging #{self} endg "
end

#psObject

Gets postscript code.



26
27
28
# File 'lib/rghost/ps_object.rb', line 26

def ps
  @body.to_s
end

#raw(*value) ⇒ Object

Pushes elements on the stack.



30
31
32
# File 'lib/rghost/ps_object.rb', line 30

def raw(*value)
  @body << "#{value.join(' ')} "
end

#set(value) ⇒ Object

Sets PsObject into this object.

Raises:

  • (TypeError)


38
39
40
41
42
43
# File 'lib/rghost/ps_object.rb', line 38

def set(value)

  raise TypeError.new("can't convert #{value.class} into PsObject") unless value.is_a? RGhost::PsObject
  @body << "#{value.ps} "
  value
end

#to_sObject

Alias for ps.



22
23
24
# File 'lib/rghost/ps_object.rb', line 22

def to_s
  ps
end