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.
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
# File 'lib/QuickBaseClient.rb', line 1076 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.
1074 1075 1076 |
# File 'lib/QuickBaseClient.rb', line 1074 def parentClass @parentClass end |
Instance Method Details
#encodeFileContentsForUpload(fileNameOrFileContents) ⇒ Object
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
# File 'lib/QuickBaseClient.rb', line 1122 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
1151 1152 1153 |
# File 'lib/QuickBaseClient.rb', line 1151 def to_s @xml end |
#verifyFilename(filename) ⇒ Object
1113 1114 1115 1116 1117 1118 1119 1120 |
# File 'lib/QuickBaseClient.rb', line 1113 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 |