repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.delete_obj_by_id | 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 | ruby | 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 | [
"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.
@param id [Integer] ID of the object to be deleted
@return [Boolean] True if object was deleted, false otherwise | [
"Delete",
"the",
"blob",
"for",
"the",
"specified",
"ID",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L117-L124 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.delete_obj_by_address | 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 | ruby | 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 | [
"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.
@param addr [Integer] Address of the blob to delete
@param id [Integer] ID of the blob to delete | [
"Delete",
"the",
"blob",
"that",
"is",
"stored",
"at",
"the",
"specified",
"address",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L129-L134 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.delete_unmarked_objects | def delete_unmarked_objects
# We don't update the index and the space list during this operation as
# we defragmentize the blob file at the end. We'll end the operation
# with an empty space list.
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? && [email protected]?(header.id)
delete_obj_by_address(header.addr, header.id)
deleted_objects_count += 1
end
pm.update(header.addr)
end
end
defragmentize
# Update the index file and create a new, empty space list.
regenerate_index_and_spaces
deleted_objects_count
end | ruby | def delete_unmarked_objects
# We don't update the index and the space list during this operation as
# we defragmentize the blob file at the end. We'll end the operation
# with an empty space list.
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? && [email protected]?(header.id)
delete_obj_by_address(header.addr, header.id)
deleted_objects_count += 1
end
pm.update(header.addr)
end
end
defragmentize
# Update the index file and create a new, empty space list.
regenerate_index_and_spaces
deleted_objects_count
end | [
"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",
"+=",
"1",
"end",
"pm",
".",
"update",
"(",
"header",
".",
"addr",
")",
"end",
"end",
"defragmentize",
"regenerate_index_and_spaces",
"deleted_objects_count",
"end"
] | Delete all unmarked objects. | [
"Delete",
"all",
"unmarked",
"objects",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L137-L160 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.write_obj_by_id | def write_obj_by_id(id, raw_obj)
# Check if we have already an object with the given ID. We'll mark it as
# outdated and save the header for later deletion. In case this
# operation is aborted or interrupted we ensure that we either have the
# old or the new version available.
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)
# If the raw_obj is larger then 256 characters we will compress it to
# safe some space in the database file. For smaller strings the
# performance impact of compression is not compensated by writing
# less data to the storage.
compressed = false
if raw_obj.bytesize > 256
raw_obj = Zlib.deflate(raw_obj)
compressed = true
end
addr, length = find_free_blob(raw_obj.bytesize)
begin
if length != -1
# Just a safeguard so we don't overwrite current data.
header = FlatFileBlobHeader.read(@f, addr)
if header.length != length
PEROBS.log.fatal "Length in free list (#{length}) and header " +
"(#{header.length}) for address #{addr} don't match."
end
if raw_obj.bytesize > header.length
PEROBS.log.fatal "Object (#{raw_obj.bytesize}) is longer than " +
"blob space (#{header.length})."
end
if header.is_valid?
PEROBS.log.fatal "Entry at address #{addr} with flags: " +
"#{header.flags} is already used for ID #{header.id}."
end
end
flags = 1 << FlatFileBlobHeader::VALID_FLAG_BIT
flags |= (1 << FlatFileBlobHeader::COMPRESSED_FLAG_BIT) if compressed
FlatFileBlobHeader.new(@f, addr, flags, raw_obj.bytesize, id, crc).write
@f.write(raw_obj)
if length != -1 && raw_obj.bytesize < length
# The new object was not appended and it did not completely fill the
# free space. So we have to write a new header to mark the remaining
# empty space.
unless length - raw_obj.bytesize >= FlatFileBlobHeader::LENGTH
PEROBS.log.fatal "Not enough space to append the empty space " +
"header (space: #{length} bytes, object: #{raw_obj.bytesize} " +
"bytes)."
end
space_address = @f.pos
space_length = length - FlatFileBlobHeader::LENGTH - raw_obj.bytesize
FlatFileBlobHeader.new(@f, space_address, 0, space_length,
0, 0).write
# Register the new space with the space list.
if @space_list.is_open? && space_length > 0
@space_list.add_space(space_address, space_length)
end
end
# Once the blob has been written we can update the index as well.
@index.insert(id, addr) if @index.is_open?
if old_addr
# If we had an existing object stored for the ID we have to mark
# this entry as deleted now.
old_header.clear_flags
# And register the newly freed space with the space list.
if @space_list.is_open?
@space_list.add_space(old_addr, old_header.length)
end
else
@f.flush
end
rescue IOError => e
PEROBS.log.fatal "Cannot write blob for ID #{id} to FlatFileDB: " +
e.message
end
addr
end | ruby | def write_obj_by_id(id, raw_obj)
# Check if we have already an object with the given ID. We'll mark it as
# outdated and save the header for later deletion. In case this
# operation is aborted or interrupted we ensure that we either have the
# old or the new version available.
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)
# If the raw_obj is larger then 256 characters we will compress it to
# safe some space in the database file. For smaller strings the
# performance impact of compression is not compensated by writing
# less data to the storage.
compressed = false
if raw_obj.bytesize > 256
raw_obj = Zlib.deflate(raw_obj)
compressed = true
end
addr, length = find_free_blob(raw_obj.bytesize)
begin
if length != -1
# Just a safeguard so we don't overwrite current data.
header = FlatFileBlobHeader.read(@f, addr)
if header.length != length
PEROBS.log.fatal "Length in free list (#{length}) and header " +
"(#{header.length}) for address #{addr} don't match."
end
if raw_obj.bytesize > header.length
PEROBS.log.fatal "Object (#{raw_obj.bytesize}) is longer than " +
"blob space (#{header.length})."
end
if header.is_valid?
PEROBS.log.fatal "Entry at address #{addr} with flags: " +
"#{header.flags} is already used for ID #{header.id}."
end
end
flags = 1 << FlatFileBlobHeader::VALID_FLAG_BIT
flags |= (1 << FlatFileBlobHeader::COMPRESSED_FLAG_BIT) if compressed
FlatFileBlobHeader.new(@f, addr, flags, raw_obj.bytesize, id, crc).write
@f.write(raw_obj)
if length != -1 && raw_obj.bytesize < length
# The new object was not appended and it did not completely fill the
# free space. So we have to write a new header to mark the remaining
# empty space.
unless length - raw_obj.bytesize >= FlatFileBlobHeader::LENGTH
PEROBS.log.fatal "Not enough space to append the empty space " +
"header (space: #{length} bytes, object: #{raw_obj.bytesize} " +
"bytes)."
end
space_address = @f.pos
space_length = length - FlatFileBlobHeader::LENGTH - raw_obj.bytesize
FlatFileBlobHeader.new(@f, space_address, 0, space_length,
0, 0).write
# Register the new space with the space list.
if @space_list.is_open? && space_length > 0
@space_list.add_space(space_address, space_length)
end
end
# Once the blob has been written we can update the index as well.
@index.insert(id, addr) if @index.is_open?
if old_addr
# If we had an existing object stored for the ID we have to mark
# this entry as deleted now.
old_header.clear_flags
# And register the newly freed space with the space list.
if @space_list.is_open?
@space_list.add_space(old_addr, old_header.length)
end
else
@f.flush
end
rescue IOError => e
PEROBS.log.fatal "Cannot write blob for ID #{id} to FlatFileDB: " +
e.message
end
addr
end | [
"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",
"=",
"find_free_blob",
"(",
"raw_obj",
".",
"bytesize",
")",
"begin",
"if",
"length",
"!=",
"-",
"1",
"header",
"=",
"FlatFileBlobHeader",
".",
"read",
"(",
"@f",
",",
"addr",
")",
"if",
"header",
".",
"length",
"!=",
"length",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Length in free list (#{length}) and header \"",
"+",
"\"(#{header.length}) for address #{addr} don't match.\"",
"end",
"if",
"raw_obj",
".",
"bytesize",
">",
"header",
".",
"length",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Object (#{raw_obj.bytesize}) is longer than \"",
"+",
"\"blob space (#{header.length}).\"",
"end",
"if",
"header",
".",
"is_valid?",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Entry at address #{addr} with flags: \"",
"+",
"\"#{header.flags} is already used for ID #{header.id}.\"",
"end",
"end",
"flags",
"=",
"1",
"<<",
"FlatFileBlobHeader",
"::",
"VALID_FLAG_BIT",
"flags",
"|=",
"(",
"1",
"<<",
"FlatFileBlobHeader",
"::",
"COMPRESSED_FLAG_BIT",
")",
"if",
"compressed",
"FlatFileBlobHeader",
".",
"new",
"(",
"@f",
",",
"addr",
",",
"flags",
",",
"raw_obj",
".",
"bytesize",
",",
"id",
",",
"crc",
")",
".",
"write",
"@f",
".",
"write",
"(",
"raw_obj",
")",
"if",
"length",
"!=",
"-",
"1",
"&&",
"raw_obj",
".",
"bytesize",
"<",
"length",
"unless",
"length",
"-",
"raw_obj",
".",
"bytesize",
">=",
"FlatFileBlobHeader",
"::",
"LENGTH",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Not enough space to append the empty space \"",
"+",
"\"header (space: #{length} bytes, object: #{raw_obj.bytesize} \"",
"+",
"\"bytes).\"",
"end",
"space_address",
"=",
"@f",
".",
"pos",
"space_length",
"=",
"length",
"-",
"FlatFileBlobHeader",
"::",
"LENGTH",
"-",
"raw_obj",
".",
"bytesize",
"FlatFileBlobHeader",
".",
"new",
"(",
"@f",
",",
"space_address",
",",
"0",
",",
"space_length",
",",
"0",
",",
"0",
")",
".",
"write",
"if",
"@space_list",
".",
"is_open?",
"&&",
"space_length",
">",
"0",
"@space_list",
".",
"add_space",
"(",
"space_address",
",",
"space_length",
")",
"end",
"end",
"@index",
".",
"insert",
"(",
"id",
",",
"addr",
")",
"if",
"@index",
".",
"is_open?",
"if",
"old_addr",
"old_header",
".",
"clear_flags",
"if",
"@space_list",
".",
"is_open?",
"@space_list",
".",
"add_space",
"(",
"old_addr",
",",
"old_header",
".",
"length",
")",
"end",
"else",
"@f",
".",
"flush",
"end",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot write blob for ID #{id} to FlatFileDB: \"",
"+",
"e",
".",
"message",
"end",
"addr",
"end"
] | 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.
@param id [Integer] ID of the object
@param raw_obj [String] Raw object as String
@return [Integer] position of the written blob in the blob file | [
"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",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L169-L252 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.read_obj_by_address | 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(header.length)
rescue IOError => e
PEROBS.log.fatal "Cannot read blob for ID #{id}: #{e.message}"
end
# Uncompress the data if the compression bit is set in the flags byte.
if header.is_compressed?
begin
buf = Zlib.inflate(buf)
rescue Zlib::BufError, Zlib::DataError
PEROBS.log.fatal "Corrupted compressed block with ID " +
"#{header.id} found."
end
end
if checksum(buf) != header.crc
PEROBS.log.fatal "Checksum failure while reading blob ID #{id}"
end
buf
end | ruby | 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(header.length)
rescue IOError => e
PEROBS.log.fatal "Cannot read blob for ID #{id}: #{e.message}"
end
# Uncompress the data if the compression bit is set in the flags byte.
if header.is_compressed?
begin
buf = Zlib.inflate(buf)
rescue Zlib::BufError, Zlib::DataError
PEROBS.log.fatal "Corrupted compressed block with ID " +
"#{header.id} found."
end
end
if checksum(buf) != header.crc
PEROBS.log.fatal "Checksum failure while reading blob ID #{id}"
end
buf
end | [
"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",
"(",
"header",
".",
"length",
")",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot read blob for ID #{id}: #{e.message}\"",
"end",
"if",
"header",
".",
"is_compressed?",
"begin",
"buf",
"=",
"Zlib",
".",
"inflate",
"(",
"buf",
")",
"rescue",
"Zlib",
"::",
"BufError",
",",
"Zlib",
"::",
"DataError",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Corrupted compressed block with ID \"",
"+",
"\"#{header.id} found.\"",
"end",
"end",
"if",
"checksum",
"(",
"buf",
")",
"!=",
"header",
".",
"crc",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Checksum failure while reading blob ID #{id}\"",
"end",
"buf",
"end"
] | Read the object at the specified address.
@param addr [Integer] Offset in the flat file
@param id [Integer] ID of the data blob
@return [String] Raw object data | [
"Read",
"the",
"object",
"at",
"the",
"specified",
"address",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L281-L312 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.defragmentize | def defragmentize
distance = 0
new_file_size = 0
deleted_blobs = 0
corrupted_blobs = 0
valid_blobs = 0
# Iterate over all entries.
@progressmeter.start('Defragmentizing blobs file', @f.size) do |pm|
each_blob_header do |header|
# If we have stumbled over a corrupted blob we treat it similar to a
# deleted blob and reuse the space.
if header.corruption_start
distance += header.addr - header.corruption_start
corrupted_blobs += 1
end
# Total size of the current entry
entry_bytes = FlatFileBlobHeader::LENGTH + header.length
if header.is_valid?
# We have found a valid entry.
valid_blobs += 1
if distance > 0
begin
# Read current entry into a buffer
@f.seek(header.addr)
buf = @f.read(entry_bytes)
# Write the buffer right after the end of the previous entry.
@f.seek(header.addr - distance)
@f.write(buf)
# Mark the space between the relocated current entry and the
# next valid entry as deleted space.
FlatFileBlobHeader.new(@f, @f.pos, 0,
distance - FlatFileBlobHeader::LENGTH,
0, 0).write
@f.flush
rescue IOError => e
PEROBS.log.fatal "Error while moving blob for ID " +
"#{header.id}: #{e.message}"
end
end
new_file_size = header.addr - distance +
FlatFileBlobHeader::LENGTH + header.length
else
deleted_blobs += 1
distance += entry_bytes
end
pm.update(header.addr)
end
end
PEROBS.log.info "#{distance / 1000} KiB/#{deleted_blobs} blobs of " +
"#{@f.size / 1000} KiB/#{valid_blobs} blobs or " +
"#{'%.1f' % (distance.to_f / @f.size * 100.0)}% reclaimed"
if corrupted_blobs > 0
PEROBS.log.info "#{corrupted_blobs} corrupted blob(s) found. Space " +
"was recycled."
end
@f.flush
@f.truncate(new_file_size)
@f.flush
sync
end | ruby | def defragmentize
distance = 0
new_file_size = 0
deleted_blobs = 0
corrupted_blobs = 0
valid_blobs = 0
# Iterate over all entries.
@progressmeter.start('Defragmentizing blobs file', @f.size) do |pm|
each_blob_header do |header|
# If we have stumbled over a corrupted blob we treat it similar to a
# deleted blob and reuse the space.
if header.corruption_start
distance += header.addr - header.corruption_start
corrupted_blobs += 1
end
# Total size of the current entry
entry_bytes = FlatFileBlobHeader::LENGTH + header.length
if header.is_valid?
# We have found a valid entry.
valid_blobs += 1
if distance > 0
begin
# Read current entry into a buffer
@f.seek(header.addr)
buf = @f.read(entry_bytes)
# Write the buffer right after the end of the previous entry.
@f.seek(header.addr - distance)
@f.write(buf)
# Mark the space between the relocated current entry and the
# next valid entry as deleted space.
FlatFileBlobHeader.new(@f, @f.pos, 0,
distance - FlatFileBlobHeader::LENGTH,
0, 0).write
@f.flush
rescue IOError => e
PEROBS.log.fatal "Error while moving blob for ID " +
"#{header.id}: #{e.message}"
end
end
new_file_size = header.addr - distance +
FlatFileBlobHeader::LENGTH + header.length
else
deleted_blobs += 1
distance += entry_bytes
end
pm.update(header.addr)
end
end
PEROBS.log.info "#{distance / 1000} KiB/#{deleted_blobs} blobs of " +
"#{@f.size / 1000} KiB/#{valid_blobs} blobs or " +
"#{'%.1f' % (distance.to_f / @f.size * 100.0)}% reclaimed"
if corrupted_blobs > 0
PEROBS.log.info "#{corrupted_blobs} corrupted blob(s) found. Space " +
"was recycled."
end
@f.flush
@f.truncate(new_file_size)
@f.flush
sync
end | [
"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",
"entry_bytes",
"=",
"FlatFileBlobHeader",
"::",
"LENGTH",
"+",
"header",
".",
"length",
"if",
"header",
".",
"is_valid?",
"valid_blobs",
"+=",
"1",
"if",
"distance",
">",
"0",
"begin",
"@f",
".",
"seek",
"(",
"header",
".",
"addr",
")",
"buf",
"=",
"@f",
".",
"read",
"(",
"entry_bytes",
")",
"@f",
".",
"seek",
"(",
"header",
".",
"addr",
"-",
"distance",
")",
"@f",
".",
"write",
"(",
"buf",
")",
"FlatFileBlobHeader",
".",
"new",
"(",
"@f",
",",
"@f",
".",
"pos",
",",
"0",
",",
"distance",
"-",
"FlatFileBlobHeader",
"::",
"LENGTH",
",",
"0",
",",
"0",
")",
".",
"write",
"@f",
".",
"flush",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Error while moving blob for ID \"",
"+",
"\"#{header.id}: #{e.message}\"",
"end",
"end",
"new_file_size",
"=",
"header",
".",
"addr",
"-",
"distance",
"+",
"FlatFileBlobHeader",
"::",
"LENGTH",
"+",
"header",
".",
"length",
"else",
"deleted_blobs",
"+=",
"1",
"distance",
"+=",
"entry_bytes",
"end",
"pm",
".",
"update",
"(",
"header",
".",
"addr",
")",
"end",
"end",
"PEROBS",
".",
"log",
".",
"info",
"\"#{distance / 1000} KiB/#{deleted_blobs} blobs of \"",
"+",
"\"#{@f.size / 1000} KiB/#{valid_blobs} blobs or \"",
"+",
"\"#{'%.1f' % (distance.to_f / @f.size * 100.0)}% reclaimed\"",
"if",
"corrupted_blobs",
">",
"0",
"PEROBS",
".",
"log",
".",
"info",
"\"#{corrupted_blobs} corrupted blob(s) found. Space \"",
"+",
"\"was recycled.\"",
"end",
"@f",
".",
"flush",
"@f",
".",
"truncate",
"(",
"new_file_size",
")",
"@f",
".",
"flush",
"sync",
"end"
] | Eliminate all the holes in the file. This is an in-place
implementation. No additional space will be needed on the file system. | [
"Eliminate",
"all",
"the",
"holes",
"in",
"the",
"file",
".",
"This",
"is",
"an",
"in",
"-",
"place",
"implementation",
".",
"No",
"additional",
"space",
"will",
"be",
"needed",
"on",
"the",
"file",
"system",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L337-L402 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.refresh | def refresh
# This iteration might look scary as we iterate over the entries while
# while we are rearranging them. Re-inserted items may be inserted
# before or at the current entry and this is fine. They also may be
# inserted after the current entry and will be re-read again unless they
# are inserted after the original file end.
file_size = @f.size
# We don't update the index and the space list during this operation as
# we defragmentize the blob file at the end. We'll end the operation
# with an empty space list.
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_by_id(header.id, buf)
end
# Some re-inserted blobs may be inserted after the original file end.
# No need to process those blobs again.
break if header.addr >= file_size
pm.update(header.addr)
end
end
# Reclaim the space saved by compressing entries.
defragmentize
# Recreate the index file and create an empty space list.
regenerate_index_and_spaces
end | ruby | def refresh
# This iteration might look scary as we iterate over the entries while
# while we are rearranging them. Re-inserted items may be inserted
# before or at the current entry and this is fine. They also may be
# inserted after the current entry and will be re-read again unless they
# are inserted after the original file end.
file_size = @f.size
# We don't update the index and the space list during this operation as
# we defragmentize the blob file at the end. We'll end the operation
# with an empty space list.
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_by_id(header.id, buf)
end
# Some re-inserted blobs may be inserted after the original file end.
# No need to process those blobs again.
break if header.addr >= file_size
pm.update(header.addr)
end
end
# Reclaim the space saved by compressing entries.
defragmentize
# Recreate the index file and create an empty space list.
regenerate_index_and_spaces
end | [
"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_by_id",
"(",
"header",
".",
"id",
",",
"buf",
")",
"end",
"break",
"if",
"header",
".",
"addr",
">=",
"file_size",
"pm",
".",
"update",
"(",
"header",
".",
"addr",
")",
"end",
"end",
"defragmentize",
"regenerate_index_and_spaces",
"end"
] | 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. | [
"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",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L407-L442 | train |
scrapper/perobs | lib/perobs/FlatFile.rb | PEROBS.FlatFile.regenerate_index_and_spaces | 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 do |header|
if header.is_valid?
if (duplicate_pos = @index.get(header.id))
PEROBS.log.error "FlatFile contains multiple blobs for ID " +
"#{header.id}. First blob is at address #{duplicate_pos}. " +
"Other blob found at address #{header.addr}."
if header.length > 0
@space_list.add_space(header.addr, header.length)
end
discard_damaged_blob(header)
else
@index.insert(header.id, header.addr)
end
else
if header.length > 0
@space_list.add_space(header.addr, header.length)
end
end
pm.update(header.addr)
end
end
sync
end | ruby | 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 do |header|
if header.is_valid?
if (duplicate_pos = @index.get(header.id))
PEROBS.log.error "FlatFile contains multiple blobs for ID " +
"#{header.id}. First blob is at address #{duplicate_pos}. " +
"Other blob found at address #{header.addr}."
if header.length > 0
@space_list.add_space(header.addr, header.length)
end
discard_damaged_blob(header)
else
@index.insert(header.id, header.addr)
end
else
if header.length > 0
@space_list.add_space(header.addr, header.length)
end
end
pm.update(header.addr)
end
end
sync
end | [
"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",
"do",
"|",
"header",
"|",
"if",
"header",
".",
"is_valid?",
"if",
"(",
"duplicate_pos",
"=",
"@index",
".",
"get",
"(",
"header",
".",
"id",
")",
")",
"PEROBS",
".",
"log",
".",
"error",
"\"FlatFile contains multiple blobs for ID \"",
"+",
"\"#{header.id}. First blob is at address #{duplicate_pos}. \"",
"+",
"\"Other blob found at address #{header.addr}.\"",
"if",
"header",
".",
"length",
">",
"0",
"@space_list",
".",
"add_space",
"(",
"header",
".",
"addr",
",",
"header",
".",
"length",
")",
"end",
"discard_damaged_blob",
"(",
"header",
")",
"else",
"@index",
".",
"insert",
"(",
"header",
".",
"id",
",",
"header",
".",
"addr",
")",
"end",
"else",
"if",
"header",
".",
"length",
">",
"0",
"@space_list",
".",
"add_space",
"(",
"header",
".",
"addr",
",",
"header",
".",
"length",
")",
"end",
"end",
"pm",
".",
"update",
"(",
"header",
".",
"addr",
")",
"end",
"end",
"sync",
"end"
] | This method clears the index tree and the free space list and
regenerates them from the FlatFile. | [
"This",
"method",
"clears",
"the",
"index",
"tree",
"and",
"the",
"free",
"space",
"list",
"and",
"regenerates",
"them",
"from",
"the",
"FlatFile",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFile.rb#L580-L612 | train |
notonthehighstreet/chicago | lib/chicago/rake_tasks.rb | Chicago.RakeTasks.define | def define
namespace :db do
desc "Write Null dimension records"
task :create_null_records do
# TODO: replace this with proper logging.
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 :write_migrations do
writer = Database::MigrationFileWriter.new
writer.write_migration_file(@staging_db, @schema,
staging_directory)
if @presentation_db
writer.write_migration_file(@presentation_db, @schema,
presentation_directory, false)
end
end
end
end | ruby | def define
namespace :db do
desc "Write Null dimension records"
task :create_null_records do
# TODO: replace this with proper logging.
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 :write_migrations do
writer = Database::MigrationFileWriter.new
writer.write_migration_file(@staging_db, @schema,
staging_directory)
if @presentation_db
writer.write_migration_file(@presentation_db, @schema,
presentation_directory, false)
end
end
end
end | [
"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",
":write_migrations",
"do",
"writer",
"=",
"Database",
"::",
"MigrationFileWriter",
".",
"new",
"writer",
".",
"write_migration_file",
"(",
"@staging_db",
",",
"@schema",
",",
"staging_directory",
")",
"if",
"@presentation_db",
"writer",
".",
"write_migration_file",
"(",
"@presentation_db",
",",
"@schema",
",",
"presentation_directory",
",",
"false",
")",
"end",
"end",
"end",
"end"
] | Defines the rake tasks.
@api private | [
"Defines",
"the",
"rake",
"tasks",
"."
] | 428e94f8089d2f36fdcff2e27ea2af572b816def | https://github.com/notonthehighstreet/chicago/blob/428e94f8089d2f36fdcff2e27ea2af572b816def/lib/chicago/rake_tasks.rb#L35-L58 | train |
scrapper/perobs | lib/perobs/LockFile.rb | PEROBS.LockFile.lock | 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)
# We have taken the lock. Write the PID into the file and leave it
# open.
@file.write($$)
@file.flush
@file.fsync
@file.truncate(@file.pos)
PEROBS.log.debug "Lock file #{@file_name} has been taken for " +
"process #{$$}"
return true
else
# We did not manage to take the lock file.
if @file.mtime <= Time.now - @timeout_secs
pid = @file.read.to_i
PEROBS.log.info "Old lock file found for PID #{pid}. " +
"Removing lock."
if is_running?(pid)
send_signal('TERM', pid)
# Give the process 3 seconds to terminate gracefully.
sleep 3
# Then send a SIGKILL to ensure it's gone.
send_signal('KILL', pid) if is_running?(pid)
end
@file.close
File.delete(@file_name) if File.exist?(@file_name)
else
PEROBS.log.debug "Lock file #{@file_name} is taken. Trying " +
"to get it #{retries} more times."
end
end
rescue => e
PEROBS.log.error "Cannot take lock file #{@file_name}: #{e.message}"
return false
end
retries -= 1
sleep(@pause_secs)
end
PEROBS.log.info "Failed to get lock file #{@file_name} due to timeout"
false
end | ruby | 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)
# We have taken the lock. Write the PID into the file and leave it
# open.
@file.write($$)
@file.flush
@file.fsync
@file.truncate(@file.pos)
PEROBS.log.debug "Lock file #{@file_name} has been taken for " +
"process #{$$}"
return true
else
# We did not manage to take the lock file.
if @file.mtime <= Time.now - @timeout_secs
pid = @file.read.to_i
PEROBS.log.info "Old lock file found for PID #{pid}. " +
"Removing lock."
if is_running?(pid)
send_signal('TERM', pid)
# Give the process 3 seconds to terminate gracefully.
sleep 3
# Then send a SIGKILL to ensure it's gone.
send_signal('KILL', pid) if is_running?(pid)
end
@file.close
File.delete(@file_name) if File.exist?(@file_name)
else
PEROBS.log.debug "Lock file #{@file_name} is taken. Trying " +
"to get it #{retries} more times."
end
end
rescue => e
PEROBS.log.error "Cannot take lock file #{@file_name}: #{e.message}"
return false
end
retries -= 1
sleep(@pause_secs)
end
PEROBS.log.info "Failed to get lock file #{@file_name} due to timeout"
false
end | [
"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 #{@file_name} has been taken for \"",
"+",
"\"process #{$$}\"",
"return",
"true",
"else",
"if",
"@file",
".",
"mtime",
"<=",
"Time",
".",
"now",
"-",
"@timeout_secs",
"pid",
"=",
"@file",
".",
"read",
".",
"to_i",
"PEROBS",
".",
"log",
".",
"info",
"\"Old lock file found for PID #{pid}. \"",
"+",
"\"Removing lock.\"",
"if",
"is_running?",
"(",
"pid",
")",
"send_signal",
"(",
"'TERM'",
",",
"pid",
")",
"sleep",
"3",
"send_signal",
"(",
"'KILL'",
",",
"pid",
")",
"if",
"is_running?",
"(",
"pid",
")",
"end",
"@file",
".",
"close",
"File",
".",
"delete",
"(",
"@file_name",
")",
"if",
"File",
".",
"exist?",
"(",
"@file_name",
")",
"else",
"PEROBS",
".",
"log",
".",
"debug",
"\"Lock file #{@file_name} is taken. Trying \"",
"+",
"\"to get it #{retries} more times.\"",
"end",
"end",
"rescue",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"error",
"\"Cannot take lock file #{@file_name}: #{e.message}\"",
"return",
"false",
"end",
"retries",
"-=",
"1",
"sleep",
"(",
"@pause_secs",
")",
"end",
"PEROBS",
".",
"log",
".",
"info",
"\"Failed to get lock file #{@file_name} due to timeout\"",
"false",
"end"
] | Create a new lock for the given file.
@param file_name [String] file name of the lock file
@param options [Hash] See case statement
Attempt to take the lock.
@return [Boolean] true if lock was taken, false otherwise | [
"Create",
"a",
"new",
"lock",
"for",
"the",
"given",
"file",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/LockFile.rb#L68-L117 | train |
scrapper/perobs | lib/perobs/LockFile.rb | PEROBS.LockFile.unlock | 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 file #{@file_name} failed: " +
e.message
return false
end
true
end | ruby | 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 file #{@file_name} failed: " +
e.message
return false
end
true
end | [
"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 file #{@file_name} failed: \"",
"+",
"e",
".",
"message",
"return",
"false",
"end",
"true",
"end"
] | Release the lock again. | [
"Release",
"the",
"lock",
"again",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/LockFile.rb#L126-L146 | train |
scrapper/perobs | lib/perobs/LockFile.rb | PEROBS.LockFile.forced_unlock | 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 | ruby | 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 | [
"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. | [
"Erase",
"the",
"lock",
"file",
".",
"It",
"s",
"essentially",
"a",
"forced",
"unlock",
"method",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/LockFile.rb#L149-L160 | train |
mreq/wmctile | lib/wmctile/router.rb | Wmctile.Router.window | 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]
# Exec the command
puts "Executing command: #{@arguments[:exec]}"
system "#{@arguments[:exec]} &"
else
raise Errors::WindowNotFound, @window_strings[index]
end
end | ruby | 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]
# Exec the command
puts "Executing command: #{@arguments[:exec]}"
system "#{@arguments[:exec]} &"
else
raise Errors::WindowNotFound, @window_strings[index]
end
end | [
"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]} &\"",
"else",
"raise",
"Errors",
"::",
"WindowNotFound",
",",
"@window_strings",
"[",
"index",
"]",
"end",
"end"
] | Starts wmctile, runs the required methods.
@param [Hash] command line options
@param [Array] window_strings ARGV array
Creates a new window based on @arguments and @window_strings.
If no window is found, checks for the -x/--exec argument. If present, executes it.
If there's no -x command and a window is not found, raises an error.
@param [Integer] index index of the window from matching windows array
@return [Window] window instance | [
"Starts",
"wmctile",
"runs",
"the",
"required",
"methods",
"."
] | a41af5afa310b09c8ba1bd45a134b9b2a87d1a35 | https://github.com/mreq/wmctile/blob/a41af5afa310b09c8ba1bd45a134b9b2a87d1a35/lib/wmctile/router.rb#L55-L69 | train |
mreq/wmctile | lib/wmctile/router.rb | Wmctile.Router.switch_to_workspace | 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'
# must be -2 as -1 is the current workspace
target_workspace = Wmctile.memory.get(:workspace_history)[-2]
end
system "wmctrl -s #{target_workspace}"
target_workspace
end | ruby | 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'
# must be -2 as -1 is the current workspace
target_workspace = Wmctile.memory.get(:workspace_history)[-2]
end
system "wmctrl -s #{target_workspace}"
target_workspace
end | [
"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",
"]",
"end",
"system",
"\"wmctrl -s #{target_workspace}\"",
"target_workspace",
"end"
] | Switch to target_workspace.
@param [String] target_workspace Target workspace index or "next"/"previous".
@return [Integer] Target workspace number | [
"Switch",
"to",
"target_workspace",
"."
] | a41af5afa310b09c8ba1bd45a134b9b2a87d1a35 | https://github.com/mreq/wmctile/blob/a41af5afa310b09c8ba1bd45a134b9b2a87d1a35/lib/wmctile/router.rb#L78-L89 | train |
ghempton/state_manager | lib/state_manager/base.rb | StateManager.Base.transition_to | def transition_to(path, current_state=self.current_state)
path = path.to_s
state = current_state || self
exit_states = []
# Find the nearest parent state on the path of the current state which
# has a sub-state at the given path
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_states = state.find_states(path)
end
# The first time we enter a state, the state_manager gets entered as well
new_states.unshift(self) unless has_state?
# Can only transition to leaf states
# TODO: transition to the initial_state of the state?
raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?
enter_states = new_states - exit_states
exit_states = exit_states - new_states
from_state = current_state
# TODO: does it make more sense to throw an error instead of allowing
# a transition to the current state?
to_state = enter_states.last || from_state
run_before_callbacks(from_state, to_state, current_event, enter_states, exit_states)
# Set the state on the underlying resource
self.current_state = to_state
run_after_callbacks(from_state, to_state, current_event, enter_states, exit_states)
end | ruby | def transition_to(path, current_state=self.current_state)
path = path.to_s
state = current_state || self
exit_states = []
# Find the nearest parent state on the path of the current state which
# has a sub-state at the given path
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_states = state.find_states(path)
end
# The first time we enter a state, the state_manager gets entered as well
new_states.unshift(self) unless has_state?
# Can only transition to leaf states
# TODO: transition to the initial_state of the state?
raise(InvalidTransition, transition_error(path)) unless new_states.last.leaf?
enter_states = new_states - exit_states
exit_states = exit_states - new_states
from_state = current_state
# TODO: does it make more sense to throw an error instead of allowing
# a transition to the current state?
to_state = enter_states.last || from_state
run_before_callbacks(from_state, to_state, current_event, enter_states, exit_states)
# Set the state on the underlying resource
self.current_state = to_state
run_after_callbacks(from_state, to_state, current_event, enter_states, exit_states)
end | [
"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_states",
"=",
"state",
".",
"find_states",
"(",
"path",
")",
"end",
"new_states",
".",
"unshift",
"(",
"self",
")",
"unless",
"has_state?",
"raise",
"(",
"InvalidTransition",
",",
"transition_error",
"(",
"path",
")",
")",
"unless",
"new_states",
".",
"last",
".",
"leaf?",
"enter_states",
"=",
"new_states",
"-",
"exit_states",
"exit_states",
"=",
"exit_states",
"-",
"new_states",
"from_state",
"=",
"current_state",
"to_state",
"=",
"enter_states",
".",
"last",
"||",
"from_state",
"run_before_callbacks",
"(",
"from_state",
",",
"to_state",
",",
"current_event",
",",
"enter_states",
",",
"exit_states",
")",
"self",
".",
"current_state",
"=",
"to_state",
"run_after_callbacks",
"(",
"from_state",
",",
"to_state",
",",
"current_event",
",",
"enter_states",
",",
"exit_states",
")",
"end"
] | Transitions to the state at the specified path. The path can be relative
to any state along the current state's path. | [
"Transitions",
"to",
"the",
"state",
"at",
"the",
"specified",
"path",
".",
"The",
"path",
"can",
"be",
"relative",
"to",
"any",
"state",
"along",
"the",
"current",
"state",
"s",
"path",
"."
] | 0e10fbb3c4b7718aa6602e240f4d8adf9cd72008 | https://github.com/ghempton/state_manager/blob/0e10fbb3c4b7718aa6602e240f4d8adf9cd72008/lib/state_manager/base.rb#L38-L74 | train |
ghempton/state_manager | lib/state_manager/base.rb | StateManager.Base.available_events | def available_events
state = current_state
ret = {}
while(state) do
ret = state.class.specification.events.merge(ret)
state = state.parent_state
end
ret
end | ruby | def available_events
state = current_state
ret = {}
while(state) do
ret = state.class.specification.events.merge(ret)
state = state.parent_state
end
ret
end | [
"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 | [
"All",
"events",
"the",
"current",
"state",
"will",
"respond",
"to"
] | 0e10fbb3c4b7718aa6602e240f4d8adf9cd72008 | https://github.com/ghempton/state_manager/blob/0e10fbb3c4b7718aa6602e240f4d8adf9cd72008/lib/state_manager/base.rb#L165-L173 | train |
tagoh/ruby-bugzilla | lib/bugzilla/product.rb | Bugzilla.Product.enterable_products | def enterable_products
ids = get_enterable_products
Hash[*get(ids)['products'].map {|x| [x['name'], x]}.flatten]
end | ruby | def enterable_products
ids = get_enterable_products
Hash[*get(ids)['products'].map {|x| [x['name'], x]}.flatten]
end | [
"def",
"enterable_products",
"ids",
"=",
"get_enterable_products",
"Hash",
"[",
"*",
"get",
"(",
"ids",
")",
"[",
"'products'",
"]",
".",
"map",
"{",
"|",
"x",
"|",
"[",
"x",
"[",
"'name'",
"]",
",",
"x",
"]",
"}",
".",
"flatten",
"]",
"end"
] | def selectable_products
=begin rdoc
==== Bugzilla::Product#enterable_products
Returns Hash table for the products information that the user
can enter bugs against. the Hash key is the product name and
containing a Hash table which contains id, name, description,
is_active, default_milestone, has_uncomfirmed, classification,
components, versions and milestones. please see
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html#get
for more details.
=end | [
"def",
"selectable_products",
"=",
"begin",
"rdoc"
] | 5aabec1b045473bcd6e6ac7427b68adb3e3b4886 | https://github.com/tagoh/ruby-bugzilla/blob/5aabec1b045473bcd6e6ac7427b68adb3e3b4886/lib/bugzilla/product.rb#L69-L72 | train |
tagoh/ruby-bugzilla | lib/bugzilla/product.rb | Bugzilla.Product.accessible_products | def accessible_products
ids = get_accessible_products
Hash[*get(ids)['products'].map {|x| [x['name'], x]}.flatten]
end | ruby | def accessible_products
ids = get_accessible_products
Hash[*get(ids)['products'].map {|x| [x['name'], x]}.flatten]
end | [
"def",
"accessible_products",
"ids",
"=",
"get_accessible_products",
"Hash",
"[",
"*",
"get",
"(",
"ids",
")",
"[",
"'products'",
"]",
".",
"map",
"{",
"|",
"x",
"|",
"[",
"x",
"[",
"'name'",
"]",
",",
"x",
"]",
"}",
".",
"flatten",
"]",
"end"
] | def enterable_products
=begin rdoc
==== Bugzilla::Product#accessible_products
Returns Hash table for the products information that the user
can search or enter bugs against. the Hash key is the product
name and containing a Hash table which contains id, name, description,
is_active, default_milestone, has_uncomfirmed, classification,
components, versions and milestones. please see
http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Product.html#get
for more details.
=end | [
"def",
"enterable_products",
"=",
"begin",
"rdoc"
] | 5aabec1b045473bcd6e6ac7427b68adb3e3b4886 | https://github.com/tagoh/ruby-bugzilla/blob/5aabec1b045473bcd6e6ac7427b68adb3e3b4886/lib/bugzilla/product.rb#L88-L91 | train |
scrapper/perobs | lib/perobs/FlatFileDB.rb | PEROBS.FlatFileDB.put_hash | 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 | ruby | 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 | [
"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.
@param name [String] Name of the hash. Will be used as file name.
@param hash [Hash] A Hash that maps String objects to strings or
numbers. | [
"Store",
"a",
"simple",
"Hash",
"as",
"a",
"JSON",
"encoded",
"file",
"into",
"the",
"DB",
"directory",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/FlatFileDB.rb#L109-L116 | train |
danielpclark/PolyBelongsTo | lib/poly_belongs_to/core.rb | PolyBelongsTo.Core.pbt_parent | 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 | ruby | 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 | [
"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.
@return [Object, nil] ActiveRecord object instasnce | [
"Get",
"the",
"parent",
"relation",
".",
"Polymorphic",
"relations",
"are",
"prioritized",
"first",
"."
] | 38d51d37f9148613519d6b6d56bdf4d0884f0e86 | https://github.com/danielpclark/PolyBelongsTo/blob/38d51d37f9148613519d6b6d56bdf4d0884f0e86/lib/poly_belongs_to/core.rb#L162-L171 | train |
danielpclark/PolyBelongsTo | lib/poly_belongs_to/core.rb | PolyBelongsTo.Core.pbt_top_parent | 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 | ruby | 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 | [
"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.
@return [Object, nil] top parent ActiveRecord object instace | [
"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",
"."
] | 38d51d37f9148613519d6b6d56bdf4d0884f0e86 | https://github.com/danielpclark/PolyBelongsTo/blob/38d51d37f9148613519d6b6d56bdf4d0884f0e86/lib/poly_belongs_to/core.rb#L176-L185 | train |
danielpclark/PolyBelongsTo | lib/poly_belongs_to/core.rb | PolyBelongsTo.Core.pbt_parents | 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 | ruby | 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 | [
"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.
@return [Array<Object>] ActiveRecord classes of parent objects. | [
"All",
"belongs_to",
"parents",
"as",
"class",
"objects",
".",
"One",
"if",
"polymorphic",
"."
] | 38d51d37f9148613519d6b6d56bdf4d0884f0e86 | https://github.com/danielpclark/PolyBelongsTo/blob/38d51d37f9148613519d6b6d56bdf4d0884f0e86/lib/poly_belongs_to/core.rb#L189-L197 | train |
PublicHealthEngland/ndr_support | lib/ndr_support/password.rb | NdrSupport.Password.valid? | def valid?(string, word_list: [])
string = prepare_string(string.to_s.dup)
slug = slugify(strip_common_words(string, word_list))
meets_requirements?(slug)
end | ruby | def valid?(string, word_list: [])
string = prepare_string(string.to_s.dup)
slug = slugify(strip_common_words(string, word_list))
meets_requirements?(slug)
end | [
"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`.
NdrSupport::Password.valid?('google password') #=> false
NdrSupport::Password.valid?(SecureRandom.hex(12)) #=> true | [
"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",
"."
] | 6daf98ca972e79de1c8457eb720f058b03ead21c | https://github.com/PublicHealthEngland/ndr_support/blob/6daf98ca972e79de1c8457eb720f058b03ead21c/lib/ndr_support/password.rb#L18-L23 | train |
xinminlabs/synvert-core | lib/synvert/core/rewriter.rb | Synvert::Core.Rewriter.add_file | 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 content
end
end | ruby | 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 content
end
end | [
"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",
"content",
"end",
"end"
] | Parses add_file dsl, it adds a new file.
@param filename [String] file name of newly created file.
@param content [String] file body of newly created file. | [
"Parses",
"add_file",
"dsl",
"it",
"adds",
"a",
"new",
"file",
"."
] | a490bfd30eaec81002d10f8fb61b49138708e46c | https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter.rb#L227-L240 | train |
xinminlabs/synvert-core | lib/synvert/core/rewriter.rb | Synvert::Core.Rewriter.remove_file | 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 | ruby | 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 | [
"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.
@param filename [String] file name. | [
"Parses",
"remove_file",
"dsl",
"it",
"removes",
"a",
"file",
"."
] | a490bfd30eaec81002d10f8fb61b49138708e46c | https://github.com/xinminlabs/synvert-core/blob/a490bfd30eaec81002d10f8fb61b49138708e46c/lib/synvert/core/rewriter.rb#L245-L250 | train |
Absolight/epp-client | lib/epp-client/connection.rb | EPPClient.Connection.open_connection | def open_connection
@tcpserver = TCPSocket.new(server, port)
@socket = OpenSSL::SSL::SSLSocket.new(@tcpserver, @context)
# Synchronously close the connection & socket
@socket.sync_close
# Connect
@socket.connect
# Get the initial greeting frame
greeting_process(one_frame)
end | ruby | def open_connection
@tcpserver = TCPSocket.new(server, port)
@socket = OpenSSL::SSL::SSLSocket.new(@tcpserver, @context)
# Synchronously close the connection & socket
@socket.sync_close
# Connect
@socket.connect
# Get the initial greeting frame
greeting_process(one_frame)
end | [
"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. | [
"Establishes",
"the",
"connection",
"to",
"the",
"server",
"if",
"successful",
"will",
"return",
"the",
"greeting",
"frame",
"."
] | c0025daee5e7087f60b654595a8e7d92e966c54e | https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/connection.rb#L8-L20 | train |
Absolight/epp-client | lib/epp-client/connection.rb | EPPClient.Connection.close_connection | 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 | ruby | 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 | [
"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 | [
"Gracefully",
"close",
"the",
"connection"
] | c0025daee5e7087f60b654595a8e7d92e966c54e | https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/connection.rb#L34-L46 | train |
Absolight/epp-client | lib/epp-client/connection.rb | EPPClient.Connection.one_frame | 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 | ruby | 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 | [
"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. | [
"gets",
"a",
"frame",
"from",
"the",
"socket",
"and",
"returns",
"the",
"parsed",
"response",
"."
] | c0025daee5e7087f60b654595a8e7d92e966c54e | https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/connection.rb#L62-L68 | train |
iconara/snogmetrics | lib/snogmetrics/kissmetrics_api.rb | Snogmetrics.KissmetricsApi.identify | def identify(identity)
unless @session[:km_identity] == identity
queue.delete_if { |e| e.first == 'identify' }
queue << ['identify', identity]
@session[:km_identity] = identity
end
end | ruby | def identify(identity)
unless @session[:km_identity] == identity
queue.delete_if { |e| e.first == 'identify' }
queue << ['identify', identity]
@session[:km_identity] = identity
end
end | [
"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. | [
"The",
"equivalent",
"of",
"the",
"KM",
".",
"identify",
"method",
"of",
"the",
"JavaScript",
"API",
"."
] | 1742fb77dee1378934fbad8b78790f59bff20c35 | https://github.com/iconara/snogmetrics/blob/1742fb77dee1378934fbad8b78790f59bff20c35/lib/snogmetrics/kissmetrics_api.rb#L22-L28 | train |
bratta/googlevoiceapi | lib/googlevoiceapi.rb | GoogleVoice.Api.sms | 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 | ruby | 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 | [
"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 | [
"Send",
"a",
"text",
"message",
"to",
"remote_number"
] | 5d6163209bda665ba0cd7bbe723e59f6f7085705 | https://github.com/bratta/googlevoiceapi/blob/5d6163209bda665ba0cd7bbe723e59f6f7085705/lib/googlevoiceapi.rb#L56-L61 | train |
bratta/googlevoiceapi | lib/googlevoiceapi.rb | GoogleVoice.Api.call | 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, :phoneType => 2, :subscriberNumber => 'undefined', :remember => '0', "_rnr_se" => @rnr_se)
end | ruby | 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, :phoneType => 2, :subscriberNumber => 'undefined', :remember => '0', "_rnr_se" => @rnr_se)
end | [
"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",
",",
":phoneType",
"=>",
"2",
",",
":subscriberNumber",
"=>",
"'undefined'",
",",
":remember",
"=>",
"'0'",
",",
"\"_rnr_se\"",
"=>",
"@rnr_se",
")",
"end"
] | Place a call to remote_number, and ring back forwarding_number which
should be set up on the currently logged in Google Voice account | [
"Place",
"a",
"call",
"to",
"remote_number",
"and",
"ring",
"back",
"forwarding_number",
"which",
"should",
"be",
"set",
"up",
"on",
"the",
"currently",
"logged",
"in",
"Google",
"Voice",
"account"
] | 5d6163209bda665ba0cd7bbe723e59f6f7085705 | https://github.com/bratta/googlevoiceapi/blob/5d6163209bda665ba0cd7bbe723e59f6f7085705/lib/googlevoiceapi.rb#L65-L70 | train |
bratta/googlevoiceapi | lib/googlevoiceapi.rb | GoogleVoice.Api.init_xml_methods | 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 | ruby | 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 | [
"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 long run. | [
"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",
"long",
"run",
"."
] | 5d6163209bda665ba0cd7bbe723e59f6f7085705 | https://github.com/bratta/googlevoiceapi/blob/5d6163209bda665ba0cd7bbe723e59f6f7085705/lib/googlevoiceapi.rb#L104-L112 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.setHTTPConnection | 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.set_auth(proxy_options["proxy_server"], proxy_options["proxy_user"], proxy_options["proxy_password"])
else
@httpConnection = HTTPClient.new
end
else
if proxy_options
@httpProxy = Net::HTTP::Proxy(proxy_options["proxy_server"], proxy_options["proxy_port"], proxy_options["proxy_user"], proxy_options["proxy_password"])
@httpConnection = @httpProxy.new( "#{@org}.#{@domain}.com", useSSL ? 443 : 80)
else
@httpConnection = Net::HTTP.new( "#{@org}.#{@domain}.com", useSSL ? 443 : 80 )
end
@httpConnection.use_ssl = useSSL
@httpConnection.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end | ruby | 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.set_auth(proxy_options["proxy_server"], proxy_options["proxy_user"], proxy_options["proxy_password"])
else
@httpConnection = HTTPClient.new
end
else
if proxy_options
@httpProxy = Net::HTTP::Proxy(proxy_options["proxy_server"], proxy_options["proxy_port"], proxy_options["proxy_user"], proxy_options["proxy_password"])
@httpConnection = @httpProxy.new( "#{@org}.#{@domain}.com", useSSL ? 443 : 80)
else
@httpConnection = Net::HTTP.new( "#{@org}.#{@domain}.com", useSSL ? 443 : 80 )
end
@httpConnection.use_ssl = useSSL
@httpConnection.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end | [
"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",
".",
"set_auth",
"(",
"proxy_options",
"[",
"\"proxy_server\"",
"]",
",",
"proxy_options",
"[",
"\"proxy_user\"",
"]",
",",
"proxy_options",
"[",
"\"proxy_password\"",
"]",
")",
"else",
"@httpConnection",
"=",
"HTTPClient",
".",
"new",
"end",
"else",
"if",
"proxy_options",
"@httpProxy",
"=",
"Net",
"::",
"HTTP",
"::",
"Proxy",
"(",
"proxy_options",
"[",
"\"proxy_server\"",
"]",
",",
"proxy_options",
"[",
"\"proxy_port\"",
"]",
",",
"proxy_options",
"[",
"\"proxy_user\"",
"]",
",",
"proxy_options",
"[",
"\"proxy_password\"",
"]",
")",
"@httpConnection",
"=",
"@httpProxy",
".",
"new",
"(",
"\"#{@org}.#{@domain}.com\"",
",",
"useSSL",
"?",
"443",
":",
"80",
")",
"else",
"@httpConnection",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"\"#{@org}.#{@domain}.com\"",
",",
"useSSL",
"?",
"443",
":",
"80",
")",
"end",
"@httpConnection",
".",
"use_ssl",
"=",
"useSSL",
"@httpConnection",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"end",
"end"
] | Initializes the connection to QuickBase. | [
"Initializes",
"the",
"connection",
"to",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L153-L174 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.setHTTPConnectionAndqbhost | def setHTTPConnectionAndqbhost( useSSL, org = "www", domain = "quickbase", proxy_options = nil )
setHTTPConnection( useSSL, org, domain, proxy_options )
setqbhost( useSSL, org, domain )
end | ruby | def setHTTPConnectionAndqbhost( useSSL, org = "www", domain = "quickbase", proxy_options = nil )
setHTTPConnection( useSSL, org, domain, proxy_options )
setqbhost( useSSL, org, domain )
end | [
"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. | [
"Initializes",
"the",
"connection",
"to",
"QuickBase",
"and",
"sets",
"the",
"QuickBase",
"URL",
"and",
"port",
"to",
"use",
"for",
"requests",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L191-L194 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.sendRequest | def sendRequest( api_Request, xmlRequestData = nil )
fire( "onSendRequest" )
resetErrorInfo
# set up the request
getDBforRequestURL( api_Request )
getAuthenticationXMLforRequest( api_Request )
isHTMLRequest = isHTMLRequest?( api_Request )
api_Request = "API_" + api_Request.to_s if prependAPI?( api_Request )
xmlRequestData << toXML( :udata, @udata ) if @udata and @udata.length > 0
xmlRequestData << toXML( :rdr, @rdr ) if @rdr and @rdr.length > 0
xmlRequestData << toXML( :xsl, @xsl ) if @xsl and @xsl.length > 0
xmlRequestData << toXML( :encoding, @encoding ) if @encoding and @encoding.length > 0
if xmlRequestData
@requestXML = toXML( :qdbapi, @authenticationXML + xmlRequestData )
else
@requestXML = toXML( :qdbapi, @authenticationXML )
end
@requestHeaders = @standardRequestHeaders
@requestHeaders["Content-Length"] = "#{@requestXML.length}"
@requestHeaders["QUICKBASE-ACTION"] = api_Request
@requestURL = "#{@qbhost}#{@dbidForRequestURL}"
printRequest( @requestURL, @requestHeaders, @requestXML ) if @printRequestsAndResponses
@logger.logRequest( @dbidForRequestURL, api_Request, @requestXML ) if @logger
begin
# send the request
if USING_HTTPCLIENT
response = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
@responseCode = response.status
@responseXML = response.content
else
if Net::HTTP.version_1_2?
response = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
@responseCode = response.code
@responseXML = response.body
else
@responseCode, @responseXML = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
end
end
printResponse( @responseCode, @responseXML ) if @printRequestsAndResponses
if not isHTMLRequest
processResponse( @responseXML )
end
@logger.logResponse( @lastError, @responseXML ) if @logger
fireDBChangeEvents
rescue Net::HTTPBadResponse => error
@lastError = "Bad HTTP Response: #{error}"
rescue Net::HTTPHeaderSyntaxError => error
@lastError = "Bad HTTP header syntax: #{error}"
rescue StandardError => error
@lastError = "Error processing #{api_Request} request: #{error}"
end
@requestSucceeded = ( @errcode == "0" and @lastError == "" )
fire( @requestSucceeded ? "onRequestSucceeded" : "onRequestFailed" )
if @stopOnError and !@requestSucceeded
raise @lastError
end
end | ruby | def sendRequest( api_Request, xmlRequestData = nil )
fire( "onSendRequest" )
resetErrorInfo
# set up the request
getDBforRequestURL( api_Request )
getAuthenticationXMLforRequest( api_Request )
isHTMLRequest = isHTMLRequest?( api_Request )
api_Request = "API_" + api_Request.to_s if prependAPI?( api_Request )
xmlRequestData << toXML( :udata, @udata ) if @udata and @udata.length > 0
xmlRequestData << toXML( :rdr, @rdr ) if @rdr and @rdr.length > 0
xmlRequestData << toXML( :xsl, @xsl ) if @xsl and @xsl.length > 0
xmlRequestData << toXML( :encoding, @encoding ) if @encoding and @encoding.length > 0
if xmlRequestData
@requestXML = toXML( :qdbapi, @authenticationXML + xmlRequestData )
else
@requestXML = toXML( :qdbapi, @authenticationXML )
end
@requestHeaders = @standardRequestHeaders
@requestHeaders["Content-Length"] = "#{@requestXML.length}"
@requestHeaders["QUICKBASE-ACTION"] = api_Request
@requestURL = "#{@qbhost}#{@dbidForRequestURL}"
printRequest( @requestURL, @requestHeaders, @requestXML ) if @printRequestsAndResponses
@logger.logRequest( @dbidForRequestURL, api_Request, @requestXML ) if @logger
begin
# send the request
if USING_HTTPCLIENT
response = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
@responseCode = response.status
@responseXML = response.content
else
if Net::HTTP.version_1_2?
response = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
@responseCode = response.code
@responseXML = response.body
else
@responseCode, @responseXML = @httpConnection.post( @requestURL, @requestXML, @requestHeaders )
end
end
printResponse( @responseCode, @responseXML ) if @printRequestsAndResponses
if not isHTMLRequest
processResponse( @responseXML )
end
@logger.logResponse( @lastError, @responseXML ) if @logger
fireDBChangeEvents
rescue Net::HTTPBadResponse => error
@lastError = "Bad HTTP Response: #{error}"
rescue Net::HTTPHeaderSyntaxError => error
@lastError = "Bad HTTP header syntax: #{error}"
rescue StandardError => error
@lastError = "Error processing #{api_Request} request: #{error}"
end
@requestSucceeded = ( @errcode == "0" and @lastError == "" )
fire( @requestSucceeded ? "onRequestSucceeded" : "onRequestFailed" )
if @stopOnError and !@requestSucceeded
raise @lastError
end
end | [
"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",
"(",
":udata",
",",
"@udata",
")",
"if",
"@udata",
"and",
"@udata",
".",
"length",
">",
"0",
"xmlRequestData",
"<<",
"toXML",
"(",
":rdr",
",",
"@rdr",
")",
"if",
"@rdr",
"and",
"@rdr",
".",
"length",
">",
"0",
"xmlRequestData",
"<<",
"toXML",
"(",
":xsl",
",",
"@xsl",
")",
"if",
"@xsl",
"and",
"@xsl",
".",
"length",
">",
"0",
"xmlRequestData",
"<<",
"toXML",
"(",
":encoding",
",",
"@encoding",
")",
"if",
"@encoding",
"and",
"@encoding",
".",
"length",
">",
"0",
"if",
"xmlRequestData",
"@requestXML",
"=",
"toXML",
"(",
":qdbapi",
",",
"@authenticationXML",
"+",
"xmlRequestData",
")",
"else",
"@requestXML",
"=",
"toXML",
"(",
":qdbapi",
",",
"@authenticationXML",
")",
"end",
"@requestHeaders",
"=",
"@standardRequestHeaders",
"@requestHeaders",
"[",
"\"Content-Length\"",
"]",
"=",
"\"#{@requestXML.length}\"",
"@requestHeaders",
"[",
"\"QUICKBASE-ACTION\"",
"]",
"=",
"api_Request",
"@requestURL",
"=",
"\"#{@qbhost}#{@dbidForRequestURL}\"",
"printRequest",
"(",
"@requestURL",
",",
"@requestHeaders",
",",
"@requestXML",
")",
"if",
"@printRequestsAndResponses",
"@logger",
".",
"logRequest",
"(",
"@dbidForRequestURL",
",",
"api_Request",
",",
"@requestXML",
")",
"if",
"@logger",
"begin",
"if",
"USING_HTTPCLIENT",
"response",
"=",
"@httpConnection",
".",
"post",
"(",
"@requestURL",
",",
"@requestXML",
",",
"@requestHeaders",
")",
"@responseCode",
"=",
"response",
".",
"status",
"@responseXML",
"=",
"response",
".",
"content",
"else",
"if",
"Net",
"::",
"HTTP",
".",
"version_1_2?",
"response",
"=",
"@httpConnection",
".",
"post",
"(",
"@requestURL",
",",
"@requestXML",
",",
"@requestHeaders",
")",
"@responseCode",
"=",
"response",
".",
"code",
"@responseXML",
"=",
"response",
".",
"body",
"else",
"@responseCode",
",",
"@responseXML",
"=",
"@httpConnection",
".",
"post",
"(",
"@requestURL",
",",
"@requestXML",
",",
"@requestHeaders",
")",
"end",
"end",
"printResponse",
"(",
"@responseCode",
",",
"@responseXML",
")",
"if",
"@printRequestsAndResponses",
"if",
"not",
"isHTMLRequest",
"processResponse",
"(",
"@responseXML",
")",
"end",
"@logger",
".",
"logResponse",
"(",
"@lastError",
",",
"@responseXML",
")",
"if",
"@logger",
"fireDBChangeEvents",
"rescue",
"Net",
"::",
"HTTPBadResponse",
"=>",
"error",
"@lastError",
"=",
"\"Bad HTTP Response: #{error}\"",
"rescue",
"Net",
"::",
"HTTPHeaderSyntaxError",
"=>",
"error",
"@lastError",
"=",
"\"Bad HTTP header syntax: #{error}\"",
"rescue",
"StandardError",
"=>",
"error",
"@lastError",
"=",
"\"Error processing #{api_Request} request: #{error}\"",
"end",
"@requestSucceeded",
"=",
"(",
"@errcode",
"==",
"\"0\"",
"and",
"@lastError",
"==",
"\"\"",
")",
"fire",
"(",
"@requestSucceeded",
"?",
"\"onRequestSucceeded\"",
":",
"\"onRequestFailed\"",
")",
"if",
"@stopOnError",
"and",
"!",
"@requestSucceeded",
"raise",
"@lastError",
"end",
"end"
] | Sends requests to QuickBase and processes the reponses. | [
"Sends",
"requests",
"to",
"QuickBase",
"and",
"processes",
"the",
"reponses",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L203-L276 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.prependAPI? | def prependAPI?( request )
ret = true
ret = false if request.to_s.include?("API_") or request.to_s.include?("QBIS_")
ret
end | ruby | def prependAPI?( request )
ret = true
ret = false if request.to_s.include?("API_") or request.to_s.include?("QBIS_")
ret
end | [
"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 | [
"Returns",
"whether",
"to",
"prepend",
"API_",
"to",
"request",
"string"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L319-L323 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.toggleTraceInfo | def toggleTraceInfo( showTrace )
if showTrace
# this will print a very large amount of stuff
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, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname }
end
end
self
end | ruby | def toggleTraceInfo( showTrace )
if showTrace
# this will print a very large amount of stuff
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, line, id, binding, classname| printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname }
end
end
self
end | [
"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",
",",
"line",
",",
"id",
",",
"binding",
",",
"classname",
"|",
"printf",
"\"%8s %s:%-2d %10s %8s\\n\"",
",",
"event",
",",
"file",
",",
"line",
",",
"id",
",",
"classname",
"}",
"end",
"end",
"self",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L327-L343 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getErrorInfoFromResponse | 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 code: #{@errcode} text: #{@errtext}: detail: #{@errdetail}"
end
end
@lastError
end | ruby | 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 code: #{@errcode} text: #{@errtext}: detail: #{@errdetail}"
end
end
@lastError
end | [
"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 code: #{@errcode} text: #{@errtext}: detail: #{@errdetail}\"",
"end",
"end",
"@lastError",
"end"
] | Extracts error info from XML responses returned by QuickBase. | [
"Extracts",
"error",
"info",
"from",
"XML",
"responses",
"returned",
"by",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L386-L399 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.parseResponseXML | 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.new( xml )
end
end | ruby | 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.new( xml )
end
end | [
"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",
".",
"new",
"(",
"xml",
")",
"end",
"end"
] | Called by processResponse to put the XML from QuickBase
into a DOM tree using the REXML module that comes with Ruby. | [
"Called",
"by",
"processResponse",
"to",
"put",
"the",
"XML",
"from",
"QuickBase",
"into",
"a",
"DOM",
"tree",
"using",
"the",
"REXML",
"module",
"that",
"comes",
"with",
"Ruby",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L403-L411 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getResponseValue | 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 | ruby | 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 | [
"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. | [
"Gets",
"the",
"value",
"for",
"a",
"specific",
"field",
"at",
"the",
"top",
"level",
"of",
"the",
"XML",
"returned",
"from",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L415-L422 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getResponsePathValues | 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 | ruby | 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 | [
"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. | [
"Gets",
"an",
"array",
"of",
"values",
"at",
"an",
"Xpath",
"in",
"the",
"XML",
"from",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L435-L440 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getResponsePathValueByDBName | 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 | ruby | 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 | [
"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 | [
"Gets",
"a",
"dbid",
"at",
"an",
"Xpath",
"in",
"the",
"XML",
"from",
"specified",
"dbName",
"of",
"Quickbase"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L443-L454 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getAttributeString | 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 | ruby | 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 | [
"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. | [
"Returns",
"a",
"string",
"representation",
"of",
"the",
"attributes",
"of",
"an",
"XML",
"element",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L472-L482 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupFieldName | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"name",
"of",
"field",
"given",
"an",
"fid",
"XML",
"element",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L498-L510 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupFieldType | 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 | ruby | 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 | [
"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. | [
"Returns",
"a",
"QuickBase",
"field",
"type",
"given",
"an",
"XML",
"fid",
"element",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L513-L523 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupFieldPropertyByName | 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
theproperty
end | ruby | 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
theproperty
end | [
"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",
"theproperty",
"end"
] | Returns the value of a field property, or nil. | [
"Returns",
"the",
"value",
"of",
"a",
"field",
"property",
"or",
"nil",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L531-L540 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.isRecordidField? | def isRecordidField?( fid )
fields = lookupFieldsByType( "recordid" )
(fields and fields.last and fields.last.attributes[ "id" ] == fid)
end | ruby | def isRecordidField?( fid )
fields = lookupFieldsByType( "recordid" )
(fields and fields.last and fields.last.attributes[ "id" ] == fid)
end | [
"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. | [
"Returns",
"whether",
"a",
"field",
"ID",
"is",
"the",
"ID",
"for",
"the",
"key",
"field",
"in",
"a",
"QuickBase",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L555-L558 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatFieldValue | 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, options )
when "currency"
value = formatCurrency( value, options )
when "percent"
value = formatPercent( value, options )
end
end
value
end | ruby | 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, options )
when "currency"
value = formatCurrency( value, options )
when "percent"
value = formatPercent( value, options )
end
end
value
end | [
"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",
",",
"options",
")",
"when",
"\"currency\"",
"value",
"=",
"formatCurrency",
"(",
"value",
",",
"options",
")",
"when",
"\"percent\"",
"value",
"=",
"formatPercent",
"(",
"value",
",",
"options",
")",
"end",
"end",
"value",
"end"
] | Returns a human-readable string representation of a QuickBase field value.
Also required for subsequent requests to QuickBase. | [
"Returns",
"a",
"human",
"-",
"readable",
"string",
"representation",
"of",
"a",
"QuickBase",
"field",
"value",
".",
"Also",
"required",
"for",
"subsequent",
"requests",
"to",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L567-L585 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.findElementByAttributeValue | 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?( REXML::Element ) and e.attributes[ attribute_name ] == attribute_value
element = e
end
}
end
end
element
end | ruby | 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?( REXML::Element ) and e.attributes[ attribute_name ] == attribute_value
element = e
end
}
end
end
element
end | [
"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?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"e",
".",
"attributes",
"[",
"attribute_name",
"]",
"==",
"attribute_value",
"element",
"=",
"e",
"end",
"}",
"end",
"end",
"element",
"end"
] | Returns the first XML sub-element with the specified attribute value. | [
"Returns",
"the",
"first",
"XML",
"sub",
"-",
"element",
"with",
"the",
"specified",
"attribute",
"value",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L716-L730 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.findElementsByAttributeName | def findElementsByAttributeName( elements, attribute_name )
elementArray = []
if elements
elements.each_element_with_attribute( attribute_name ) { |e| elementArray << e }
end
elementArray
end | ruby | def findElementsByAttributeName( elements, attribute_name )
elementArray = []
if elements
elements.each_element_with_attribute( attribute_name ) { |e| elementArray << e }
end
elementArray
end | [
"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. | [
"Returns",
"an",
"array",
"of",
"XML",
"sub",
"-",
"elements",
"with",
"the",
"specified",
"attribute",
"name",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L750-L756 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupFieldData | 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
@field_data
end | ruby | 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
@field_data
end | [
"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",
"@field_data",
"end"
] | Returns the XML element for a field returned by a getRecordInfo call. | [
"Returns",
"the",
"XML",
"element",
"for",
"a",
"field",
"returned",
"by",
"a",
"getRecordInfo",
"call",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L765-L778 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getFieldDataValue | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"value",
"for",
"a",
"field",
"returned",
"by",
"a",
"getRecordInfo",
"call",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L781-L791 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getFieldDataPrintableValue | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"printable",
"value",
"for",
"a",
"field",
"returned",
"by",
"a",
"getRecordInfo",
"call",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L794-L804 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getFieldIDs | 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 | ruby | 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 | [
"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. | [
"Get",
"an",
"array",
"of",
"field",
"IDs",
"for",
"a",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L823-L834 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getFieldNames | 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 lowerOrUppercase == "lowercase"
fieldNames << f.elements[ "label" ].text.downcase
elsif lowerOrUppercase == "uppercase"
fieldNames << f.elements[ "label" ].text.upcase
else
fieldNames << f.elements[ "label" ].text.dup
end
end
}
end
fieldNames
end | ruby | 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 lowerOrUppercase == "lowercase"
fieldNames << f.elements[ "label" ].text.downcase
elsif lowerOrUppercase == "uppercase"
fieldNames << f.elements[ "label" ].text.upcase
else
fieldNames << f.elements[ "label" ].text.dup
end
end
}
end
fieldNames
end | [
"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",
"lowerOrUppercase",
"==",
"\"lowercase\"",
"fieldNames",
"<<",
"f",
".",
"elements",
"[",
"\"label\"",
"]",
".",
"text",
".",
"downcase",
"elsif",
"lowerOrUppercase",
"==",
"\"uppercase\"",
"fieldNames",
"<<",
"f",
".",
"elements",
"[",
"\"label\"",
"]",
".",
"text",
".",
"upcase",
"else",
"fieldNames",
"<<",
"f",
".",
"elements",
"[",
"\"label\"",
"]",
".",
"text",
".",
"dup",
"end",
"end",
"}",
"end",
"fieldNames",
"end"
] | Get an array of field names for a table. | [
"Get",
"an",
"array",
"of",
"field",
"names",
"for",
"a",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L837-L856 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getApplicationVariables | 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 | ruby | 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 | [
"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. | [
"Get",
"a",
"Hash",
"of",
"application",
"variables",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L859-L871 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupChdbid | 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, "name" )
chdbidArray.each{ |chdbid|
if chdbid.has_text?
dbid = chdbid.text
getSchema( dbid )
name = getResponseElement( "table/name" )
if name and name.has_text? and name.text.downcase == unmodifiedTableName.downcase
@chdbid = chdbid
@dbid = dbid
return @dbid
end
end
}
end
nil
end | ruby | 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, "name" )
chdbidArray.each{ |chdbid|
if chdbid.has_text?
dbid = chdbid.text
getSchema( dbid )
name = getResponseElement( "table/name" )
if name and name.has_text? and name.text.downcase == unmodifiedTableName.downcase
@chdbid = chdbid
@dbid = dbid
return @dbid
end
end
}
end
nil
end | [
"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",
",",
"\"name\"",
")",
"chdbidArray",
".",
"each",
"{",
"|",
"chdbid",
"|",
"if",
"chdbid",
".",
"has_text?",
"dbid",
"=",
"chdbid",
".",
"text",
"getSchema",
"(",
"dbid",
")",
"name",
"=",
"getResponseElement",
"(",
"\"table/name\"",
")",
"if",
"name",
"and",
"name",
".",
"has_text?",
"and",
"name",
".",
"text",
".",
"downcase",
"==",
"unmodifiedTableName",
".",
"downcase",
"@chdbid",
"=",
"chdbid",
"@dbid",
"=",
"dbid",
"return",
"@dbid",
"end",
"end",
"}",
"end",
"nil",
"end"
] | Makes the table with the specified name the 'active' table, and returns the id from the table. | [
"Makes",
"the",
"table",
"with",
"the",
"specified",
"name",
"the",
"active",
"table",
"and",
"returns",
"the",
"id",
"from",
"the",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L914-L938 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getTableName | def getTableName(dbid)
tableName = nil
dbid ||= @dbid
if getSchema(dbid)
tableName = getResponseElement( "table/name" ).text
end
tableName
end | ruby | def getTableName(dbid)
tableName = nil
dbid ||= @dbid
if getSchema(dbid)
tableName = getResponseElement( "table/name" ).text
end
tableName
end | [
"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. | [
"Get",
"the",
"name",
"of",
"a",
"table",
"given",
"its",
"id",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L941-L948 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getTableNames | 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" )
if name and name.has_text?
if lowercaseOrUpperCase == "lowercase"
tableNames << name.text.downcase
elsif lowercaseOrUpperCase == "uppercase"
tableNames << name.text.upcase
else
tableNames << name.text.dup
end
end
end
}
end
tableNames
end | ruby | 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" )
if name and name.has_text?
if lowercaseOrUpperCase == "lowercase"
tableNames << name.text.downcase
elsif lowercaseOrUpperCase == "uppercase"
tableNames << name.text.upcase
else
tableNames << name.text.dup
end
end
end
}
end
tableNames
end | [
"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\"",
")",
"if",
"name",
"and",
"name",
".",
"has_text?",
"if",
"lowercaseOrUpperCase",
"==",
"\"lowercase\"",
"tableNames",
"<<",
"name",
".",
"text",
".",
"downcase",
"elsif",
"lowercaseOrUpperCase",
"==",
"\"uppercase\"",
"tableNames",
"<<",
"name",
".",
"text",
".",
"upcase",
"else",
"tableNames",
"<<",
"name",
".",
"text",
".",
"dup",
"end",
"end",
"end",
"}",
"end",
"tableNames",
"end"
] | Get a list of the names of the child tables of an application. | [
"Get",
"a",
"list",
"of",
"the",
"names",
"of",
"the",
"child",
"tables",
"of",
"an",
"application",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L951-L975 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getTableIDs | 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 | ruby | 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 | [
"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. | [
"Get",
"a",
"list",
"of",
"the",
"dbids",
"of",
"the",
"child",
"tables",
"of",
"an",
"application",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L978-L991 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getNumTables | def getNumTables(dbid)
numTables = 0
dbid ||= @dbid
if getSchema(dbid)
if @chdbids
chdbidArray = findElementsByAttributeName( @chdbids, "name" )
numTables = chdbidArray.length
end
end
numTables
end | ruby | def getNumTables(dbid)
numTables = 0
dbid ||= @dbid
if getSchema(dbid)
if @chdbids
chdbidArray = findElementsByAttributeName( @chdbids, "name" )
numTables = chdbidArray.length
end
end
numTables
end | [
"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 | [
"Get",
"the",
"number",
"of",
"child",
"tables",
"of",
"an",
"application"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L994-L1004 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getRealmForDbid | 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 StandardError => error
@realm = nil
end
else
raise "Please get the HTTPClient gem: gem install httpclient"
end
@realm
end | ruby | 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 StandardError => error
@realm = nil
end
else
raise "Please get the HTTPClient gem: gem install httpclient"
end
@realm
end | [
"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",
"StandardError",
"=>",
"error",
"@realm",
"=",
"nil",
"end",
"else",
"raise",
"\"Please get the HTTPClient gem: gem install httpclient\"",
"end",
"@realm",
"end"
] | Given a DBID, get the QuickBase realm it is in. | [
"Given",
"a",
"DBID",
"get",
"the",
"QuickBase",
"realm",
"it",
"is",
"in",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1024-L1041 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.isValidFieldType? | 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 | ruby | 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 | [
"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. | [
"Returns",
"whether",
"a",
"given",
"string",
"represents",
"a",
"valid",
"QuickBase",
"field",
"type",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1054-L1058 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.isValidFieldProperty? | 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 display_dow
display_graphic display_month display_relative display_time display_today display_user display_zone
does_average does_total doesdatacopy exact fieldhelp find_enabled foreignkey format formula
has_extension hours24 label max_versions maxlength nowrap num_lines required sort_as_given
source_fid source_fieldname target_dbid target_dbname target_fid target_fieldname unique units
use_new_window width }
end
ret = @validFieldProperties.include?( property )
end | ruby | 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 display_dow
display_graphic display_month display_relative display_time display_today display_user display_zone
does_average does_total doesdatacopy exact fieldhelp find_enabled foreignkey format formula
has_extension hours24 label max_versions maxlength nowrap num_lines required sort_as_given
source_fid source_fieldname target_dbid target_dbname target_fid target_fieldname unique units
use_new_window width }
end
ret = @validFieldProperties.include?( property )
end | [
"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",
"display_dow",
"display_graphic",
"display_month",
"display_relative",
"display_time",
"display_today",
"display_user",
"display_zone",
"does_average",
"does_total",
"doesdatacopy",
"exact",
"fieldhelp",
"find_enabled",
"foreignkey",
"format",
"formula",
"has_extension",
"hours24",
"label",
"max_versions",
"maxlength",
"nowrap",
"num_lines",
"required",
"sort_as_given",
"source_fid",
"source_fieldname",
"target_dbid",
"target_dbname",
"target_fid",
"target_fieldname",
"unique",
"units",
"use_new_window",
"width",
"}",
"end",
"ret",
"=",
"@validFieldProperties",
".",
"include?",
"(",
"property",
")",
"end"
] | Returns whether a given string represents a valid QuickBase field property. | [
"Returns",
"whether",
"a",
"given",
"string",
"represents",
"a",
"valid",
"QuickBase",
"field",
"property",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1067-L1079 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.verifyFieldList | 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 not a valid field ID"
end
}
@fids = fids
else
raise "verifyFieldList: fids must be an array of one or more field IDs"
end
elsif fnames
if fnames.is_a?( Array ) and fnames.length > 0
fnames.each { |name|
fid = lookupFieldIDByName( name )
if fid
@fids ||= []
@fids << fid
else
raise "verifyFieldList: '#{name}' is not a valid field name"
end
}
@fnames = fnames
else
raise "verifyFieldList: fnames must be an array of one or more field names"
end
else
raise "verifyFieldList: must specify fids or fnames"
end
@fids
end | ruby | 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 not a valid field ID"
end
}
@fids = fids
else
raise "verifyFieldList: fids must be an array of one or more field IDs"
end
elsif fnames
if fnames.is_a?( Array ) and fnames.length > 0
fnames.each { |name|
fid = lookupFieldIDByName( name )
if fid
@fids ||= []
@fids << fid
else
raise "verifyFieldList: '#{name}' is not a valid field name"
end
}
@fnames = fnames
else
raise "verifyFieldList: fnames must be an array of one or more field names"
end
else
raise "verifyFieldList: must specify fids or fnames"
end
@fids
end | [
"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 not a valid field ID\"",
"end",
"}",
"@fids",
"=",
"fids",
"else",
"raise",
"\"verifyFieldList: fids must be an array of one or more field IDs\"",
"end",
"elsif",
"fnames",
"if",
"fnames",
".",
"is_a?",
"(",
"Array",
")",
"and",
"fnames",
".",
"length",
">",
"0",
"fnames",
".",
"each",
"{",
"|",
"name",
"|",
"fid",
"=",
"lookupFieldIDByName",
"(",
"name",
")",
"if",
"fid",
"@fids",
"||=",
"[",
"]",
"@fids",
"<<",
"fid",
"else",
"raise",
"\"verifyFieldList: '#{name}' is not a valid field name\"",
"end",
"}",
"@fnames",
"=",
"fnames",
"else",
"raise",
"\"verifyFieldList: fnames must be an array of one or more field names\"",
"end",
"else",
"raise",
"\"verifyFieldList: must specify fids or fnames\"",
"end",
"@fids",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1200-L1239 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getQueryRequestXML | 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 )
else
@query = "{'0'.CT.''}"
xmlRequestData = toXML( :query, @query )
end
xmlRequestData
end | ruby | 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 )
else
@query = "{'0'.CT.''}"
xmlRequestData = toXML( :query, @query )
end
xmlRequestData
end | [
"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",
")",
"else",
"@query",
"=",
"\"{'0'.CT.''}\"",
"xmlRequestData",
"=",
"toXML",
"(",
":query",
",",
"@query",
")",
"end",
"xmlRequestData",
"end"
] | Builds the request XML for retrieving the results of a query. | [
"Builds",
"the",
"request",
"XML",
"for",
"retrieving",
"the",
"results",
"of",
"a",
"query",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1242-L1258 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getColumnListForQuery | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"clist",
"associated",
"with",
"a",
"query",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1261-L1272 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getSortListForQuery | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"slist",
"associated",
"with",
"a",
"query",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1277-L1288 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getCriteriaForQuery | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"criteria",
"associated",
"with",
"a",
"query",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1293-L1304 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.verifyQueryOperator | def verifyQueryOperator( operator, fieldType )
queryOperator = ""
if @queryOperators.nil?
@queryOperators = {}
@queryOperatorFieldType = {}
@queryOperators[ "CT" ] = [ "contains", "[]" ]
@queryOperators[ "XCT" ] = [ "does not contain", "![]" ]
@queryOperators[ "EX" ] = [ "is", "==", "eq" ]
@queryOperators[ "TV" ] = [ "true value" ]
@queryOperators[ "XEX" ] = [ "is not", "!=", "ne" ]
@queryOperators[ "SW" ] = [ "starts with" ]
@queryOperators[ "XSW" ] = [ "does not start with" ]
@queryOperators[ "BF" ] = [ "is before", "<" ]
@queryOperators[ "OBF" ] = [ "is on or before", "<=" ]
@queryOperators[ "AF" ] = [ "is after", ">" ]
@queryOperators[ "OAF" ] = [ "is on or after", ">=" ]
@queryOperatorFieldType[ "BF" ] = [ "date" ]
@queryOperatorFieldType[ "OBF" ] = [ "date" ]
@queryOperatorFieldType[ "ABF" ] = [ "date" ]
@queryOperatorFieldType[ "OAF" ] = [ "date" ]
@queryOperators[ "LT" ] = [ "is less than", "<" ]
@queryOperators[ "LTE" ] = [ "is less than or equal to", "<=" ]
@queryOperators[ "GT" ] = [ "is greater than", ">" ]
@queryOperators[ "GTE" ] = [ "is greater than or equal to", ">=" ]
end
upcaseOperator = operator.upcase
@queryOperators.each { |queryop,aliases|
if queryop == upcaseOperator
if @queryOperatorFieldType[ queryop ] and @queryOperatorFieldType[ queryop ].include?( fieldType )
queryOperator = upcaseOperator
break
else
queryOperator = upcaseOperator
break
end
else
aliases.each { |a|
if a == upcaseOperator
if @queryOperatorFieldType[ queryop ] and @queryOperatorFieldType[ queryop ].include?( fieldType )
queryOperator = queryop
break
else
queryOperator = queryop
break
end
end
}
end
}
queryOperator
end | ruby | def verifyQueryOperator( operator, fieldType )
queryOperator = ""
if @queryOperators.nil?
@queryOperators = {}
@queryOperatorFieldType = {}
@queryOperators[ "CT" ] = [ "contains", "[]" ]
@queryOperators[ "XCT" ] = [ "does not contain", "![]" ]
@queryOperators[ "EX" ] = [ "is", "==", "eq" ]
@queryOperators[ "TV" ] = [ "true value" ]
@queryOperators[ "XEX" ] = [ "is not", "!=", "ne" ]
@queryOperators[ "SW" ] = [ "starts with" ]
@queryOperators[ "XSW" ] = [ "does not start with" ]
@queryOperators[ "BF" ] = [ "is before", "<" ]
@queryOperators[ "OBF" ] = [ "is on or before", "<=" ]
@queryOperators[ "AF" ] = [ "is after", ">" ]
@queryOperators[ "OAF" ] = [ "is on or after", ">=" ]
@queryOperatorFieldType[ "BF" ] = [ "date" ]
@queryOperatorFieldType[ "OBF" ] = [ "date" ]
@queryOperatorFieldType[ "ABF" ] = [ "date" ]
@queryOperatorFieldType[ "OAF" ] = [ "date" ]
@queryOperators[ "LT" ] = [ "is less than", "<" ]
@queryOperators[ "LTE" ] = [ "is less than or equal to", "<=" ]
@queryOperators[ "GT" ] = [ "is greater than", ">" ]
@queryOperators[ "GTE" ] = [ "is greater than or equal to", ">=" ]
end
upcaseOperator = operator.upcase
@queryOperators.each { |queryop,aliases|
if queryop == upcaseOperator
if @queryOperatorFieldType[ queryop ] and @queryOperatorFieldType[ queryop ].include?( fieldType )
queryOperator = upcaseOperator
break
else
queryOperator = upcaseOperator
break
end
else
aliases.each { |a|
if a == upcaseOperator
if @queryOperatorFieldType[ queryop ] and @queryOperatorFieldType[ queryop ].include?( fieldType )
queryOperator = queryop
break
else
queryOperator = queryop
break
end
end
}
end
}
queryOperator
end | [
"def",
"verifyQueryOperator",
"(",
"operator",
",",
"fieldType",
")",
"queryOperator",
"=",
"\"\"",
"if",
"@queryOperators",
".",
"nil?",
"@queryOperators",
"=",
"{",
"}",
"@queryOperatorFieldType",
"=",
"{",
"}",
"@queryOperators",
"[",
"\"CT\"",
"]",
"=",
"[",
"\"contains\"",
",",
"\"[]\"",
"]",
"@queryOperators",
"[",
"\"XCT\"",
"]",
"=",
"[",
"\"does not contain\"",
",",
"\"![]\"",
"]",
"@queryOperators",
"[",
"\"EX\"",
"]",
"=",
"[",
"\"is\"",
",",
"\"==\"",
",",
"\"eq\"",
"]",
"@queryOperators",
"[",
"\"TV\"",
"]",
"=",
"[",
"\"true value\"",
"]",
"@queryOperators",
"[",
"\"XEX\"",
"]",
"=",
"[",
"\"is not\"",
",",
"\"!=\"",
",",
"\"ne\"",
"]",
"@queryOperators",
"[",
"\"SW\"",
"]",
"=",
"[",
"\"starts with\"",
"]",
"@queryOperators",
"[",
"\"XSW\"",
"]",
"=",
"[",
"\"does not start with\"",
"]",
"@queryOperators",
"[",
"\"BF\"",
"]",
"=",
"[",
"\"is before\"",
",",
"\"<\"",
"]",
"@queryOperators",
"[",
"\"OBF\"",
"]",
"=",
"[",
"\"is on or before\"",
",",
"\"<=\"",
"]",
"@queryOperators",
"[",
"\"AF\"",
"]",
"=",
"[",
"\"is after\"",
",",
"\">\"",
"]",
"@queryOperators",
"[",
"\"OAF\"",
"]",
"=",
"[",
"\"is on or after\"",
",",
"\">=\"",
"]",
"@queryOperatorFieldType",
"[",
"\"BF\"",
"]",
"=",
"[",
"\"date\"",
"]",
"@queryOperatorFieldType",
"[",
"\"OBF\"",
"]",
"=",
"[",
"\"date\"",
"]",
"@queryOperatorFieldType",
"[",
"\"ABF\"",
"]",
"=",
"[",
"\"date\"",
"]",
"@queryOperatorFieldType",
"[",
"\"OAF\"",
"]",
"=",
"[",
"\"date\"",
"]",
"@queryOperators",
"[",
"\"LT\"",
"]",
"=",
"[",
"\"is less than\"",
",",
"\"<\"",
"]",
"@queryOperators",
"[",
"\"LTE\"",
"]",
"=",
"[",
"\"is less than or equal to\"",
",",
"\"<=\"",
"]",
"@queryOperators",
"[",
"\"GT\"",
"]",
"=",
"[",
"\"is greater than\"",
",",
"\">\"",
"]",
"@queryOperators",
"[",
"\"GTE\"",
"]",
"=",
"[",
"\"is greater than or equal to\"",
",",
"\">=\"",
"]",
"end",
"upcaseOperator",
"=",
"operator",
".",
"upcase",
"@queryOperators",
".",
"each",
"{",
"|",
"queryop",
",",
"aliases",
"|",
"if",
"queryop",
"==",
"upcaseOperator",
"if",
"@queryOperatorFieldType",
"[",
"queryop",
"]",
"and",
"@queryOperatorFieldType",
"[",
"queryop",
"]",
".",
"include?",
"(",
"fieldType",
")",
"queryOperator",
"=",
"upcaseOperator",
"break",
"else",
"queryOperator",
"=",
"upcaseOperator",
"break",
"end",
"else",
"aliases",
".",
"each",
"{",
"|",
"a",
"|",
"if",
"a",
"==",
"upcaseOperator",
"if",
"@queryOperatorFieldType",
"[",
"queryop",
"]",
"and",
"@queryOperatorFieldType",
"[",
"queryop",
"]",
".",
"include?",
"(",
"fieldType",
")",
"queryOperator",
"=",
"queryop",
"break",
"else",
"queryOperator",
"=",
"queryop",
"break",
"end",
"end",
"}",
"end",
"}",
"queryOperator",
"end"
] | Returns a valid query operator. | [
"Returns",
"a",
"valid",
"query",
"operator",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1309-L1367 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupBaseFieldTypeByName | def lookupBaseFieldTypeByName( fieldName )
type = ""
fid = lookupFieldIDByName( fieldName )
field = lookupField( fid ) if fid
type = field.attributes[ "base_type" ] if field
type
end | ruby | def lookupBaseFieldTypeByName( fieldName )
type = ""
fid = lookupFieldIDByName( fieldName )
field = lookupField( fid ) if fid
type = field.attributes[ "base_type" ] if field
type
end | [
"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. | [
"Get",
"a",
"field",
"s",
"base",
"type",
"using",
"its",
"name",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1370-L1376 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.lookupFieldTypeByName | def lookupFieldTypeByName( fieldName )
type = ""
fid = lookupFieldIDByName( fieldName )
field = lookupField( fid ) if fid
type = field.attributes[ "field_type" ] if field
type
end | ruby | def lookupFieldTypeByName( fieldName )
type = ""
fid = lookupFieldIDByName( fieldName )
field = lookupField( fid ) if fid
type = field.attributes[ "field_type" ] if field
type
end | [
"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. | [
"Get",
"a",
"field",
"s",
"type",
"using",
"its",
"name",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1379-L1385 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatDate | 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 addDay
fmt = t.strftime( fmtString )
elsif milliseconds_s.length > 0
t = Time.at( (milliseconds_s.to_i) / 1000 )
t += (60 * 60 * 24) if addDay
fmt = t.strftime( fmtString )
end
end
fmt
end | ruby | 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 addDay
fmt = t.strftime( fmtString )
elsif milliseconds_s.length > 0
t = Time.at( (milliseconds_s.to_i) / 1000 )
t += (60 * 60 * 24) if addDay
fmt = t.strftime( fmtString )
end
end
fmt
end | [
"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",
"addDay",
"fmt",
"=",
"t",
".",
"strftime",
"(",
"fmtString",
")",
"elsif",
"milliseconds_s",
".",
"length",
">",
"0",
"t",
"=",
"Time",
".",
"at",
"(",
"(",
"milliseconds_s",
".",
"to_i",
")",
"/",
"1000",
")",
"t",
"+=",
"(",
"60",
"*",
"60",
"*",
"24",
")",
"if",
"addDay",
"fmt",
"=",
"t",
".",
"strftime",
"(",
"fmtString",
")",
"end",
"end",
"fmt",
"end"
] | Returns the human-readable string represntation of a date, given the
milliseconds version of the date. Also needed for requests to QuickBase. | [
"Returns",
"the",
"human",
"-",
"readable",
"string",
"represntation",
"of",
"a",
"date",
"given",
"the",
"milliseconds",
"version",
"of",
"the",
"date",
".",
"Also",
"needed",
"for",
"requests",
"to",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1394-L1410 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatDuration | 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 == "minutes"
value = minutes.to_s
end
end
value
end | ruby | 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 == "minutes"
value = minutes.to_s
end
end
value
end | [
"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",
"==",
"\"minutes\"",
"value",
"=",
"minutes",
".",
"to_s",
"end",
"end",
"value",
"end"
] | Converts milliseconds to hours and returns the value as a string. | [
"Converts",
"milliseconds",
"to",
"hours",
"and",
"returns",
"the",
"value",
"as",
"a",
"string",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1413-L1431 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatTimeOfDay | 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 | ruby | 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 | [
"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. | [
"Returns",
"a",
"string",
"format",
"for",
"a",
"time",
"of",
"day",
"value",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1434-L1438 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatCurrency | 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"
value = "#{currencySymbol}#{value}"
elsif currencyFormat == "1"
if value.include?("-")
value.gsub!("-","-#{currencySymbol}")
elsif value.include?("+")
value.gsub!("+","+#{currencySymbol}")
else
value = "#{currencySymbol}#{value}"
end
elsif currencyFormat == "2"
value = "#{value}#{currencySymbol}"
end
else
value = "#{currencySymbol}#{value}"
end
end
value
end | ruby | 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"
value = "#{currencySymbol}#{value}"
elsif currencyFormat == "1"
if value.include?("-")
value.gsub!("-","-#{currencySymbol}")
elsif value.include?("+")
value.gsub!("+","+#{currencySymbol}")
else
value = "#{currencySymbol}#{value}"
end
elsif currencyFormat == "2"
value = "#{value}#{currencySymbol}"
end
else
value = "#{currencySymbol}#{value}"
end
end
value
end | [
"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\"",
"value",
"=",
"\"#{currencySymbol}#{value}\"",
"elsif",
"currencyFormat",
"==",
"\"1\"",
"if",
"value",
".",
"include?",
"(",
"\"-\"",
")",
"value",
".",
"gsub!",
"(",
"\"-\"",
",",
"\"-#{currencySymbol}\"",
")",
"elsif",
"value",
".",
"include?",
"(",
"\"+\"",
")",
"value",
".",
"gsub!",
"(",
"\"+\"",
",",
"\"+#{currencySymbol}\"",
")",
"else",
"value",
"=",
"\"#{currencySymbol}#{value}\"",
"end",
"elsif",
"currencyFormat",
"==",
"\"2\"",
"value",
"=",
"\"#{value}#{currencySymbol}\"",
"end",
"else",
"value",
"=",
"\"#{currencySymbol}#{value}\"",
"end",
"end",
"value",
"end"
] | Returns a string formatted for a currency value. | [
"Returns",
"a",
"string",
"formatted",
"for",
"a",
"currency",
"value",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1441-L1474 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.formatPercent | 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 | ruby | 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 | [
"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 | [
"Returns",
"a",
"string",
"formatted",
"for",
"a",
"percent",
"value",
"given",
"the",
"data",
"from",
"QuickBase"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1477-L1493 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.dateToMS | def dateToMS( dateString )
milliseconds = 0
if dateString and dateString.match( /[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9][0-9][0-9]/)
d = Date.new( dateString[7,4], dateString[4,2], dateString[0,2] )
milliseconds = d.jd
end
milliseconds
end | ruby | def dateToMS( dateString )
milliseconds = 0
if dateString and dateString.match( /[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9][0-9][0-9]/)
d = Date.new( dateString[7,4], dateString[4,2], dateString[0,2] )
milliseconds = d.jd
end
milliseconds
end | [
"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. | [
"Returns",
"the",
"milliseconds",
"representation",
"of",
"a",
"date",
"specified",
"in",
"mm",
"-",
"dd",
"-",
"yyyy",
"format",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1496-L1503 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.escapeXML | 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 | ruby | 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 | [
"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. | [
"Returns",
"the",
"URL",
"-",
"encoded",
"version",
"of",
"a",
"non",
"-",
"printing",
"character",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1512-L1519 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.encodingStrings | 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.each{ |s| s.each{|k,v| yield k,v } }
end
else
@encodingStrings
end
end | ruby | 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.each{ |s| s.each{|k,v| yield k,v } }
end
else
@encodingStrings
end
end | [
"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",
".",
"each",
"{",
"|",
"s",
"|",
"s",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"yield",
"k",
",",
"v",
"}",
"}",
"end",
"else",
"@encodingStrings",
"end",
"end"
] | Returns the list of string substitutions to make to encode or decode field values used in XML. | [
"Returns",
"the",
"list",
"of",
"string",
"substitutions",
"to",
"make",
"to",
"encode",
"or",
"decode",
"field",
"values",
"used",
"in",
"XML",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1522-L1533 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.encodeXML | def encodeXML( text, doNPChars = false )
encodingStrings { |key,value| text.gsub!( key, value ) if text }
text.gsub!( /([^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()# ])/ ) { |c| escapeXML( $1 ) } if text and doNPChars
text
end | ruby | def encodeXML( text, doNPChars = false )
encodingStrings { |key,value| text.gsub!( key, value ) if text }
text.gsub!( /([^;\/?:@&=+\$,A-Za-z0-9\-_.!~*'()# ])/ ) { |c| escapeXML( $1 ) } if text and doNPChars
text
end | [
"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. | [
"Modify",
"the",
"given",
"string",
"for",
"use",
"as",
"a",
"XML",
"field",
"value",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1536-L1540 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.decodeXML | def decodeXML( text )
encodingStrings( true ) { |key,value| text.gsub!( value, key ) if text }
text.gsub!( /&#([0-9]{2,3});/ ) { |c| $1.chr } if text
text
end | ruby | def decodeXML( text )
encodingStrings( true ) { |key,value| text.gsub!( value, key ) if text }
text.gsub!( /&#([0-9]{2,3});/ ) { |c| $1.chr } if text
text
end | [
"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. | [
"Modify",
"the",
"given",
"XML",
"field",
"value",
"for",
"use",
"as",
"a",
"string",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1543-L1547 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.fire | def fire( event )
if @eventSubscribers and @eventSubscribers.include?( event )
handlers = @eventSubscribers[ event ]
if handlers
handlers.each{ |handler| handler.handle( event ) }
end
end
end | ruby | def fire( event )
if @eventSubscribers and @eventSubscribers.include?( event )
handlers = @eventSubscribers[ event ]
if handlers
handlers.each{ |handler| handler.handle( event ) }
end
end
end | [
"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 | [
"Called",
"by",
"client",
"methods",
"to",
"notify",
"event",
"subscribers"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1594-L1601 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client._addRecord | def _addRecord( fvlist = nil, disprec = nil, fform = nil, ignoreError = nil, update_id = nil )
addRecord( @dbid, fvlist, disprec, fform, ignoreError, update_id )
end | ruby | def _addRecord( fvlist = nil, disprec = nil, fform = nil, ignoreError = nil, update_id = nil )
addRecord( @dbid, fvlist, disprec, fform, ignoreError, update_id )
end | [
"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. | [
"API_AddRecord",
"using",
"the",
"active",
"table",
"id",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L1710-L1712 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client._doQueryHash | 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["qname"],
doQueryOptions["clist"],
doQueryOptions["slist"],
doQueryOptions["fmt"],
doQueryOptions["options"] )
end | ruby | 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["qname"],
doQueryOptions["clist"],
doQueryOptions["slist"],
doQueryOptions["fmt"],
doQueryOptions["options"] )
end | [
"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",
"[",
"\"qname\"",
"]",
",",
"doQueryOptions",
"[",
"\"clist\"",
"]",
",",
"doQueryOptions",
"[",
"\"slist\"",
"]",
",",
"doQueryOptions",
"[",
"\"fmt\"",
"]",
",",
"doQueryOptions",
"[",
"\"options\"",
"]",
")",
"end"
] | version of doQuery that takes a Hash of parameters | [
"version",
"of",
"doQuery",
"that",
"takes",
"a",
"Hash",
"of",
"parameters"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L2129-L2142 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.downLoadFile | 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 @printRequestsAndResponses
puts
puts "downLoadFile request: -------------------------------------"
p @downLoadFileURL
p @requestHeaders
end
begin
if USING_HTTPCLIENT
@responseCode = 404
@fileContents = @httpConnection.get_content( @downLoadFileURL, nil, @requestHeaders )
@responseCode = 200 if @fileContents
else
@responseCode, @fileContents = @httpConnection.get( @downLoadFileURL, @requestHeaders )
end
rescue Net::HTTPBadResponse => @lastError
rescue Net::HTTPHeaderSyntaxError => @lastError
rescue StandardError => @lastError
end
if @printRequestsAndResponses
puts
puts "downLoadFile response: -------------------------------------"
p @responseCode
p @fileContents
end
return self if @chainAPIcalls
return @responseCode, @fileContents
end | ruby | 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 @printRequestsAndResponses
puts
puts "downLoadFile request: -------------------------------------"
p @downLoadFileURL
p @requestHeaders
end
begin
if USING_HTTPCLIENT
@responseCode = 404
@fileContents = @httpConnection.get_content( @downLoadFileURL, nil, @requestHeaders )
@responseCode = 200 if @fileContents
else
@responseCode, @fileContents = @httpConnection.get( @downLoadFileURL, @requestHeaders )
end
rescue Net::HTTPBadResponse => @lastError
rescue Net::HTTPHeaderSyntaxError => @lastError
rescue StandardError => @lastError
end
if @printRequestsAndResponses
puts
puts "downLoadFile response: -------------------------------------"
p @responseCode
p @fileContents
end
return self if @chainAPIcalls
return @responseCode, @fileContents
end | [
"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",
"@printRequestsAndResponses",
"puts",
"puts",
"\"downLoadFile request: -------------------------------------\"",
"p",
"@downLoadFileURL",
"p",
"@requestHeaders",
"end",
"begin",
"if",
"USING_HTTPCLIENT",
"@responseCode",
"=",
"404",
"@fileContents",
"=",
"@httpConnection",
".",
"get_content",
"(",
"@downLoadFileURL",
",",
"nil",
",",
"@requestHeaders",
")",
"@responseCode",
"=",
"200",
"if",
"@fileContents",
"else",
"@responseCode",
",",
"@fileContents",
"=",
"@httpConnection",
".",
"get",
"(",
"@downLoadFileURL",
",",
"@requestHeaders",
")",
"end",
"rescue",
"Net",
"::",
"HTTPBadResponse",
"=>",
"@lastError",
"rescue",
"Net",
"::",
"HTTPHeaderSyntaxError",
"=>",
"@lastError",
"rescue",
"StandardError",
"=>",
"@lastError",
"end",
"if",
"@printRequestsAndResponses",
"puts",
"puts",
"\"downLoadFile response: -------------------------------------\"",
"p",
"@responseCode",
"p",
"@fileContents",
"end",
"return",
"self",
"if",
"@chainAPIcalls",
"return",
"@responseCode",
",",
"@fileContents",
"end"
] | Download a file's contents from a file attachment field in QuickBase.
You must write the contents to disk before a local file exists. | [
"Download",
"a",
"file",
"s",
"contents",
"from",
"a",
"file",
"attachment",
"field",
"in",
"QuickBase",
".",
"You",
"must",
"write",
"the",
"contents",
"to",
"disk",
"before",
"a",
"local",
"file",
"exists",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L2163-L2206 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.downloadAndSaveFile | 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 record and record[fid] and record[fid].length > 0
Misc.save_file( record[fid], fileContents )
else
Misc.save_file( "#{dbid}_#{rid}_#{fid}", fileContents )
end
end
end
end | ruby | 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 record and record[fid] and record[fid].length > 0
Misc.save_file( record[fid], fileContents )
else
Misc.save_file( "#{dbid}_#{rid}_#{fid}", fileContents )
end
end
end
end | [
"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",
"record",
"and",
"record",
"[",
"fid",
"]",
"and",
"record",
"[",
"fid",
"]",
".",
"length",
">",
"0",
"Misc",
".",
"save_file",
"(",
"record",
"[",
"fid",
"]",
",",
"fileContents",
")",
"else",
"Misc",
".",
"save_file",
"(",
"\"#{dbid}_#{rid}_#{fid}\"",
",",
"fileContents",
")",
"end",
"end",
"end",
"end"
] | Download and save a file from a file attachment field in QuickBase.
Use the filename parameter to override the file name from QuickBase. | [
"Download",
"and",
"save",
"a",
"file",
"from",
"a",
"file",
"attachment",
"field",
"in",
"QuickBase",
".",
"Use",
"the",
"filename",
"parameter",
"to",
"override",
"the",
"file",
"name",
"from",
"QuickBase",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L2218-L2232 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.fieldAddChoices | 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( :fieldAddChoices, xmlRequestData )
@fid = getResponseValue( :fid )
@fname = getResponseValue( :fname )
@numadded = getResponseValue( :numadded )
return self if @chainAPIcalls
return @fid, @name, @numadded
end | ruby | 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( :fieldAddChoices, xmlRequestData )
@fid = getResponseValue( :fid )
@fname = getResponseValue( :fname )
@numadded = getResponseValue( :numadded )
return self if @chainAPIcalls
return @fid, @name, @numadded
end | [
"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",
"(",
":fieldAddChoices",
",",
"xmlRequestData",
")",
"@fid",
"=",
"getResponseValue",
"(",
":fid",
")",
"@fname",
"=",
"getResponseValue",
"(",
":fname",
")",
"@numadded",
"=",
"getResponseValue",
"(",
":numadded",
")",
"return",
"self",
"if",
"@chainAPIcalls",
"return",
"@fid",
",",
"@name",
",",
"@numadded",
"end"
] | API_FieldAddChoices
The choice parameter can be one choice string or an array of choice strings. | [
"API_FieldAddChoices",
"The",
"choice",
"parameter",
"can",
"be",
"one",
"choice",
"string",
"or",
"an",
"array",
"of",
"choice",
"strings",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L2263-L2283 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.iterateDBPages | 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 }
yield @page
end
}
end | ruby | 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 }
yield @page
end
}
end | [
"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",
"}",
"yield",
"@page",
"end",
"}",
"end"
] | Loop through the list of Pages for an application | [
"Loop",
"through",
"the",
"list",
"of",
"Pages",
"for",
"an",
"application"
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3128-L3138 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getAllValuesForFields | 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( fieldNames )
if fieldID
fieldIDs[ fieldNames ] = fieldID
elsif fieldNames.match(/[0-9]+/) # assume fieldNames is a field ID
fieldIDs[ fieldNames ] = fieldNames
end
elsif fieldNames and fieldNames.is_a?( Array )
fieldNames.each{ |name|
if name
values[ name ] = []
fieldID = lookupFieldIDByName( name )
if fieldID
fieldIDs[ fieldID ] = name
elsif name.match(/[0-9]+/) # assume name is a field ID
fieldIDs[ name ] = name
end
end
}
elsif fieldNames.nil?
getFieldNames(dbid).each{|name|
values[ name ] = []
fieldID = lookupFieldIDByName( name )
fieldIDs[ fieldID ] = name
}
end
if clist
clist << "."
clist = fieldIDs.keys.join('.')
elsif qid.nil? and qname.nil?
clist = fieldIDs.keys.join('.')
end
if clist
clist = clist.split('.')
clist.uniq!
clist = clist.join(".")
end
doQuery( dbid, query, qid, qname, clist, slist, fmt, options )
if @records and values.length > 0 and fieldIDs.length > 0
@records.each { |r|
if r.is_a?( REXML::Element) and r.name == "record"
values.each{ |k,v| v << "" }
r.each{ |f|
if f.is_a?( REXML::Element) and f.name == "f"
fid = f.attributes[ "id" ]
name = fieldIDs[ fid ] if fid
if name and values[ name ]
v = values[ name ]
v[-1] = f.text if v and f.has_text?
end
end
}
end
}
end
end
if values and block_given?
values.each{ |field, values| yield field, values }
else
values
end
end | ruby | 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( fieldNames )
if fieldID
fieldIDs[ fieldNames ] = fieldID
elsif fieldNames.match(/[0-9]+/) # assume fieldNames is a field ID
fieldIDs[ fieldNames ] = fieldNames
end
elsif fieldNames and fieldNames.is_a?( Array )
fieldNames.each{ |name|
if name
values[ name ] = []
fieldID = lookupFieldIDByName( name )
if fieldID
fieldIDs[ fieldID ] = name
elsif name.match(/[0-9]+/) # assume name is a field ID
fieldIDs[ name ] = name
end
end
}
elsif fieldNames.nil?
getFieldNames(dbid).each{|name|
values[ name ] = []
fieldID = lookupFieldIDByName( name )
fieldIDs[ fieldID ] = name
}
end
if clist
clist << "."
clist = fieldIDs.keys.join('.')
elsif qid.nil? and qname.nil?
clist = fieldIDs.keys.join('.')
end
if clist
clist = clist.split('.')
clist.uniq!
clist = clist.join(".")
end
doQuery( dbid, query, qid, qname, clist, slist, fmt, options )
if @records and values.length > 0 and fieldIDs.length > 0
@records.each { |r|
if r.is_a?( REXML::Element) and r.name == "record"
values.each{ |k,v| v << "" }
r.each{ |f|
if f.is_a?( REXML::Element) and f.name == "f"
fid = f.attributes[ "id" ]
name = fieldIDs[ fid ] if fid
if name and values[ name ]
v = values[ name ]
v[-1] = f.text if v and f.has_text?
end
end
}
end
}
end
end
if values and block_given?
values.each{ |field, values| yield field, values }
else
values
end
end | [
"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",
"(",
"fieldNames",
")",
"if",
"fieldID",
"fieldIDs",
"[",
"fieldNames",
"]",
"=",
"fieldID",
"elsif",
"fieldNames",
".",
"match",
"(",
"/",
"/",
")",
"fieldIDs",
"[",
"fieldNames",
"]",
"=",
"fieldNames",
"end",
"elsif",
"fieldNames",
"and",
"fieldNames",
".",
"is_a?",
"(",
"Array",
")",
"fieldNames",
".",
"each",
"{",
"|",
"name",
"|",
"if",
"name",
"values",
"[",
"name",
"]",
"=",
"[",
"]",
"fieldID",
"=",
"lookupFieldIDByName",
"(",
"name",
")",
"if",
"fieldID",
"fieldIDs",
"[",
"fieldID",
"]",
"=",
"name",
"elsif",
"name",
".",
"match",
"(",
"/",
"/",
")",
"fieldIDs",
"[",
"name",
"]",
"=",
"name",
"end",
"end",
"}",
"elsif",
"fieldNames",
".",
"nil?",
"getFieldNames",
"(",
"dbid",
")",
".",
"each",
"{",
"|",
"name",
"|",
"values",
"[",
"name",
"]",
"=",
"[",
"]",
"fieldID",
"=",
"lookupFieldIDByName",
"(",
"name",
")",
"fieldIDs",
"[",
"fieldID",
"]",
"=",
"name",
"}",
"end",
"if",
"clist",
"clist",
"<<",
"\".\"",
"clist",
"=",
"fieldIDs",
".",
"keys",
".",
"join",
"(",
"'.'",
")",
"elsif",
"qid",
".",
"nil?",
"and",
"qname",
".",
"nil?",
"clist",
"=",
"fieldIDs",
".",
"keys",
".",
"join",
"(",
"'.'",
")",
"end",
"if",
"clist",
"clist",
"=",
"clist",
".",
"split",
"(",
"'.'",
")",
"clist",
".",
"uniq!",
"clist",
"=",
"clist",
".",
"join",
"(",
"\".\"",
")",
"end",
"doQuery",
"(",
"dbid",
",",
"query",
",",
"qid",
",",
"qname",
",",
"clist",
",",
"slist",
",",
"fmt",
",",
"options",
")",
"if",
"@records",
"and",
"values",
".",
"length",
">",
"0",
"and",
"fieldIDs",
".",
"length",
">",
"0",
"@records",
".",
"each",
"{",
"|",
"r",
"|",
"if",
"r",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"r",
".",
"name",
"==",
"\"record\"",
"values",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"v",
"<<",
"\"\"",
"}",
"r",
".",
"each",
"{",
"|",
"f",
"|",
"if",
"f",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"f",
".",
"name",
"==",
"\"f\"",
"fid",
"=",
"f",
".",
"attributes",
"[",
"\"id\"",
"]",
"name",
"=",
"fieldIDs",
"[",
"fid",
"]",
"if",
"fid",
"if",
"name",
"and",
"values",
"[",
"name",
"]",
"v",
"=",
"values",
"[",
"name",
"]",
"v",
"[",
"-",
"1",
"]",
"=",
"f",
".",
"text",
"if",
"v",
"and",
"f",
".",
"has_text?",
"end",
"end",
"}",
"end",
"}",
"end",
"end",
"if",
"values",
"and",
"block_given?",
"values",
".",
"each",
"{",
"|",
"field",
",",
"values",
"|",
"yield",
"field",
",",
"values",
"}",
"else",
"values",
"end",
"end"
] | Get all the values for one or more fields from a specified table.
e.g. getAllValuesForFields( "dhnju5y7", [ "Name", "Phone" ] )
The results are returned in Hash, e.g. { "Name" => values[ "Name" ], "Phone" => values[ "Phone" ] }
The parameters after 'fieldNames' are passed directly to the doQuery() API_ call.
Invalid 'fieldNames' will be treated as field IDs by default, e.g. getAllValuesForFields( "dhnju5y7", [ "3" ] )
returns a list of Record ID#s even if the 'Record ID#' field name has been changed. | [
"Get",
"all",
"the",
"values",
"for",
"one",
"or",
"more",
"fields",
"from",
"a",
"specified",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3339-L3413 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getAllValuesForFieldsAsArray | 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
fieldNames ||= getFieldNames(@dbid)
if fieldNames and fieldNames[0]
ret = Array.new(valuesForFields[fieldNames[0]].length)
fieldType = {}
fieldNames.each{|field|fieldType[field]=lookupFieldTypeByName(field)}
valuesForFields.each{ |field,values|
values.each_index { |i|
ret[i] ||= {}
ret[i][field]=formatFieldValue(values[i],fieldType[field])
}
}
end
end
ret
end | ruby | 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
fieldNames ||= getFieldNames(@dbid)
if fieldNames and fieldNames[0]
ret = Array.new(valuesForFields[fieldNames[0]].length)
fieldType = {}
fieldNames.each{|field|fieldType[field]=lookupFieldTypeByName(field)}
valuesForFields.each{ |field,values|
values.each_index { |i|
ret[i] ||= {}
ret[i][field]=formatFieldValue(values[i],fieldType[field])
}
}
end
end
ret
end | [
"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",
"fieldNames",
"||=",
"getFieldNames",
"(",
"@dbid",
")",
"if",
"fieldNames",
"and",
"fieldNames",
"[",
"0",
"]",
"ret",
"=",
"Array",
".",
"new",
"(",
"valuesForFields",
"[",
"fieldNames",
"[",
"0",
"]",
"]",
".",
"length",
")",
"fieldType",
"=",
"{",
"}",
"fieldNames",
".",
"each",
"{",
"|",
"field",
"|",
"fieldType",
"[",
"field",
"]",
"=",
"lookupFieldTypeByName",
"(",
"field",
")",
"}",
"valuesForFields",
".",
"each",
"{",
"|",
"field",
",",
"values",
"|",
"values",
".",
"each_index",
"{",
"|",
"i",
"|",
"ret",
"[",
"i",
"]",
"||=",
"{",
"}",
"ret",
"[",
"i",
"]",
"[",
"field",
"]",
"=",
"formatFieldValue",
"(",
"values",
"[",
"i",
"]",
",",
"fieldType",
"[",
"field",
"]",
")",
"}",
"}",
"end",
"end",
"ret",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3419-L3437 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getAllValuesForFieldsAsJSON | 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 | ruby | 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 | [
"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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3443-L3446 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getAllValuesForFieldsAsPrettyJSON | 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) if ret
end | ruby | 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) if ret
end | [
"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",
")",
"if",
"ret",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3452-L3455 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getSummaryRecords | 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 << summaryRecord.dup
}
summaryRecords
end | ruby | 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 << summaryRecord.dup
}
summaryRecords
end | [
"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",
"<<",
"summaryRecord",
".",
"dup",
"}",
"summaryRecords",
"end"
] | Collect summary records into an array. | [
"Collect",
"summary",
"records",
"into",
"an",
"array",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3836-L3842 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.iterateRecordInfos | 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(name)}
iterateRecords(dbid, [recordIDFieldName], query, qid, qname, clist, slist, fmt, options){|r|
getRecordInfo(dbid,r[recordIDFieldName])
fieldValues = {}
fieldIDs.each{|k,v|
fieldValues[k] = getFieldDataPrintableValue(v)
fieldValues[k] ||= getFieldDataValue(v)
}
yield fieldValues
}
end | ruby | 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(name)}
iterateRecords(dbid, [recordIDFieldName], query, qid, qname, clist, slist, fmt, options){|r|
getRecordInfo(dbid,r[recordIDFieldName])
fieldValues = {}
fieldIDs.each{|k,v|
fieldValues[k] = getFieldDataPrintableValue(v)
fieldValues[k] ||= getFieldDataValue(v)
}
yield fieldValues
}
end | [
"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",
"(",
"name",
")",
"}",
"iterateRecords",
"(",
"dbid",
",",
"[",
"recordIDFieldName",
"]",
",",
"query",
",",
"qid",
",",
"qname",
",",
"clist",
",",
"slist",
",",
"fmt",
",",
"options",
")",
"{",
"|",
"r",
"|",
"getRecordInfo",
"(",
"dbid",
",",
"r",
"[",
"recordIDFieldName",
"]",
")",
"fieldValues",
"=",
"{",
"}",
"fieldIDs",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"fieldValues",
"[",
"k",
"]",
"=",
"getFieldDataPrintableValue",
"(",
"v",
")",
"fieldValues",
"[",
"k",
"]",
"||=",
"getFieldDataValue",
"(",
"v",
")",
"}",
"yield",
"fieldValues",
"}",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L3846-L3861 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.applyPercentToRecords | 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" # Record ID#
iterateRecords( dbid, fieldNames, query, qid, qname, clist, slist, fmt, options ){|record|
result = percent( [total[numericField],record[numericField]] )
clearFieldValuePairList
addFieldValuePair( percentField, nil, nil, result.to_s )
editRecord( dbid, record["3"], fvlist )
}
end | ruby | 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" # Record ID#
iterateRecords( dbid, fieldNames, query, qid, qname, clist, slist, fmt, options ){|record|
result = percent( [total[numericField],record[numericField]] )
clearFieldValuePairList
addFieldValuePair( percentField, nil, nil, result.to_s )
editRecord( dbid, record["3"], fvlist )
}
end | [
"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\"",
"iterateRecords",
"(",
"dbid",
",",
"fieldNames",
",",
"query",
",",
"qid",
",",
"qname",
",",
"clist",
",",
"slist",
",",
"fmt",
",",
"options",
")",
"{",
"|",
"record",
"|",
"result",
"=",
"percent",
"(",
"[",
"total",
"[",
"numericField",
"]",
",",
"record",
"[",
"numericField",
"]",
"]",
")",
"clearFieldValuePairList",
"addFieldValuePair",
"(",
"percentField",
",",
"nil",
",",
"nil",
",",
"result",
".",
"to_s",
")",
"editRecord",
"(",
"dbid",
",",
"record",
"[",
"\"3\"",
"]",
",",
"fvlist",
")",
"}",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4105-L4116 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.applyDeviationToRecords | 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" # Record ID#
iterateRecords( dbid, fieldNames, query, qid, qname, clist, slist, fmt, options ){|record|
result = deviation( [avg[numericField],record[numericField]] )
clearFieldValuePairList
addFieldValuePair( deviationField, nil, nil, result.to_s )
editRecord( dbid, record["3"], fvlist )
}
end | ruby | 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" # Record ID#
iterateRecords( dbid, fieldNames, query, qid, qname, clist, slist, fmt, options ){|record|
result = deviation( [avg[numericField],record[numericField]] )
clearFieldValuePairList
addFieldValuePair( deviationField, nil, nil, result.to_s )
editRecord( dbid, record["3"], fvlist )
}
end | [
"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\"",
"iterateRecords",
"(",
"dbid",
",",
"fieldNames",
",",
"query",
",",
"qid",
",",
"qname",
",",
"clist",
",",
"slist",
",",
"fmt",
",",
"options",
")",
"{",
"|",
"record",
"|",
"result",
"=",
"deviation",
"(",
"[",
"avg",
"[",
"numericField",
"]",
",",
"record",
"[",
"numericField",
"]",
"]",
")",
"clearFieldValuePairList",
"addFieldValuePair",
"(",
"deviationField",
",",
"nil",
",",
"nil",
",",
"result",
".",
"to_s",
")",
"editRecord",
"(",
"dbid",
",",
"record",
"[",
"\"3\"",
"]",
",",
"fvlist",
")",
"}",
"end"
] | 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. | [
"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",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4120-L4131 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.percent | 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 = inputValues[1].to_f
((value/total)*100)
end | ruby | 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 = inputValues[1].to_f
((value/total)*100)
end | [
"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",
"=",
"inputValues",
"[",
"1",
"]",
".",
"to_f",
"(",
"(",
"value",
"/",
"total",
")",
"*",
"100",
")",
"end"
] | Given an array of two numbers, return the second number as a percentage of the first number. | [
"Given",
"an",
"array",
"of",
"two",
"numbers",
"return",
"the",
"second",
"number",
"as",
"a",
"percentage",
"of",
"the",
"first",
"number",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4134-L4142 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.deviation | 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
end | ruby | 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
end | [
"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",
"end"
] | Given an array of two numbers, return the difference between the numbers as a positive number. | [
"Given",
"an",
"array",
"of",
"two",
"numbers",
"return",
"the",
"difference",
"between",
"the",
"numbers",
"as",
"a",
"positive",
"number",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4145-L4151 | train |
garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getFieldChoices | 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)
if element.name == "choice" and element.has_text?
choices << element.text
end
end
}
processChildElements(field,true,choicesProc)
choices = nil if choices.length == 0
choices
else
nil
end
end | ruby | 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)
if element.name == "choice" and element.has_text?
choices << element.text
end
end
}
processChildElements(field,true,choicesProc)
choices = nil if choices.length == 0
choices
else
nil
end
end | [
"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",
")",
"if",
"element",
".",
"name",
"==",
"\"choice\"",
"and",
"element",
".",
"has_text?",
"choices",
"<<",
"element",
".",
"text",
"end",
"end",
"}",
"processChildElements",
"(",
"field",
",",
"true",
",",
"choicesProc",
")",
"choices",
"=",
"nil",
"if",
"choices",
".",
"length",
"==",
"0",
"choices",
"else",
"nil",
"end",
"end"
] | Get an array of the existing choices for a multiple-choice text field. | [
"Get",
"an",
"array",
"of",
"the",
"existing",
"choices",
"for",
"a",
"multiple",
"-",
"choice",
"text",
"field",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4154-L4177 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.