class QuickBase::Client::FieldValuePairXML

Encapsulates field values to be set and file uploads to be made during addRecord() and editRecord() calls.

Attributes

parentClass[R]

Public Class Methods

new( parentClass, name, fid, filename, value ) click to toggle source
# File lib/QuickBaseClient.rb, line 1079
def initialize( parentClass, name, fid, filename, value )

   @parentClass = parentClass

   name = name.downcase if name
   name = name.gsub( /\W/, "_" )  if name
 
   if filename or value
      @xml = "<field "
      if name
         @xml << "name='#{name}'"
      elsif fid
         @xml << "fid='#{fid}'"
      else
         raise "FieldValuePairXML::initialize: must specify 'name' or 'fid'"
      end
      if filename
         @xml << " filename='#{verifyFilename(filename)}'"
      end
      if value
         if filename
            value = encodeFileContentsForUpload( value )
         else
            value = @parentClass.encodeXML( value )
         end
         @xml << ">#{value}</field>"
      elsif filename
         value = encodeFileContentsForUpload( filename )
         @xml << ">#{value}</field>"
      else
         @xml << "/>"
      end
   else
      raise "FieldValuePairXML::initialize: must specify 'filename' or 'value'"
   end
end

Public Instance Methods

encodeFileContentsForUpload( fileNameOrFileContents ) click to toggle source
# File lib/QuickBaseClient.rb, line 1125
def encodeFileContentsForUpload( fileNameOrFileContents )
   if fileNameOrFileContents
      if FileTest.readable?( fileNameOrFileContents )
         f = File.new( fileNameOrFileContents, "r" )
         if f
             encodedFileContents = ""
             f.binmode
             buffer = f.read(60)
             while buffer
               encodedFileContents << [buffer].pack('m').tr( "\r\n", '' )
               buffer = f.read(60)
             end
             f.close
             return encodedFileContents
        end
     elsif fileNameOrFileContents.is_a?( String )
        encodedFileContents = ""
        buffer = fileNameOrFileContents.slice!(0,60)
        while buffer and buffer.length > 0 
           buffer = buffer.to_s
           encodedFileContents << [buffer].pack('m').tr( "\r\n", '' )
           buffer = fileNameOrFileContents.slice!(0,60)
        end
        return encodedFileContents
     end
  end
  nil
end
to_s() click to toggle source
# File lib/QuickBaseClient.rb, line 1154
def to_s
   @xml
end
verifyFilename( filename ) click to toggle source
# File lib/QuickBaseClient.rb, line 1116
def verifyFilename( filename )
   if filename
      filename.slice!( 0, filename.rindex( '\\' )+1 ) if filename.include?( '\\' )
      filename.slice!( 0, filename.rindex( '/' )+1 ) if filename.include?( '/' )
      filename = @parentClass.encodeXML( filename )
   end
   filename
end