Module: RGhost::RubyToPs

Overview

Converts Ruby types to Postscript types

Instance Method Summary collapse

Instance Method Details

#array_to_stack(arr) ⇒ Object



57
58
59
# File 'lib/rghost/ruby_to_ps.rb', line 57

def array_to_stack(arr)
  "#{arr.join(' ')} "
end

#hash_to_array(hash) ⇒ Object



53
54
55
# File 'lib/rghost/ruby_to_ps.rb', line 53

def hash_to_array(hash)
  to_string_array(hash.values)
end

#pack_string(s) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/rghost/ruby_to_ps.rb', line 14

def pack_string(s)
  if RGhost::Config::GS[:charset_convert] 
    RGhost::Config::GS[:charset_convert].call(s.to_s).to_s 
  else
    s
  end
end

#ps_escape(value) ⇒ Object



23
24
25
26
# File 'lib/rghost/ruby_to_ps.rb', line 23

def ps_escape(value)
  #value.to_s.gsub(/\(/,'\\(').gsub(/\)/,"\\)").gsub(/\\/,"\134")
  value.to_s.gsub(/(\(|\)|\\)/,'\\\\\1')
end

#string_eval(str) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rghost/ruby_to_ps.rb', line 61

def string_eval(str)
  str=pack_string(str)
  return "(#{ps_escape(str)}) show " unless str =~ /%/

  s=str.scan(/([^%][a-z]*[^%]|\d+%?)|(%[^\s%]+%)/).flatten.compact
  #puts s 
  tudo=""
  s.each do |v|
    case v
    when /^%/ then tudo << "#{v.gsub(/%/,'')} to_s show "
    else
      tudo << "(#{ps_escape(v)}) show "
    end
  end
  tudo
end

#to_array(arr) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rghost/ruby_to_ps.rb', line 37

def to_array(arr)
  return "[ ]" unless arr
  ps_arr=[]
  arr.each do |a|
    ps_arr << case a
    when TrueClass,FalseClass then to_bool(a)
    when Numeric then a
    when Proc then a.to_s
    when Array then to_array(a)
    else
      to_string(a.to_s)
    end
  end
  "[#{ps_arr.join(' ')}] "
end

#to_bool(value) ⇒ Object



28
29
30
# File 'lib/rghost/ruby_to_ps.rb', line 28

def to_bool(value)
  value ? "true":"false"
end

#to_string(value) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/rghost/ruby_to_ps.rb', line 5

def to_string(value)
  #ps escape
  value=pack_string(value)
  ps_str=ps_escape(value)
  
  "(#{ps_str}) "

end

#to_string_array(arr) ⇒ Object



32
33
34
35
# File 'lib/rghost/ruby_to_ps.rb', line 32

def to_string_array(arr)

  "[#{arr.map{|a| to_string(a.to_s) }}] "
end