Module: RGhost::RubyToPs
- Included in:
- Callback, Color, Dash, Document, FontMap, Grid::Base, Grid::FieldFormat, Grid::Header, Paper, RectangleLink, Show, Text, TextArea, TextIn, TextLinkIn, VirtualPages
- Defined in:
- lib/rghost/ruby_to_ps.rb
Overview
Converts Ruby types to Postscript types
Instance Method Summary collapse
- #array_to_stack(arr) ⇒ Object
- #hash_to_array(hash) ⇒ Object
- #pack_string(s) ⇒ Object
- #ps_escape(value) ⇒ Object
- #string_eval(str) ⇒ Object
- #to_array(arr) ⇒ Object
- #to_bool(value) ⇒ Object
- #to_string(value) ⇒ Object
- #to_string_array(arr) ⇒ Object
Instance Method Details
#array_to_stack(arr) ⇒ Object
60 61 62 |
# File 'lib/rghost/ruby_to_ps.rb', line 60 def array_to_stack(arr) "#{arr.join(' ')} " end |
#hash_to_array(hash) ⇒ Object
56 57 58 |
# File 'lib/rghost/ruby_to_ps.rb', line 56 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 |
# File 'lib/rghost/ruby_to_ps.rb', line 23 def ps_escape(value) value.to_s.gsub(/(\(|\)|\\)/,'\\\\\1') end |
#string_eval(str) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rghost/ruby_to_ps.rb', line 64 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 /^%/ tudo << "#{v.gsub(/%/,'')} to_s show " else tudo << "(#{ps_escape(v)}) show " end end tudo end |
#to_array(arr) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rghost/ruby_to_ps.rb', line 36 def to_array(arr) return "[ ]" unless arr ps_arr=[] arr.each do |a| ps_arr << case a when TrueClass,FalseClass to_bool(a) when Numeric a when Proc a.to_s when Array to_array(a) else to_string(a.to_s) end end "[#{ps_arr.join(' ')}] " end |
#to_bool(value) ⇒ Object
27 28 29 |
# File 'lib/rghost/ruby_to_ps.rb', line 27 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
31 32 33 34 |
# File 'lib/rghost/ruby_to_ps.rb', line 31 def to_string_array(arr) "[#{arr.map{|a| to_string(a.to_s) }}] " end |