bin/pdf2ruby in origami-2.0.3 vs bin/pdf2ruby in origami-2.0.4

- old
+ new

@@ -94,14 +94,12 @@ code << case obj when Origami::Null "Null.new" - when Origami::Boolean, Origami::Number - obj.value.to_s - when Origami::String - obj.inspect + when Origami::Boolean, Origami::Number, Origami::Name, Origami::String + literalToRuby(obj) when Origami::Dictionary customclass = nil if obj.class != Origami::Dictionary p = (obj.class == Origami::Encoding) ? 0 : 1 customclass = obj.class.to_s.split('::')[p..-1].join('::') # strip Origami prefix if there is no collision @@ -109,12 +107,10 @@ dictionaryToRuby(obj, inclevel, internalname, customclass) when Origami::Array arrayToRuby(obj, inclevel, internalname) when Origami::Stream streamToRuby(obj, internalname) unless obj.is_a?(ObjectStream) or obj.is_a?(XRefStream) - when Origami::Name - nameToRuby(obj) when Origami::Reference referenceToRuby(obj, internalname) else raise RuntimeError, "Unknown object type: #{obj.class}" end @@ -142,19 +138,12 @@ @obj_route.push(varname) unless @obj_route.include?(varname) varname end end -def nameToRuby(name) - code = ':' - valid = (name.value.to_s =~ /[+.:-]/).nil? - - code << '"' unless valid - code << name.value.to_s - code << '"' unless valid - - code +def literalToRuby(obj) + obj.value.inspect end def arrayToRuby(arr, inclevel, internalname) i = 0 code = "\n" + " " * inclevel + "[" @@ -178,11 +167,11 @@ code << "#{customtype}.new(#{dictionaryToHashMap(dict, inclevel, internalname)}" code << " " * inclevel + ")" else code << "{\n" dict.each_pair do |key, val| - rubyname = nameToRuby(key) + rubyname = literalToRuby(key) subintname = "#{internalname}[#{rubyname}]" if val.is_a?(Origami::Reference) and @var_hash[val] and @var_hash[val][0,3] == "obj" oldname = @var_hash[val] newname = (key.value.to_s.downcase.gsub(/[^[[:alnum:]]]/,'_') + "_" + @var_hash[val][4..-1]).tr('.', '_') @@ -210,10 +199,10 @@ def dictionaryToHashMap(dict, inclevel, internalname) i = 0 code = "\n" dict.each_pair do |key, val| - rubyname = nameToRuby(key) + rubyname = literalToRuby(key) subintname = "#{internalname}[#{rubyname}]" if val.is_a?(Origami::Reference) and @var_hash[val] and @var_hash[val][0,3] == "obj" oldname = @var_hash[val] newname = (key.value.to_s.downcase + "_" + @var_hash[val][4..-1]).tr('.', '_')