idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
18,700 | def delete_obj_by_id ( id ) if ( pos = find_obj_addr_by_id ( id ) ) delete_obj_by_address ( pos , id ) return true end return false end | Delete the blob for the specified ID . |
18,701 | def delete_obj_by_address ( addr , id ) @index . remove ( id ) if @index . is_open? header = FlatFileBlobHeader . read ( @f , addr , id ) header . clear_flags @space_list . add_space ( addr , header . length ) if @space_list . is_open? end | Delete the blob that is stored at the specified address . |
18,702 | def delete_unmarked_objects clear_index_files deleted_objects_count = 0 @progressmeter . start ( 'Sweeping unmarked objects' , @f . size ) do | pm | each_blob_header do | header | if header . is_valid? && ! @marks . include? ( header . id ) delete_obj_by_address ( header . addr , header . id ) deleted_objects_count += ... | Delete all unmarked objects . |
18,703 | def write_obj_by_id ( id , raw_obj ) if ( old_addr = find_obj_addr_by_id ( id ) ) old_header = FlatFileBlobHeader . read ( @f , old_addr ) old_header . set_outdated_flag end crc = checksum ( raw_obj ) compressed = false if raw_obj . bytesize > 256 raw_obj = Zlib . deflate ( raw_obj ) compressed = true end addr , length... | Write the given object into the file . This method never uses in - place updates for existing objects . A new copy is inserted first and only when the insert was successful the old copy is deleted and the index updated . |
18,704 | def read_obj_by_address ( addr , id ) header = FlatFileBlobHeader . read ( @f , addr , id ) if header . id != id PEROBS . log . fatal "Database index corrupted: Index for object " + "#{id} points to object with ID #{header.id}" end buf = nil begin @f . seek ( addr + FlatFileBlobHeader :: LENGTH ) buf = @f . read ( head... | Read the object at the specified address . |
18,705 | def defragmentize distance = 0 new_file_size = 0 deleted_blobs = 0 corrupted_blobs = 0 valid_blobs = 0 @progressmeter . start ( 'Defragmentizing blobs file' , @f . size ) do | pm | each_blob_header do | header | if header . corruption_start distance += header . addr - header . corruption_start corrupted_blobs += 1 end ... | Eliminate all the holes in the file . This is an in - place implementation . No additional space will be needed on the file system . |
18,706 | def refresh file_size = @f . size clear_index_files @progressmeter . start ( 'Converting objects to new storage format' , @f . size ) do | pm | each_blob_header do | header | if header . is_valid? buf = read_obj_by_address ( header . addr , header . id ) delete_obj_by_address ( header . addr , header . id ) write_obj_b... | This method iterates over all entries in the FlatFile and removes the entry and inserts it again . This is useful to update all entries in case the storage format has changed . |
18,707 | def regenerate_index_and_spaces PEROBS . log . warn "Re-generating FlatFileDB index and space files" @index . open unless @index . is_open? @index . clear @space_list . open unless @space_list . is_open? @space_list . clear @progressmeter . start ( 'Re-generating database index' , @f . size ) do | pm | each_blob_header... | This method clears the index tree and the free space list and regenerates them from the FlatFile . |
18,708 | def define namespace :db do desc "Write Null dimension records" task :create_null_records do warn "Loading NULL records." @schema . dimensions . each do | dimension | dimension . create_null_records ( @staging_db ) end end desc "Writes a migration file to change the database based on defined Facts & Dimensions" task :w... | Defines the rake tasks . |
18,709 | def lock retries = @max_retries while retries > 0 begin @file = File . open ( @file_name , File :: RDWR | File :: CREAT , 0644 ) @file . sync = true if @file . flock ( File :: LOCK_EX | File :: LOCK_NB ) @file . write ( $$ ) @file . flush @file . fsync @file . truncate ( @file . pos ) PEROBS . log . debug "Lock file #{... | Create a new lock for the given file . |
18,710 | def unlock unless @file PEROBS . log . error "There is no current lock to release" return false end begin @file . flock ( File :: LOCK_UN ) @file . fsync @file . close forced_unlock PEROBS . log . debug "Lock file #{@file_name} for PID #{$$} has been " + "released" rescue => e PEROBS . log . error "Releasing of lock fi... | Release the lock again . |
18,711 | def forced_unlock @file = nil if File . exist? ( @file_name ) begin File . delete ( @file_name ) PEROBS . log . debug "Lock file #{@file_name} has been deleted." rescue IOError => e PEROBS . log . error "Cannot delete lock file #{@file_name}: " + e . message end end end | Erase the lock file . It s essentially a forced unlock method . |
18,712 | def window ( index = 0 ) if @arguments [ :use_active_window ] Window . new ( @arguments , Wmctile . current_window_id ) else Window . new ( @arguments , @window_strings [ index ] ) end rescue Errors :: WindowNotFound if @arguments [ :exec ] puts "Executing command: #{@arguments[:exec]}" system "#{@arguments[:exec]} &" ... | Starts wmctile runs the required methods . |
18,713 | def switch_to_workspace ( target_workspace ) if target_workspace == 'next' target_workspace = Wmctile . current_workspace + 1 elsif target_workspace == 'previous' target_workspace = Wmctile . current_workspace - 1 elsif target_workspace == 'history' target_workspace = Wmctile . memory . get ( :workspace_history ) [ - 2... | Switch to target_workspace . |
18,714 | def transition_to ( path , current_state = self . current_state ) path = path . to_s state = current_state || self exit_states = [ ] new_states = state . find_states ( path ) while ( ! new_states ) do exit_states << state state = state . parent_state raise ( StateNotFound , transition_error ( path ) ) unless state new_... | Transitions to the state at the specified path . The path can be relative to any state along the current state s path . |
18,715 | def available_events state = current_state ret = { } while ( state ) do ret = state . class . specification . events . merge ( ret ) state = state . parent_state end ret end | All events the current state will respond to |
18,716 | def enterable_products ids = get_enterable_products Hash [ * get ( ids ) [ 'products' ] . map { | x | [ x [ 'name' ] , x ] } . flatten ] end | def selectable_products = begin rdoc |
18,717 | def accessible_products ids = get_accessible_products Hash [ * get ( ids ) [ 'products' ] . map { | x | [ x [ 'name' ] , x ] } . flatten ] end | def enterable_products = begin rdoc |
18,718 | def put_hash ( name , hash ) file_name = File . join ( @db_dir , name + '.json' ) begin RobustFile . write ( file_name , hash . to_json ) rescue IOError => e PEROBS . log . fatal "Cannot write hash file '#{file_name}': #{e.message}" end end | Store a simple Hash as a JSON encoded file into the DB directory . |
18,719 | def pbt_parent val = pbt if val && ! pbt_id . nil? if poly? "#{pbt_type}" . constantize . where ( id : pbt_id ) . first else "#{val}" . camelize . constantize . where ( id : pbt_id ) . first end end end | Get the parent relation . Polymorphic relations are prioritized first . |
18,720 | def pbt_top_parent record = self return nil unless record . pbt_parent no_repeat = PolyBelongsTo :: SingletonSet . new while ! no_repeat . include? ( record . pbt_parent ) && ! record . pbt_parent . nil? no_repeat . add? ( record ) record = record . pbt_parent end record end | Climb up each parent object in the hierarchy until the top is reached . This has a no - repeat safety built in . Polymorphic parents have priority . |
18,721 | def pbt_parents if poly? Array [ pbt_parent ] . compact else self . class . pbts . map do | i | try { "#{i}" . camelize . constantize . where ( id : send ( "#{i}_id" ) ) . first } end . compact end end | All belongs_to parents as class objects . One if polymorphic . |
18,722 | def valid? ( string , word_list : [ ] ) string = prepare_string ( string . to_s . dup ) slug = slugify ( strip_common_words ( string , word_list ) ) meets_requirements? ( slug ) end | Is the given string deemed a good password? An additional word_list can be provided ; its entries add only minimally when considering the strength of string . |
18,723 | def add_file ( filename , content ) return if @sandbox filepath = File . join ( Configuration . instance . get ( :path ) , filename ) if File . exist? ( filepath ) puts "File #{filepath} already exists." return end FileUtils . mkdir_p File . dirname ( filepath ) File . open filepath , 'w' do | file | file . write conte... | Parses add_file dsl it adds a new file . |
18,724 | def remove_file ( filename ) return if @sandbox file_path = File . join ( Configuration . instance . get ( :path ) , filename ) File . delete ( file_path ) if File . exist? ( file_path ) end | Parses remove_file dsl it removes a file . |
18,725 | def open_connection @tcpserver = TCPSocket . new ( server , port ) @socket = OpenSSL :: SSL :: SSLSocket . new ( @tcpserver , @context ) @socket . sync_close @socket . connect greeting_process ( one_frame ) end | Establishes the connection to the server if successful will return the greeting frame . |
18,726 | def close_connection if defined? ( @socket ) && @socket . is_a? ( OpenSSL :: SSL :: SSLSocket ) @socket . close @socket = nil end if defined? ( @tcpserver ) && @tcpserver . is_a? ( TCPSocket ) @tcpserver . close @tcpserver = nil end return true if @tcpserver . nil? && @socket . nil? end | Gracefully close the connection |
18,727 | def one_frame size = @socket . read ( 4 ) raise SocketError , @socket . eof? ? 'Connection closed by remote server' : 'Error reading frame from remote server' if size . nil? size = size . unpack ( 'N' ) [ 0 ] @recv_frame = @socket . read ( size - 4 ) recv_frame_to_xml end | gets a frame from the socket and returns the parsed response . |
18,728 | def identify ( identity ) unless @session [ :km_identity ] == identity queue . delete_if { | e | e . first == 'identify' } queue << [ 'identify' , identity ] @session [ :km_identity ] = identity end end | The equivalent of the KM . identify method of the JavaScript API . |
18,729 | def sms ( remote_number , text_message ) login unless logged_in? remote_number = validate_number ( remote_number ) text_message = @coder . encode ( text_message ) @agent . post ( 'https://www.google.com/voice/sms/send/' , :id => '' , :phoneNumber => remote_number , :text => text_message , "_rnr_se" => @rnr_se ) end | Send a text message to remote_number |
18,730 | def call ( remote_number , forwarding_number ) login unless logged_in? remote_number = validate_number ( remote_number ) forwarding_number = validate_number ( forwarding_number ) @agent . post ( 'https://www.google.com/voice/call/connect/' , :outgoingNumber => remote_number , :forwardingNumber => forwarding_number , :p... | Place a call to remote_number and ring back forwarding_number which should be set up on the currently logged in Google Voice account |
18,731 | def init_xml_methods ( ) ( class << self ; self ; end ) . class_eval do %w{ unread inbox starred all spam trash voicemail sms trash recorded placed received missed } . each do | method | define_method "#{method}_xml" . to_sym do get_xml_document ( "https://www.google.com/voice/inbox/recent/#{method}" ) end end end end | Google provides XML data for various call histories all with the same URL pattern in a getful manner . So here we re just dynamically creating methods to fetch that data in a DRY - manner . Yes define_method is slow but we re already making web calls which drags performance down anyway so it shouldn t matter in the lon... |
18,732 | def setHTTPConnection ( useSSL , org = "www" , domain = "quickbase" , proxy_options = nil ) @useSSL = useSSL @org = org @domain = domain if USING_HTTPCLIENT if proxy_options @httpConnection = HTTPClient . new ( "#{proxy_options["proxy_server"]}:#{proxy_options["proxy_port"] || useSSL ? "443" : "80"}" ) @httpConnection ... | Initializes the connection to QuickBase . |
18,733 | def setHTTPConnectionAndqbhost ( useSSL , org = "www" , domain = "quickbase" , proxy_options = nil ) setHTTPConnection ( useSSL , org , domain , proxy_options ) setqbhost ( useSSL , org , domain ) end | Initializes the connection to QuickBase and sets the QuickBase URL and port to use for requests . |
18,734 | def sendRequest ( api_Request , xmlRequestData = nil ) fire ( "onSendRequest" ) resetErrorInfo getDBforRequestURL ( api_Request ) getAuthenticationXMLforRequest ( api_Request ) isHTMLRequest = isHTMLRequest? ( api_Request ) api_Request = "API_" + api_Request . to_s if prependAPI? ( api_Request ) xmlRequestData << toXML... | Sends requests to QuickBase and processes the reponses . |
18,735 | def prependAPI? ( request ) ret = true ret = false if request . to_s . include? ( "API_" ) or request . to_s . include? ( "QBIS_" ) ret end | Returns whether to prepend API_ to request string |
18,736 | def toggleTraceInfo ( showTrace ) if showTrace set_trace_func proc { | event , file , line , id , binding , classname | printf "%8s %s:%-2d %10s %8s\n" , event , file , line , id , classname } if block_given? yield set_trace_func nil end else set_trace_func nil if block_given? yield set_trace_func proc { | event , file... | Turns program stack tracing on or off . If followed by a block the tracing will be toggled on or off at the end of the block . |
18,737 | def getErrorInfoFromResponse if @responseXMLdoc errcode = getResponseValue ( :errcode ) @errcode = errcode ? errcode : "" errtext = getResponseValue ( :errtext ) @errtext = errtext ? errtext : "" errdetail = getResponseValue ( :errdetail ) @errdetail = errdetail ? errdetail : "" if @errcode != "0" @lastError = "Error c... | Extracts error info from XML responses returned by QuickBase . |
18,738 | def parseResponseXML ( xml ) if xml xml . gsub! ( "\r" , "" ) if @ignoreCR and @ignoreCR == true xml . gsub! ( "\n" , "" ) if @ignoreLF and @ignoreLF == true xml . gsub! ( "\t" , "" ) if @ignoreTAB and @ignoreTAB == true xml . gsub! ( "<BR/>" , "<BR/>" ) if @escapeBR @qdbapi = @responseXMLdoc = REXML :: Document ... | Called by processResponse to put the XML from QuickBase into a DOM tree using the REXML module that comes with Ruby . |
18,739 | def getResponseValue ( field ) @fieldValue = nil if field and @responseXMLdoc @fieldValue = @responseXMLdoc . root . elements [ field . to_s ] @fieldValue = fieldValue . text if fieldValue and fieldValue . has_text? end @fieldValue end | Gets the value for a specific field at the top level of the XML returned from QuickBase . |
18,740 | def getResponsePathValues ( path ) @fieldValue = "" e = getResponseElements ( path ) e . each { | e | @fieldValue << e . text if e and e . is_a? ( REXML :: Element ) and e . has_text? } @fieldValue end | Gets an array of values at an Xpath in the XML from QuickBase . |
18,741 | def getResponsePathValueByDBName ( path , dbName ) @fieldValue = "" if path and @responseXMLdoc e = @responseXMLdoc . root . elements [ path . to_s ] end e . each { | e | if e and e . is_a? ( REXML :: Element ) and e . dbinfo . dbname == dbName return e . dbinfo . dbid end } @fieldValue end | Gets a dbid at an Xpath in the XML from specified dbName of Quickbase |
18,742 | def getAttributeString ( element ) attributes = "" if element . is_a? ( REXML :: Element ) and element . has_attributes? attributes = "(" element . attributes . each { | name , value | attributes << "#{name}=#{value} " } attributes << ")" end attributes end | Returns a string representation of the attributes of an XML element . |
18,743 | def lookupFieldName ( element ) name = "" if element and element . is_a? ( REXML :: Element ) name = element . name if element . name == "f" and @fields fid = element . attributes [ "id" ] field = lookupField ( fid ) if fid label = field . elements [ "label" ] if field name = label . text if label end end name end | Returns the name of field given an fid XML element . |
18,744 | def lookupFieldType ( element ) type = "" if element and element . is_a? ( REXML :: Element ) if element . name == "f" and @fields fid = element . attributes [ "id" ] field = lookupField ( fid ) if fid type = field . attributes [ "field_type" ] if field end end type end | Returns a QuickBase field type given an XML fid element . |
18,745 | def lookupFieldPropertyByName ( fieldName , property ) theproperty = nil if isValidFieldProperty? ( property ) fid = lookupFieldIDByName ( fieldName ) field = lookupField ( fid ) if fid theproperty = field . elements [ property ] if field theproperty = theproperty . text if theproperty and theproperty . has_text? end t... | Returns the value of a field property or nil . |
18,746 | def isRecordidField? ( fid ) fields = lookupFieldsByType ( "recordid" ) ( fields and fields . last and fields . last . attributes [ "id" ] == fid ) end | Returns whether a field ID is the ID for the key field in a QuickBase table . |
18,747 | def formatFieldValue ( value , type , options = nil ) if value and type case type when "date" value = formatDate ( value ) when "date / time" , "timestamp" value = formatDate ( value , "%m-%d-%Y %I:%M %p" ) when "timeofday" value = formatTimeOfDay ( value , options ) when "duration" value = formatDuration ( value , opt... | Returns a human - readable string representation of a QuickBase field value . Also required for subsequent requests to QuickBase . |
18,748 | def findElementByAttributeValue ( elements , attribute_name , attribute_value ) element = nil if elements if elements . is_a? ( REXML :: Element ) elements . each_element_with_attribute ( attribute_name , attribute_value ) { | e | element = e } elsif elements . is_a? ( Array ) elements . each { | e | if e . is_a? ( REX... | Returns the first XML sub - element with the specified attribute value . |
18,749 | def findElementsByAttributeName ( elements , attribute_name ) elementArray = [ ] if elements elements . each_element_with_attribute ( attribute_name ) { | e | elementArray << e } end elementArray end | Returns an array of XML sub - elements with the specified attribute name . |
18,750 | def lookupFieldData ( fid ) @field_data = nil if @field_data_list @field_data_list . each { | field | if field and field . is_a? ( REXML :: Element ) and field . has_elements? fieldid = field . elements [ "fid" ] if fieldid and fieldid . has_text? and fieldid . text == fid . to_s @field_data = field end end } end @fiel... | Returns the XML element for a field returned by a getRecordInfo call . |
18,751 | def getFieldDataValue ( fid ) value = nil if @field_data_list field_data = lookupFieldData ( fid ) if field_data valueElement = field_data . elements [ "value" ] value = valueElement . text if valueElement . has_text? end end value end | Returns the value for a field returned by a getRecordInfo call . |
18,752 | def getFieldDataPrintableValue ( fid ) printable = nil if @field_data_list field_data = lookupFieldData ( fid ) if field_data printableElement = field_data . elements [ "printable" ] printable = printableElement . text if printableElement and printableElement . has_text? end end printable end | Returns the printable value for a field returned by a getRecordInfo call . |
18,753 | def getFieldIDs ( dbid = nil , exclude_built_in_fields = false ) fieldIDs = [ ] dbid ||= @dbid getSchema ( dbid ) if @fields @fields . each_element_with_attribute ( "id" ) { | f | next if exclude_built_in_fields and isBuiltInField? ( f . attributes [ "id" ] ) fieldIDs << f . attributes [ "id" ] . dup } end fieldIDs end | Get an array of field IDs for a table . |
18,754 | def getFieldNames ( dbid = nil , lowerOrUppercase = "" , exclude_built_in_fields = false ) fieldNames = [ ] dbid ||= @dbid getSchema ( dbid ) if @fields @fields . each_element_with_attribute ( "id" ) { | f | next if exclude_built_in_fields and isBuiltInField? ( f . attributes [ "id" ] ) if f . name == "field" if lowerO... | Get an array of field names for a table . |
18,755 | def getApplicationVariables ( dbid = nil ) variablesHash = { } dbid ||= @dbid qbc . getSchema ( dbid ) if @variables @variables . each_element_with_attribute ( "name" ) { | var | if var . name == "var" and var . has_text? variablesHash [ var . attributes [ "name" ] ] = var . text end } end variablesHash end | Get a Hash of application variables . |
18,756 | def lookupChdbid ( tableName , dbid = nil ) getSchema ( dbid ) if dbid unmodifiedTableName = tableName . dup @chdbid = findElementByAttributeValue ( @chdbids , "name" , formatChdbidName ( tableName ) ) if @chdbid @dbid = @chdbid . text return @dbid end if @chdbids chdbidArray = findElementsByAttributeName ( @chdbids , ... | Makes the table with the specified name the active table and returns the id from the table . |
18,757 | def getTableName ( dbid ) tableName = nil dbid ||= @dbid if getSchema ( dbid ) tableName = getResponseElement ( "table/name" ) . text end tableName end | Get the name of a table given its id . |
18,758 | def getTableNames ( dbid , lowercaseOrUpperCase = "" ) tableNames = [ ] dbid ||= @dbid getSchema ( dbid ) if @chdbids chdbidArray = findElementsByAttributeName ( @chdbids , "name" ) chdbidArray . each { | chdbid | if chdbid . has_text? dbid = chdbid . text getSchema ( dbid ) name = getResponseElement ( "table/name" ) i... | Get a list of the names of the child tables of an application . |
18,759 | def getTableIDs ( dbid ) tableIDs = [ ] dbid ||= @dbid getSchema ( dbid ) if @chdbids chdbidArray = findElementsByAttributeName ( @chdbids , "name" ) chdbidArray . each { | chdbid | if chdbid . has_text? tableIDs << chdbid . text end } end tableIDs end | Get a list of the dbids of the child tables of an application . |
18,760 | def getNumTables ( dbid ) numTables = 0 dbid ||= @dbid if getSchema ( dbid ) if @chdbids chdbidArray = findElementsByAttributeName ( @chdbids , "name" ) numTables = chdbidArray . length end end numTables end | Get the number of child tables of an application |
18,761 | def getRealmForDbid ( dbid ) @realm = nil if USING_HTTPCLIENT begin httpclient = HTTPClient . new resp = httpclient . get ( "https://www.quickbase.com/db/#{dbid}" ) location = resp . header [ 'Location' ] [ 0 ] location . sub! ( "https://" , "" ) parts = location . split ( / \. / ) @realm = parts [ 0 ] rescue StandardE... | Given a DBID get the QuickBase realm it is in . |
18,762 | def isValidFieldType? ( type ) @validFieldTypes ||= %w{ checkbox dblink date duration email file fkey float formula currency lookup multiuserid phone percent rating recordid text timeofday timestamp url userid icalendarbutton } @validFieldTypes . include? ( type ) end | Returns whether a given string represents a valid QuickBase field type . |
18,763 | def isValidFieldProperty? ( property ) if @validFieldProperties . nil? @validFieldProperties = %w{ allow_new_choices allowHTML appears_by_default append_only blank_is_zero bold carrychoices comma_start cover_text currency_format currency_symbol decimal_places default_kind default_today default_today default_value displ... | Returns whether a given string represents a valid QuickBase field property . |
18,764 | def verifyFieldList ( fnames , fids = nil , dbid = @dbid ) getSchema ( dbid ) @fids = @fnames = nil if fids if fids . is_a? ( Array ) and fids . length > 0 fids . each { | id | fid = lookupField ( id ) if fid fname = lookupFieldNameFromID ( id ) @fnames ||= [ ] @fnames << fname else raise "verifyFieldList: '#{id}' is n... | Given an array of field names or field IDs and a table ID builds an array of valid field IDs and field names . Throws an exception when an invalid name or ID is encountered . |
18,765 | def getQueryRequestXML ( query = nil , qid = nil , qname = nil ) @query = @qid = @qname = nil if query @query = query == "" ? "{'0'.CT.''}" : query xmlRequestData = toXML ( :query , @query ) elsif qid @qid = qid xmlRequestData = toXML ( :qid , @qid ) elsif qname @qname = qname xmlRequestData = toXML ( :qname , @qname )... | Builds the request XML for retrieving the results of a query . |
18,766 | def getColumnListForQuery ( id , name ) clistForQuery = nil if id query = lookupQuery ( id ) elsif name query = lookupQueryByName ( name ) end if query and query . elements [ "qyclst" ] clistForQuery = query . elements [ "qyclst" ] . text . dup end clistForQuery end | Returns the clist associated with a query . |
18,767 | def getSortListForQuery ( id , name ) slistForQuery = nil if id query = lookupQuery ( id ) elsif name query = lookupQueryByName ( name ) end if query and query . elements [ "qyslst" ] slistForQuery = query . elements [ "qyslst" ] . text . dup end slistForQuery end | Returns the slist associated with a query . |
18,768 | def getCriteriaForQuery ( id , name ) criteriaForQuery = nil if id query = lookupQuery ( id ) elsif name query = lookupQueryByName ( name ) end if query and query . elements [ "qycrit" ] criteriaForQuery = query . elements [ "qycrit" ] . text . dup end criteriaForQuery end | Returns the criteria associated with a query . |
18,769 | def verifyQueryOperator ( operator , fieldType ) queryOperator = "" if @queryOperators . nil? @queryOperators = { } @queryOperatorFieldType = { } @queryOperators [ "CT" ] = [ "contains" , "[]" ] @queryOperators [ "XCT" ] = [ "does not contain" , "![]" ] @queryOperators [ "EX" ] = [ "is" , "==" , "eq" ] @queryOperators ... | Returns a valid query operator . |
18,770 | def lookupBaseFieldTypeByName ( fieldName ) type = "" fid = lookupFieldIDByName ( fieldName ) field = lookupField ( fid ) if fid type = field . attributes [ "base_type" ] if field type end | Get a field s base type using its name . |
18,771 | def lookupFieldTypeByName ( fieldName ) type = "" fid = lookupFieldIDByName ( fieldName ) field = lookupField ( fid ) if fid type = field . attributes [ "field_type" ] if field type end | Get a field s type using its name . |
18,772 | def formatDate ( milliseconds , fmtString = nil , addDay = false ) fmt = "" fmtString = "%m-%d-%Y" if fmtString . nil? if milliseconds milliseconds_s = milliseconds . to_s if milliseconds_s . length == 13 t = Time . at ( milliseconds_s [ 0 , 10 ] . to_i , milliseconds_s [ 10 , 3 ] . to_i ) t += ( 60 * 60 * 24 ) if addD... | Returns the human - readable string represntation of a date given the milliseconds version of the date . Also needed for requests to QuickBase . |
18,773 | def formatDuration ( value , option = "hours" ) option = "hours" if option . nil? if value . nil? value = "" else seconds = ( value . to_i / 1000 ) minutes = ( seconds / 60 ) hours = ( minutes / 60 ) days = ( hours / 24 ) if option == "days" value = days . to_s elsif option == "hours" value = hours . to_s elsif option ... | Converts milliseconds to hours and returns the value as a string . |
18,774 | def formatTimeOfDay ( milliseconds , format = "%I:%M %p" ) format ||= "%I:%M %p" timeOfDay = "" timeOfDay = Time . at ( milliseconds . to_i / 1000 ) . utc . strftime ( format ) if milliseconds end | Returns a string format for a time of day value . |
18,775 | def formatCurrency ( value , options = nil ) value ||= "0.00" if ! value . include? ( '.' ) value << ".00" end currencySymbol = currencyFormat = nil if options currencySymbol = options [ "currencySymbol" ] currencyFormat = options [ "currencyFormat" ] end if currencySymbol if currencyFormat if currencyFormat == "0" val... | Returns a string formatted for a currency value . |
18,776 | def formatPercent ( value , options = nil ) if value percent = ( value . to_f * 100 ) value = percent . to_s if value . include? ( "." ) int , fraction = value . split ( '.' ) if fraction . to_i == 0 value = int else value = "#{int}.#{fraction[0,2]}" end end else value = "0" end value end | Returns a string formatted for a percent value given the data from QuickBase |
18,777 | def dateToMS ( dateString ) milliseconds = 0 if dateString and dateString . match ( / \- \- / ) d = Date . new ( dateString [ 7 , 4 ] , dateString [ 4 , 2 ] , dateString [ 0 , 2 ] ) milliseconds = d . jd end milliseconds end | Returns the milliseconds representation of a date specified in mm - dd - yyyy format . |
18,778 | def escapeXML ( char ) if @xmlEscapes . nil? @xmlEscapes = { } ( 0 .. 255 ) . each { | i | @xmlEscapes [ i . chr ] = sprintf ( "&#%03d;" , i ) } end return @xmlEscapes [ char ] if @xmlEscapes [ char ] char end | Returns the URL - encoded version of a non - printing character . |
18,779 | def encodingStrings ( reverse = false ) @encodingStrings = [ { "&" => "&" } , { "<" => "<" } , { ">" => ">" } , { "'" => "'" } , { "\"" => """ } ] if @encodingStrings . nil? if block_given? if reverse @encodingStrings . reverse_each { | s | s . each { | k , v | yield v , k } } else @encodingStrings ... | Returns the list of string substitutions to make to encode or decode field values used in XML . |
18,780 | def encodeXML ( text , doNPChars = false ) encodingStrings { | key , value | text . gsub! ( key , value ) if text } text . gsub! ( / \/ \$ \- / ) { | c | escapeXML ( $1 ) } if text and doNPChars text end | Modify the given string for use as a XML field value . |
18,781 | def decodeXML ( text ) encodingStrings ( true ) { | key , value | text . gsub! ( value , key ) if text } text . gsub! ( / / ) { | c | $1 . chr } if text text end | Modify the given XML field value for use as a string . |
18,782 | def fire ( event ) if @eventSubscribers and @eventSubscribers . include? ( event ) handlers = @eventSubscribers [ event ] if handlers handlers . each { | handler | handler . handle ( event ) } end end end | Called by client methods to notify event subscribers |
18,783 | def _addRecord ( fvlist = nil , disprec = nil , fform = nil , ignoreError = nil , update_id = nil ) addRecord ( @dbid , fvlist , disprec , fform , ignoreError , update_id ) end | API_AddRecord using the active table id . |
18,784 | def _doQueryHash ( doQueryOptions ) doQueryOptions ||= { } raise "options must be a Hash" unless doQueryOptions . is_a? ( Hash ) doQueryOptions [ "dbid" ] ||= @dbid doQueryOptions [ "fmt" ] ||= "structured" doQuery ( doQueryOptions [ "dbid" ] , doQueryOptions [ "query" ] , doQueryOptions [ "qid" ] , doQueryOptions [ "q... | version of doQuery that takes a Hash of parameters |
18,785 | def downLoadFile ( dbid , rid , fid , vid = "0" ) @dbid , @rid , @fid , @vid = dbid , rid , fid , vid @downLoadFileURL = "http://#{@org}.#{@domain}.com/up/#{dbid}/a/r#{rid}/e#{fid}/v#{vid}" if @useSSL @downLoadFileURL . gsub! ( "http:" , "https:" ) end @requestHeaders = { "Cookie" => "ticket=#{@ticket}" } if @printRequ... | Download a file s contents from a file attachment field in QuickBase . You must write the contents to disk before a local file exists . |
18,786 | def downloadAndSaveFile ( dbid , rid , fid , filename = nil , vid = "0" ) response , fileContents = downLoadFile ( dbid , rid , fid , vid ) if fileContents and fileContents . length > 0 if filename and filename . length > 0 Misc . save_file ( filename , fileContents ) else record = getRecord ( rid , dbid , [ fid ] ) if... | Download and save a file from a file attachment field in QuickBase . Use the filename parameter to override the file name from QuickBase . |
18,787 | def fieldAddChoices ( dbid , fid , choice ) @dbid , @fid , @choice = dbid , fid , choice xmlRequestData = toXML ( :fid , @fid ) if @choice . is_a? ( Array ) @choice . each { | c | xmlRequestData << toXML ( :choice , c ) } elsif @choice . is_a? ( String ) xmlRequestData << toXML ( :choice , @choice ) end sendRequest ( :... | API_FieldAddChoices The choice parameter can be one choice string or an array of choice strings . |
18,788 | def iterateDBPages ( dbid ) listDBPages ( dbid ) { | page | if page . is_a? ( REXML :: Element ) and page . name == "page" @pageid = page . attributes [ "id" ] @pagetype = page . attributes [ "type" ] @pagename = page . text if page . has_text? @page = { "name" => @pagename , "id" => @pageid , "type" => @pagetype } yie... | Loop through the list of Pages for an application |
18,789 | def getAllValuesForFields ( dbid , fieldNames = nil , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) if dbid getSchema ( dbid ) values = { } fieldIDs = { } if fieldNames and fieldNames . is_a? ( String ) values [ fieldNames ] = [ ] fieldID = lookupFieldIDByName ... | Get all the values for one or more fields from a specified table . |
18,790 | def getAllValuesForFieldsAsArray ( dbid , fieldNames = nil , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) ret = [ ] valuesForFields = getAllValuesForFields ( dbid , fieldNames , query , qid , qname , clist , slist , fmt , options ) if valuesForFields fieldName... | Get all the values for one or more fields from a specified table . This also formats the field values instead of returning the raw value . |
18,791 | def getAllValuesForFieldsAsJSON ( dbid , fieldNames = nil , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) ret = getAllValuesForFieldsAsArray ( dbid , fieldNames , query , qid , qname , clist , slist , fmt , options ) ret = JSON . generate ( ret ) if ret end | Get all the values for one or more fields from a specified table in JSON format . This formats the field values instead of returning raw values . |
18,792 | def getAllValuesForFieldsAsPrettyJSON ( dbid , fieldNames = nil , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) ret = getAllValuesForFieldsAsArray ( dbid , fieldNames , query , qid , qname , clist , slist , fmt , options ) ret = JSON . pretty_generate ( ret ) i... | Get all the values for one or more fields from a specified table in human - readable JSON format . This formats the field values instead of returning raw values . |
18,793 | def getSummaryRecords ( dbid , fieldNames , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) summaryRecords = [ ] iterateSummaryRecords ( dbid , fieldNames , query , qid , qname , clist , slist , fmt = "structured" , options ) { | summaryRecord | summaryRecords <<... | Collect summary records into an array . |
18,794 | def iterateRecordInfos ( dbid , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) getSchema ( dbid ) recordIDFieldName = lookupFieldNameFromID ( "3" ) fieldNames = getFieldNames fieldIDs = { } fieldNames . each { | name | fieldIDs [ name ] = lookupFieldIDByName ( n... | Loop through a list of records returned from a query . Each record will contain all the fields with values formatted for readability by QuickBase via API_GetRecordInfo . |
18,795 | def applyPercentToRecords ( dbid , numericField , percentField , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) fieldNames = Array [ numericField ] total = sum ( dbid , fieldNames , query , qid , qname , clist , slist , fmt , options ) fieldNames << "3" iterateR... | Query records sum the values in a numeric field calculate each record s percentage of the sum and put the percent in a percent field each record . |
18,796 | def applyDeviationToRecords ( dbid , numericField , deviationField , query = nil , qid = nil , qname = nil , clist = nil , slist = nil , fmt = "structured" , options = nil ) fieldNames = Array [ numericField ] avg = average ( dbid , fieldNames , query , qid , qname , clist , slist , fmt , options ) fieldNames << "3" it... | Query records get the average of the values in a numeric field calculate each record s deviation from the average and put the deviation in a percent field each record . |
18,797 | def percent ( inputValues ) raise "'inputValues' must not be nil" if inputValues . nil? raise "'inputValues' must be an Array" if not inputValues . is_a? ( Array ) raise "'inputValues' must have at least two elements" if inputValues . length < 2 total = inputValues [ 0 ] . to_f total = 1.0 if total == 0.00 value = inpu... | Given an array of two numbers return the second number as a percentage of the first number . |
18,798 | def deviation ( inputValues ) raise "'inputValues' must not be nil" if inputValues . nil? raise "'inputValues' must be an Array" if not inputValues . is_a? ( Array ) raise "'inputValues' must have at least two elements" if inputValues . length < 2 value = inputValues [ 0 ] . to_f - inputValues [ 1 ] . to_f value . abs ... | Given an array of two numbers return the difference between the numbers as a positive number . |
18,799 | def getFieldChoices ( dbid , fieldName = nil , fid = nil ) getSchema ( dbid ) if fieldName fid = lookupFieldIDByName ( fieldName ) elsif not fid raise "'fieldName' or 'fid' must be specified" end field = lookupField ( fid ) if field choices = [ ] choicesProc = proc { | element | if element . is_a? ( REXML :: Element ) ... | Get an array of the existing choices for a multiple - choice text field . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.