class BLM::Row

Public Instance Methods

media_fields() click to toggle source
# File lib/rightmove.rb, line 74
def media_fields
        self.attributes.select {|k,v| k.to_s =~ /media_(image|floor_plan)_.*/i }
end
method_missing(method, arguments = {}, &block) click to toggle source
# File lib/rightmove.rb, line 50
def method_missing(method, arguments = {}, &block)
        unless @attributes[method].nil?
                value = @attributes[method] 
                if arguments[:instantiate_with]
                        return value unless value =~ /\.jpg/i
                        if arguments[:instantiate_with].instance_of?(Zip::ZipFile)
                                zip = arguments[:instantiate_with]
                        else
                                zip = Zip::ZipFile.open(arguments[:instantiate_with])
                        end
                        matching_files = zip.entries.select {|v| v.to_s =~ /#{value}/ }
                        unless matching_files.empty?
                                file = StringIO.new( zip.read(matching_files.first) )
                                file.class.class_eval { attr_accessor :original_filename, :content_type }
                                file.original_filename = matching_files.first.to_s
                                file.content_type = "image/jpg"
                                return file
                        end
                else
                        value
                end
        end
end