Deserializing old PHP data with Ruby -- but PHP object had a .type property

Status
Not open for further replies.

Dromio

Ars Scholae Palatinae
1,411
I'm a total newbie with Ruby, but I thought I'd use it to try and reclaim the data from my ancient PHP based photo site. That site used PHP serialization to store data in the filesystem like this: (pointed to gist because it's too big to fit here)

https://gist.github.com/727628

So I found a ruby gem called php_serializer that seems to do most of the trick. Except for one big problem -- the extension of the image in question is in a property called "type" (see it up there?). When I deserialize this to ruby, it doesn't like me looking at the .type property. Here's some code:

Code:
require "rubygems"             
require "php_serialize"        

def get_file_as_string(filename)  
  data = ''
  f = File.open(filename, "r") 
  f.each_line do |line|        
    data += line               
  end
  return data                  
end

class PhotoInfo
        def initialize(galleryItem)             
                @caption = galleryItem.caption  
                @image = galleryItem.image.name 
                @extension = galleryItem.image.type #THIS IS A PROBLEM
        end
        def print              
                puts "_____________________________" 
                puts @caption
                puts @image    
                puts @extension
        end
end

toDeserialize = get_file_as_string(ARGV[0])
out = PHP.unserialize(toDeserialize)

out.each do |item|
        photo = PhotoInfo.new(item)
        photo.print
end

Anyone more knowledgeable with Ruby know what I can do? How do I get to the "type" of the image in the object?
 
Status
Not open for further replies.