Class: QuickBase::Client::FieldValuePairXML
- Inherits:
-
Object
- Object
- QuickBase::Client::FieldValuePairXML
- Defined in:
- lib/QuickBaseClient.rb
Overview
Encapsulates field values to be set and file uploads to be made during addRecord() and editRecord() calls.
Instance Attribute Summary collapse
-
#parentClass ⇒ Object
readonly
Returns the value of attribute parentClass.
Instance Method Summary collapse
- #encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
-
#initialize(parentClass, name, fid, filename, value) ⇒ FieldValuePairXML
constructor
A new instance of FieldValuePairXML.
- #to_s ⇒ Object
- #verifyFilename(filename) ⇒ Object
Constructor Details
#initialize(parentClass, name, fid, filename, value) ⇒ FieldValuePairXML
Returns a new instance of FieldValuePairXML.
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/QuickBaseClient.rb', line 1057 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 |
Instance Attribute Details
#parentClass ⇒ Object (readonly)
Returns the value of attribute parentClass.
1055 1056 1057 |
# File 'lib/QuickBaseClient.rb', line 1055 def parentClass @parentClass end |
Instance Method Details
#encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
# File 'lib/QuickBaseClient.rb', line 1103 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 ⇒ Object
1132 1133 1134 |
# File 'lib/QuickBaseClient.rb', line 1132 def to_s @xml end |
#verifyFilename(filename) ⇒ Object
1094 1095 1096 1097 1098 1099 1100 1101 |
# File 'lib/QuickBaseClient.rb', line 1094 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 |