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.
1097 1098 1099 1100 1101 1102 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 1131 1132 |
# File 'lib/QuickBaseClient.rb', line 1097 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.
1095 1096 1097 |
# File 'lib/QuickBaseClient.rb', line 1095 def parentClass @parentClass end |
Instance Method Details
#encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 |
# File 'lib/QuickBaseClient.rb', line 1143 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
1172 1173 1174 |
# File 'lib/QuickBaseClient.rb', line 1172 def to_s @xml end |
#verifyFilename(filename) ⇒ Object
1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/QuickBaseClient.rb', line 1134 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 |