id
int32 0
24.9k
| 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
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,100 | 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 |
4,101 | 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 |
4,102 | 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 |
4,103 | 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 |
4,104 | 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 |
4,105 | 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 |
4,106 | 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 |
4,107 | 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 |
4,108 | 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 |
4,109 | 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 |
4,110 | 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 |
4,111 | 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 |
4,112 | 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 |
4,113 | 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 |
4,114 | 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 |
4,115 | 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 |
4,116 | 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 |
4,117 | 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 |
4,118 | 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 |
4,119 | 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 |
4,120 | 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 |
4,121 | 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 |
4,122 | 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 |
4,123 | 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 |
4,124 | 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 |
4,125 | 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 |
4,126 | 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 |
4,127 | 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 |
4,128 | 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 |
4,129 | 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 |
4,130 | 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 |
4,131 | 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 |
4,132 | 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 |
4,133 | 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 |
4,134 | 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 |
4,135 | 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 |
4,136 | 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",
"(",
"/",
"/",
")",
"# assume fieldNames is a field ID \r",
"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",
"(",
"/",
"/",
")",
"# assume name is a field ID\r",
"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 |
4,137 | 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 |
4,138 | 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 |
4,139 | 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 |
4,140 | 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 |
4,141 | 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 |
4,142 | 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\"",
"# Record ID#\r",
"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 |
4,143 | 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\"",
"# Record ID#\r",
"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 |
4,144 | 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 |
4,145 | 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 |
4,146 | 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 |
4,147 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.deleteDuplicateRecords | def deleteDuplicateRecords( fnames, fids = nil, options = nil, dbid = @dbid )
num_deleted = 0
if options and not options.is_a?( Hash )
raise "deleteDuplicateRecords: 'options' parameter must be a Hash"
else
options = {}
options[ "keeplastrecord" ] = true
options[ "ignoreCase" ] = true
end
findDuplicateRecordIDs( fnames, fids, dbid, options[ "ignoreCase" ] ) { |dupeValues, recordIDs|
if options[ "keeplastrecord" ]
recordIDs[0..(recordIDs.length-2)].each{ |rid| num_deleted += 1 if deleteRecord( dbid, rid ) }
elsif options[ "keepfirstrecord" ]
recordIDs[1..(recordIDs.length-1)].each{ |rid| num_deleted += 1 if deleteRecord( dbid, rid ) }
end
}
num_deleted
end | ruby | def deleteDuplicateRecords( fnames, fids = nil, options = nil, dbid = @dbid )
num_deleted = 0
if options and not options.is_a?( Hash )
raise "deleteDuplicateRecords: 'options' parameter must be a Hash"
else
options = {}
options[ "keeplastrecord" ] = true
options[ "ignoreCase" ] = true
end
findDuplicateRecordIDs( fnames, fids, dbid, options[ "ignoreCase" ] ) { |dupeValues, recordIDs|
if options[ "keeplastrecord" ]
recordIDs[0..(recordIDs.length-2)].each{ |rid| num_deleted += 1 if deleteRecord( dbid, rid ) }
elsif options[ "keepfirstrecord" ]
recordIDs[1..(recordIDs.length-1)].each{ |rid| num_deleted += 1 if deleteRecord( dbid, rid ) }
end
}
num_deleted
end | [
"def",
"deleteDuplicateRecords",
"(",
"fnames",
",",
"fids",
"=",
"nil",
",",
"options",
"=",
"nil",
",",
"dbid",
"=",
"@dbid",
")",
"num_deleted",
"=",
"0",
"if",
"options",
"and",
"not",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"raise",
"\"deleteDuplicateRecords: 'options' parameter must be a Hash\"",
"else",
"options",
"=",
"{",
"}",
"options",
"[",
"\"keeplastrecord\"",
"]",
"=",
"true",
"options",
"[",
"\"ignoreCase\"",
"]",
"=",
"true",
"end",
"findDuplicateRecordIDs",
"(",
"fnames",
",",
"fids",
",",
"dbid",
",",
"options",
"[",
"\"ignoreCase\"",
"]",
")",
"{",
"|",
"dupeValues",
",",
"recordIDs",
"|",
"if",
"options",
"[",
"\"keeplastrecord\"",
"]",
"recordIDs",
"[",
"0",
"..",
"(",
"recordIDs",
".",
"length",
"-",
"2",
")",
"]",
".",
"each",
"{",
"|",
"rid",
"|",
"num_deleted",
"+=",
"1",
"if",
"deleteRecord",
"(",
"dbid",
",",
"rid",
")",
"}",
"elsif",
"options",
"[",
"\"keepfirstrecord\"",
"]",
"recordIDs",
"[",
"1",
"..",
"(",
"recordIDs",
".",
"length",
"-",
"1",
")",
"]",
".",
"each",
"{",
"|",
"rid",
"|",
"num_deleted",
"+=",
"1",
"if",
"deleteRecord",
"(",
"dbid",
",",
"rid",
")",
"}",
"end",
"}",
"num_deleted",
"end"
] | Finds records with the same values in a specified
list of fields and deletes all but the first or last duplicate record.
The field list may be a list of field IDs or a list of field names.
The 'options' parameter can be used to keep the oldest record instead of the
newest record, and to control whether to ignore the case of field values when
deciding which records are duplicates. Returns the number of records deleted. | [
"Finds",
"records",
"with",
"the",
"same",
"values",
"in",
"a",
"specified",
"list",
"of",
"fields",
"and",
"deletes",
"all",
"but",
"the",
"first",
"or",
"last",
"duplicate",
"record",
".",
"The",
"field",
"list",
"may",
"be",
"a",
"list",
"of",
"field",
"IDs",
"or",
"a",
"list",
"of",
"field",
"names",
".",
"The",
"options",
"parameter",
"can",
"be",
"used",
"to",
"keep",
"the",
"oldest",
"record",
"instead",
"of",
"the",
"newest",
"record",
"and",
"to",
"control",
"whether",
"to",
"ignore",
"the",
"case",
"of",
"field",
"values",
"when",
"deciding",
"which",
"records",
"are",
"duplicates",
".",
"Returns",
"the",
"number",
"of",
"records",
"deleted",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4257-L4274 |
4,148 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.copyRecord | def copyRecord( rid, numCopies = 1, dbid = @dbid )
clearFieldValuePairList
getRecordInfo( dbid, rid ) { |field|
if field and field.elements[ "value" ] and field.elements[ "value" ].has_text?
if field.elements[ "fid" ].text.to_i > 5 #skip built-in fields
addFieldValuePair( field.elements[ "name" ].text, nil, nil, field.elements[ "value" ].text )
end
end
}
newRecordIDs = []
if @fvlist and @fvlist.length > 0
numCopies.times {
addRecord( dbid, @fvlist )
newRecordIDs << @rid if @rid and @update_id
}
end
if block_given?
newRecordIDs.each{ |newRecordID| yield newRecordID }
else
newRecordIDs
end
end | ruby | def copyRecord( rid, numCopies = 1, dbid = @dbid )
clearFieldValuePairList
getRecordInfo( dbid, rid ) { |field|
if field and field.elements[ "value" ] and field.elements[ "value" ].has_text?
if field.elements[ "fid" ].text.to_i > 5 #skip built-in fields
addFieldValuePair( field.elements[ "name" ].text, nil, nil, field.elements[ "value" ].text )
end
end
}
newRecordIDs = []
if @fvlist and @fvlist.length > 0
numCopies.times {
addRecord( dbid, @fvlist )
newRecordIDs << @rid if @rid and @update_id
}
end
if block_given?
newRecordIDs.each{ |newRecordID| yield newRecordID }
else
newRecordIDs
end
end | [
"def",
"copyRecord",
"(",
"rid",
",",
"numCopies",
"=",
"1",
",",
"dbid",
"=",
"@dbid",
")",
"clearFieldValuePairList",
"getRecordInfo",
"(",
"dbid",
",",
"rid",
")",
"{",
"|",
"field",
"|",
"if",
"field",
"and",
"field",
".",
"elements",
"[",
"\"value\"",
"]",
"and",
"field",
".",
"elements",
"[",
"\"value\"",
"]",
".",
"has_text?",
"if",
"field",
".",
"elements",
"[",
"\"fid\"",
"]",
".",
"text",
".",
"to_i",
">",
"5",
"#skip built-in fields\r",
"addFieldValuePair",
"(",
"field",
".",
"elements",
"[",
"\"name\"",
"]",
".",
"text",
",",
"nil",
",",
"nil",
",",
"field",
".",
"elements",
"[",
"\"value\"",
"]",
".",
"text",
")",
"end",
"end",
"}",
"newRecordIDs",
"=",
"[",
"]",
"if",
"@fvlist",
"and",
"@fvlist",
".",
"length",
">",
"0",
"numCopies",
".",
"times",
"{",
"addRecord",
"(",
"dbid",
",",
"@fvlist",
")",
"newRecordIDs",
"<<",
"@rid",
"if",
"@rid",
"and",
"@update_id",
"}",
"end",
"if",
"block_given?",
"newRecordIDs",
".",
"each",
"{",
"|",
"newRecordID",
"|",
"yield",
"newRecordID",
"}",
"else",
"newRecordIDs",
"end",
"end"
] | Make one or more copies of a record. | [
"Make",
"one",
"or",
"more",
"copies",
"of",
"a",
"record",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4277-L4298 |
4,149 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client._importFromExcel | def _importFromExcel(excelFilename,lastColumn = 'j',lastDataRow = 0,worksheetNumber = 1,fieldNameRow = 1,firstDataRow = 2,firstColumn = 'a')
importFromExcel( @dbid, excelFilename, lastColumn, lastDataRow, worksheetNumber, fieldNameRow, firstDataRow, firstColumn )
end | ruby | def _importFromExcel(excelFilename,lastColumn = 'j',lastDataRow = 0,worksheetNumber = 1,fieldNameRow = 1,firstDataRow = 2,firstColumn = 'a')
importFromExcel( @dbid, excelFilename, lastColumn, lastDataRow, worksheetNumber, fieldNameRow, firstDataRow, firstColumn )
end | [
"def",
"_importFromExcel",
"(",
"excelFilename",
",",
"lastColumn",
"=",
"'j'",
",",
"lastDataRow",
"=",
"0",
",",
"worksheetNumber",
"=",
"1",
",",
"fieldNameRow",
"=",
"1",
",",
"firstDataRow",
"=",
"2",
",",
"firstColumn",
"=",
"'a'",
")",
"importFromExcel",
"(",
"@dbid",
",",
"excelFilename",
",",
"lastColumn",
",",
"lastDataRow",
",",
"worksheetNumber",
",",
"fieldNameRow",
",",
"firstDataRow",
",",
"firstColumn",
")",
"end"
] | Import data directly from an Excel file into the active table. | [
"Import",
"data",
"directly",
"from",
"an",
"Excel",
"file",
"into",
"the",
"active",
"table",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4380-L4382 |
4,150 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.importCSVFile | def importCSVFile( filename, dbid = @dbid, targetFieldNames = nil, validateLines = true )
importSVFile( filename, ",", dbid, targetFieldNames, validateLines )
end | ruby | def importCSVFile( filename, dbid = @dbid, targetFieldNames = nil, validateLines = true )
importSVFile( filename, ",", dbid, targetFieldNames, validateLines )
end | [
"def",
"importCSVFile",
"(",
"filename",
",",
"dbid",
"=",
"@dbid",
",",
"targetFieldNames",
"=",
"nil",
",",
"validateLines",
"=",
"true",
")",
"importSVFile",
"(",
"filename",
",",
"\",\"",
",",
"dbid",
",",
"targetFieldNames",
",",
"validateLines",
")",
"end"
] | Add records from lines in a CSV file.
If dbid is not specified, the active table will be used.
values in subsequent lines. The file must not contain commas inside field names or values. | [
"Add",
"records",
"from",
"lines",
"in",
"a",
"CSV",
"file",
".",
"If",
"dbid",
"is",
"not",
"specified",
"the",
"active",
"table",
"will",
"be",
"used",
".",
"values",
"in",
"subsequent",
"lines",
".",
"The",
"file",
"must",
"not",
"contain",
"commas",
"inside",
"field",
"names",
"or",
"values",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4387-L4389 |
4,151 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.importTSVFile | def importTSVFile( filename, dbid = @dbid, targetFieldNames = nil, validateLines = true )
importSVFile( filename, "\t", dbid, targetFieldNames, validateLines )
end | ruby | def importTSVFile( filename, dbid = @dbid, targetFieldNames = nil, validateLines = true )
importSVFile( filename, "\t", dbid, targetFieldNames, validateLines )
end | [
"def",
"importTSVFile",
"(",
"filename",
",",
"dbid",
"=",
"@dbid",
",",
"targetFieldNames",
"=",
"nil",
",",
"validateLines",
"=",
"true",
")",
"importSVFile",
"(",
"filename",
",",
"\"\\t\"",
",",
"dbid",
",",
"targetFieldNames",
",",
"validateLines",
")",
"end"
] | Import records from a text file in Tab-Separated-Values format. | [
"Import",
"records",
"from",
"a",
"text",
"file",
"in",
"Tab",
"-",
"Separated",
"-",
"Values",
"format",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4392-L4394 |
4,152 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.makeSVFile | def makeSVFile( filename, fieldSeparator = ",", dbid = @dbid, query = nil, qid = nil, qname = nil )
File.open( filename, "w" ) { |file|
if dbid
doQuery( dbid, query, qid, qname )
end
if @records and @fields
# ------------- write field names on first line ----------------
output = ""
fieldNamesBlock = proc { |element|
if element.is_a?(REXML::Element) and element.name == "label" and element.has_text?
output << "#{element.text}#{fieldSeparator}"
end
}
processChildElements( @fields, true, fieldNamesBlock )
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
# ------------- write records ----------------
output = ""
valuesBlock = proc { |element|
if element.is_a?(REXML::Element)
if element.name == "record"
if output.length > 1
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
end
output = ""
elsif element.name == "f"
if element.has_text?
text = element.text
text.gsub!("<BR/>","\n")
text = "\"#{text}\"" if text.include?( fieldSeparator )
output << "#{text}#{fieldSeparator}"
else
output << "#{fieldSeparator}"
end
end
end
}
processChildElements( @records, false, valuesBlock )
if output.length > 1
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
output = ""
end
end
}
end | ruby | def makeSVFile( filename, fieldSeparator = ",", dbid = @dbid, query = nil, qid = nil, qname = nil )
File.open( filename, "w" ) { |file|
if dbid
doQuery( dbid, query, qid, qname )
end
if @records and @fields
# ------------- write field names on first line ----------------
output = ""
fieldNamesBlock = proc { |element|
if element.is_a?(REXML::Element) and element.name == "label" and element.has_text?
output << "#{element.text}#{fieldSeparator}"
end
}
processChildElements( @fields, true, fieldNamesBlock )
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
# ------------- write records ----------------
output = ""
valuesBlock = proc { |element|
if element.is_a?(REXML::Element)
if element.name == "record"
if output.length > 1
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
end
output = ""
elsif element.name == "f"
if element.has_text?
text = element.text
text.gsub!("<BR/>","\n")
text = "\"#{text}\"" if text.include?( fieldSeparator )
output << "#{text}#{fieldSeparator}"
else
output << "#{fieldSeparator}"
end
end
end
}
processChildElements( @records, false, valuesBlock )
if output.length > 1
output << "\n"
output.sub!( "#{fieldSeparator}\n", "\n" )
file.write( output )
output = ""
end
end
}
end | [
"def",
"makeSVFile",
"(",
"filename",
",",
"fieldSeparator",
"=",
"\",\"",
",",
"dbid",
"=",
"@dbid",
",",
"query",
"=",
"nil",
",",
"qid",
"=",
"nil",
",",
"qname",
"=",
"nil",
")",
"File",
".",
"open",
"(",
"filename",
",",
"\"w\"",
")",
"{",
"|",
"file",
"|",
"if",
"dbid",
"doQuery",
"(",
"dbid",
",",
"query",
",",
"qid",
",",
"qname",
")",
"end",
"if",
"@records",
"and",
"@fields",
"# ------------- write field names on first line ----------------\r",
"output",
"=",
"\"\"",
"fieldNamesBlock",
"=",
"proc",
"{",
"|",
"element",
"|",
"if",
"element",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"element",
".",
"name",
"==",
"\"label\"",
"and",
"element",
".",
"has_text?",
"output",
"<<",
"\"#{element.text}#{fieldSeparator}\"",
"end",
"}",
"processChildElements",
"(",
"@fields",
",",
"true",
",",
"fieldNamesBlock",
")",
"output",
"<<",
"\"\\n\"",
"output",
".",
"sub!",
"(",
"\"#{fieldSeparator}\\n\"",
",",
"\"\\n\"",
")",
"file",
".",
"write",
"(",
"output",
")",
"# ------------- write records ----------------\r",
"output",
"=",
"\"\"",
"valuesBlock",
"=",
"proc",
"{",
"|",
"element",
"|",
"if",
"element",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"if",
"element",
".",
"name",
"==",
"\"record\"",
"if",
"output",
".",
"length",
">",
"1",
"output",
"<<",
"\"\\n\"",
"output",
".",
"sub!",
"(",
"\"#{fieldSeparator}\\n\"",
",",
"\"\\n\"",
")",
"file",
".",
"write",
"(",
"output",
")",
"end",
"output",
"=",
"\"\"",
"elsif",
"element",
".",
"name",
"==",
"\"f\"",
"if",
"element",
".",
"has_text?",
"text",
"=",
"element",
".",
"text",
"text",
".",
"gsub!",
"(",
"\"<BR/>\"",
",",
"\"\\n\"",
")",
"text",
"=",
"\"\\\"#{text}\\\"\"",
"if",
"text",
".",
"include?",
"(",
"fieldSeparator",
")",
"output",
"<<",
"\"#{text}#{fieldSeparator}\"",
"else",
"output",
"<<",
"\"#{fieldSeparator}\"",
"end",
"end",
"end",
"}",
"processChildElements",
"(",
"@records",
",",
"false",
",",
"valuesBlock",
")",
"if",
"output",
".",
"length",
">",
"1",
"output",
"<<",
"\"\\n\"",
"output",
".",
"sub!",
"(",
"\"#{fieldSeparator}\\n\"",
",",
"\"\\n\"",
")",
"file",
".",
"write",
"(",
"output",
")",
"output",
"=",
"\"\"",
"end",
"end",
"}",
"end"
] | Make a CSV file using the results of a query.
Specify a different separator in the second paramater.
Fields containing the separator will be double-quoted.
e.g. makeSVFile( "contacts.txt", "\t", nil )
e.g. makeSVFile( "contacts.txt", ",", "dhnju5y7", nil, nil, "List Changes" ) | [
"Make",
"a",
"CSV",
"file",
"using",
"the",
"results",
"of",
"a",
"query",
".",
"Specify",
"a",
"different",
"separator",
"in",
"the",
"second",
"paramater",
".",
"Fields",
"containing",
"the",
"separator",
"will",
"be",
"double",
"-",
"quoted",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4489-L4544 |
4,153 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.makeCSVFileForReport | def makeCSVFileForReport(filename,dbid=@dbid,query=nil,qid=nil,qname=nil)
csv = getCSVForReport(dbid,query,qid,qname)
File.open(filename,"w"){|f|f.write(csv || "")}
end | ruby | def makeCSVFileForReport(filename,dbid=@dbid,query=nil,qid=nil,qname=nil)
csv = getCSVForReport(dbid,query,qid,qname)
File.open(filename,"w"){|f|f.write(csv || "")}
end | [
"def",
"makeCSVFileForReport",
"(",
"filename",
",",
"dbid",
"=",
"@dbid",
",",
"query",
"=",
"nil",
",",
"qid",
"=",
"nil",
",",
"qname",
"=",
"nil",
")",
"csv",
"=",
"getCSVForReport",
"(",
"dbid",
",",
"query",
",",
"qid",
",",
"qname",
")",
"File",
".",
"open",
"(",
"filename",
",",
"\"w\"",
")",
"{",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"csv",
"||",
"\"\"",
")",
"}",
"end"
] | Create a CSV file using the records for a Report. | [
"Create",
"a",
"CSV",
"file",
"using",
"the",
"records",
"for",
"a",
"Report",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4547-L4550 |
4,154 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.getCSVForReport | def getCSVForReport(dbid,query=nil,qid=nil,qname=nil)
genResultsTable(dbid,query,nil,nil,nil,nil,"csv",qid,qname)
end | ruby | def getCSVForReport(dbid,query=nil,qid=nil,qname=nil)
genResultsTable(dbid,query,nil,nil,nil,nil,"csv",qid,qname)
end | [
"def",
"getCSVForReport",
"(",
"dbid",
",",
"query",
"=",
"nil",
",",
"qid",
"=",
"nil",
",",
"qname",
"=",
"nil",
")",
"genResultsTable",
"(",
"dbid",
",",
"query",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"\"csv\"",
",",
"qid",
",",
"qname",
")",
"end"
] | Get the CSV data for a Report. | [
"Get",
"the",
"CSV",
"data",
"for",
"a",
"Report",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4553-L4555 |
4,155 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.doSQLUpdate | def doSQLUpdate(sqlString)
sql = sqlString.dup
dbname = ""
state = nil
fieldName = ""
fieldValue = ""
sqlQuery = "SELECT 3 FROM "
clearFieldValuePairList
sql.split(' ').each{ |token|
case token
when "UPDATE"
state = "getTable" unless state == "getFilter"
next
when "SET"
state = "getFieldName" unless state == "getFilter"
next
when "="
sqlQuery << " = " if state == "getFilter"
state = "getFieldValue" unless state == "getFilter"
next
when "WHERE"
sqlQuery << " WHERE "
state = "getFilter"
next
end
if state == "getTable"
dbname = token.dup
sqlQuery << dbname
elsif state == "getFieldName"
fieldName = token.gsub('[','').gsub(']','')
elsif state == "getFieldValue"
test = token
if test[-1,1] == "'" or test[-2,2] == "',"
fieldValue << token
if fieldValue[-2,2] == "',"
state = "getFieldName"
fieldValue.gsub!("',","")
end
fieldValue.gsub!("'","")
if fieldName.length > 0
addFieldValuePair(fieldName,nil,nil,fieldValue)
fieldName = ""
fieldValue = ""
end
else
fieldValue << "#{token} "
end
elsif state == "getFilter"
sqlQuery << token
end
}
rows = doSQLQuery(sqlQuery,:Array)
if rows and @dbid and @fvlist
idFieldName = lookupFieldNameFromID("3")
rows.each{ |row|
recordID = row[idFieldName]
editRecord(@dbid,recordID,@fvlist) if recordID
}
end
end | ruby | def doSQLUpdate(sqlString)
sql = sqlString.dup
dbname = ""
state = nil
fieldName = ""
fieldValue = ""
sqlQuery = "SELECT 3 FROM "
clearFieldValuePairList
sql.split(' ').each{ |token|
case token
when "UPDATE"
state = "getTable" unless state == "getFilter"
next
when "SET"
state = "getFieldName" unless state == "getFilter"
next
when "="
sqlQuery << " = " if state == "getFilter"
state = "getFieldValue" unless state == "getFilter"
next
when "WHERE"
sqlQuery << " WHERE "
state = "getFilter"
next
end
if state == "getTable"
dbname = token.dup
sqlQuery << dbname
elsif state == "getFieldName"
fieldName = token.gsub('[','').gsub(']','')
elsif state == "getFieldValue"
test = token
if test[-1,1] == "'" or test[-2,2] == "',"
fieldValue << token
if fieldValue[-2,2] == "',"
state = "getFieldName"
fieldValue.gsub!("',","")
end
fieldValue.gsub!("'","")
if fieldName.length > 0
addFieldValuePair(fieldName,nil,nil,fieldValue)
fieldName = ""
fieldValue = ""
end
else
fieldValue << "#{token} "
end
elsif state == "getFilter"
sqlQuery << token
end
}
rows = doSQLQuery(sqlQuery,:Array)
if rows and @dbid and @fvlist
idFieldName = lookupFieldNameFromID("3")
rows.each{ |row|
recordID = row[idFieldName]
editRecord(@dbid,recordID,@fvlist) if recordID
}
end
end | [
"def",
"doSQLUpdate",
"(",
"sqlString",
")",
"sql",
"=",
"sqlString",
".",
"dup",
"dbname",
"=",
"\"\"",
"state",
"=",
"nil",
"fieldName",
"=",
"\"\"",
"fieldValue",
"=",
"\"\"",
"sqlQuery",
"=",
"\"SELECT 3 FROM \"",
"clearFieldValuePairList",
"sql",
".",
"split",
"(",
"' '",
")",
".",
"each",
"{",
"|",
"token",
"|",
"case",
"token",
"when",
"\"UPDATE\"",
"state",
"=",
"\"getTable\"",
"unless",
"state",
"==",
"\"getFilter\"",
"next",
"when",
"\"SET\"",
"state",
"=",
"\"getFieldName\"",
"unless",
"state",
"==",
"\"getFilter\"",
"next",
"when",
"\"=\"",
"sqlQuery",
"<<",
"\" = \"",
"if",
"state",
"==",
"\"getFilter\"",
"state",
"=",
"\"getFieldValue\"",
"unless",
"state",
"==",
"\"getFilter\"",
"next",
"when",
"\"WHERE\"",
"sqlQuery",
"<<",
"\" WHERE \"",
"state",
"=",
"\"getFilter\"",
"next",
"end",
"if",
"state",
"==",
"\"getTable\"",
"dbname",
"=",
"token",
".",
"dup",
"sqlQuery",
"<<",
"dbname",
"elsif",
"state",
"==",
"\"getFieldName\"",
"fieldName",
"=",
"token",
".",
"gsub",
"(",
"'['",
",",
"''",
")",
".",
"gsub",
"(",
"']'",
",",
"''",
")",
"elsif",
"state",
"==",
"\"getFieldValue\"",
"test",
"=",
"token",
"if",
"test",
"[",
"-",
"1",
",",
"1",
"]",
"==",
"\"'\"",
"or",
"test",
"[",
"-",
"2",
",",
"2",
"]",
"==",
"\"',\"",
"fieldValue",
"<<",
"token",
"if",
"fieldValue",
"[",
"-",
"2",
",",
"2",
"]",
"==",
"\"',\"",
"state",
"=",
"\"getFieldName\"",
"fieldValue",
".",
"gsub!",
"(",
"\"',\"",
",",
"\"\"",
")",
"end",
"fieldValue",
".",
"gsub!",
"(",
"\"'\"",
",",
"\"\"",
")",
"if",
"fieldName",
".",
"length",
">",
"0",
"addFieldValuePair",
"(",
"fieldName",
",",
"nil",
",",
"nil",
",",
"fieldValue",
")",
"fieldName",
"=",
"\"\"",
"fieldValue",
"=",
"\"\"",
"end",
"else",
"fieldValue",
"<<",
"\"#{token} \"",
"end",
"elsif",
"state",
"==",
"\"getFilter\"",
"sqlQuery",
"<<",
"token",
"end",
"}",
"rows",
"=",
"doSQLQuery",
"(",
"sqlQuery",
",",
":Array",
")",
"if",
"rows",
"and",
"@dbid",
"and",
"@fvlist",
"idFieldName",
"=",
"lookupFieldNameFromID",
"(",
"\"3\"",
")",
"rows",
".",
"each",
"{",
"|",
"row",
"|",
"recordID",
"=",
"row",
"[",
"idFieldName",
"]",
"editRecord",
"(",
"@dbid",
",",
"recordID",
",",
"@fvlist",
")",
"if",
"recordID",
"}",
"end",
"end"
] | Translate a simple SQL UPDATE statement to a QuickBase editRecord call.
Note: This method is here primarily for Rails integration.
Note: This assumes, like SQL, that your column (i.e. field) names do not contain spaces.
Note: This assumes that Record ID# is the key field in your table. | [
"Translate",
"a",
"simple",
"SQL",
"UPDATE",
"statement",
"to",
"a",
"QuickBase",
"editRecord",
"call",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4828-L4892 |
4,156 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.doSQLInsert | def doSQLInsert(sqlString)
sql = sqlString.dup
dbname = ""
state = nil
fieldName = ""
fieldValue = ""
fieldNames = []
fieldValues = []
index = 0
clearFieldValuePairList
sql.gsub!("("," ")
sql.gsub!(")"," ")
sql.split(' ').each{ |token|
case token
when "INSERT", "INTO"
state = "getTable"
next
when "VALUES"
state = "getFieldValue"
next
end
if state == "getTable"
dbname = token.strip
state = "getFieldName"
elsif state == "getFieldName"
fieldName = token.dup
fieldName.gsub!("],","")
fieldName.gsub!('[','')
fieldName.gsub!(']','')
fieldName.gsub!(',','')
fieldNames << fieldName
elsif state == "getFieldValue"
test = token.dup
if test[-1,1] == "'" or test[-2,2] == "',"
fieldValue << token.dup
if fieldValue[-2,2] == "',"
fieldValue.gsub!("',",'')
end
fieldValue.gsub!('\'','')
if fieldValue.length > 0 and fieldNames[index]
addFieldValuePair(fieldNames[index],nil,nil,fieldValue)
fieldName = ""
fieldValue = ""
end
index += 1
elsif token == ","
addFieldValuePair(fieldNames[index],nil,nil,"")
fieldName = ""
fieldValue = ""
index += 1
else
fieldValue << "#{token.dup} "
end
end
}
if dbname and @dbid.nil?
dbid = findDBByname( dbname )
else
dbid = lookupChdbid( dbname )
end
dbid ||= @dbid
recordid = nil
if dbid
recordid,updateid = addRecord(dbid,@fvlist)
end
recordid
end | ruby | def doSQLInsert(sqlString)
sql = sqlString.dup
dbname = ""
state = nil
fieldName = ""
fieldValue = ""
fieldNames = []
fieldValues = []
index = 0
clearFieldValuePairList
sql.gsub!("("," ")
sql.gsub!(")"," ")
sql.split(' ').each{ |token|
case token
when "INSERT", "INTO"
state = "getTable"
next
when "VALUES"
state = "getFieldValue"
next
end
if state == "getTable"
dbname = token.strip
state = "getFieldName"
elsif state == "getFieldName"
fieldName = token.dup
fieldName.gsub!("],","")
fieldName.gsub!('[','')
fieldName.gsub!(']','')
fieldName.gsub!(',','')
fieldNames << fieldName
elsif state == "getFieldValue"
test = token.dup
if test[-1,1] == "'" or test[-2,2] == "',"
fieldValue << token.dup
if fieldValue[-2,2] == "',"
fieldValue.gsub!("',",'')
end
fieldValue.gsub!('\'','')
if fieldValue.length > 0 and fieldNames[index]
addFieldValuePair(fieldNames[index],nil,nil,fieldValue)
fieldName = ""
fieldValue = ""
end
index += 1
elsif token == ","
addFieldValuePair(fieldNames[index],nil,nil,"")
fieldName = ""
fieldValue = ""
index += 1
else
fieldValue << "#{token.dup} "
end
end
}
if dbname and @dbid.nil?
dbid = findDBByname( dbname )
else
dbid = lookupChdbid( dbname )
end
dbid ||= @dbid
recordid = nil
if dbid
recordid,updateid = addRecord(dbid,@fvlist)
end
recordid
end | [
"def",
"doSQLInsert",
"(",
"sqlString",
")",
"sql",
"=",
"sqlString",
".",
"dup",
"dbname",
"=",
"\"\"",
"state",
"=",
"nil",
"fieldName",
"=",
"\"\"",
"fieldValue",
"=",
"\"\"",
"fieldNames",
"=",
"[",
"]",
"fieldValues",
"=",
"[",
"]",
"index",
"=",
"0",
"clearFieldValuePairList",
"sql",
".",
"gsub!",
"(",
"\"(\"",
",",
"\" \"",
")",
"sql",
".",
"gsub!",
"(",
"\")\"",
",",
"\" \"",
")",
"sql",
".",
"split",
"(",
"' '",
")",
".",
"each",
"{",
"|",
"token",
"|",
"case",
"token",
"when",
"\"INSERT\"",
",",
"\"INTO\"",
"state",
"=",
"\"getTable\"",
"next",
"when",
"\"VALUES\"",
"state",
"=",
"\"getFieldValue\"",
"next",
"end",
"if",
"state",
"==",
"\"getTable\"",
"dbname",
"=",
"token",
".",
"strip",
"state",
"=",
"\"getFieldName\"",
"elsif",
"state",
"==",
"\"getFieldName\"",
"fieldName",
"=",
"token",
".",
"dup",
"fieldName",
".",
"gsub!",
"(",
"\"],\"",
",",
"\"\"",
")",
"fieldName",
".",
"gsub!",
"(",
"'['",
",",
"''",
")",
"fieldName",
".",
"gsub!",
"(",
"']'",
",",
"''",
")",
"fieldName",
".",
"gsub!",
"(",
"','",
",",
"''",
")",
"fieldNames",
"<<",
"fieldName",
"elsif",
"state",
"==",
"\"getFieldValue\"",
"test",
"=",
"token",
".",
"dup",
"if",
"test",
"[",
"-",
"1",
",",
"1",
"]",
"==",
"\"'\"",
"or",
"test",
"[",
"-",
"2",
",",
"2",
"]",
"==",
"\"',\"",
"fieldValue",
"<<",
"token",
".",
"dup",
"if",
"fieldValue",
"[",
"-",
"2",
",",
"2",
"]",
"==",
"\"',\"",
"fieldValue",
".",
"gsub!",
"(",
"\"',\"",
",",
"''",
")",
"end",
"fieldValue",
".",
"gsub!",
"(",
"'\\''",
",",
"''",
")",
"if",
"fieldValue",
".",
"length",
">",
"0",
"and",
"fieldNames",
"[",
"index",
"]",
"addFieldValuePair",
"(",
"fieldNames",
"[",
"index",
"]",
",",
"nil",
",",
"nil",
",",
"fieldValue",
")",
"fieldName",
"=",
"\"\"",
"fieldValue",
"=",
"\"\"",
"end",
"index",
"+=",
"1",
"elsif",
"token",
"==",
"\",\"",
"addFieldValuePair",
"(",
"fieldNames",
"[",
"index",
"]",
",",
"nil",
",",
"nil",
",",
"\"\"",
")",
"fieldName",
"=",
"\"\"",
"fieldValue",
"=",
"\"\"",
"index",
"+=",
"1",
"else",
"fieldValue",
"<<",
"\"#{token.dup} \"",
"end",
"end",
"}",
"if",
"dbname",
"and",
"@dbid",
".",
"nil?",
"dbid",
"=",
"findDBByname",
"(",
"dbname",
")",
"else",
"dbid",
"=",
"lookupChdbid",
"(",
"dbname",
")",
"end",
"dbid",
"||=",
"@dbid",
"recordid",
"=",
"nil",
"if",
"dbid",
"recordid",
",",
"updateid",
"=",
"addRecord",
"(",
"dbid",
",",
"@fvlist",
")",
"end",
"recordid",
"end"
] | Translate a simple SQL INSERT statement to a QuickBase addRecord call.
Note: This method is here primarily for Rails integration.
Note: This assumes, like SQL, that your column (i.e. field) names do not contain spaces. | [
"Translate",
"a",
"simple",
"SQL",
"INSERT",
"statement",
"to",
"a",
"QuickBase",
"addRecord",
"call",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4898-L4971 |
4,157 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.eachField | def eachField( record = @record )
if record and block_given?
record.each{ |field|
if field.is_a?( REXML::Element) and field.name == "f" and field.attributes["id"]
@field = field
yield field
end
}
end
nil
end | ruby | def eachField( record = @record )
if record and block_given?
record.each{ |field|
if field.is_a?( REXML::Element) and field.name == "f" and field.attributes["id"]
@field = field
yield field
end
}
end
nil
end | [
"def",
"eachField",
"(",
"record",
"=",
"@record",
")",
"if",
"record",
"and",
"block_given?",
"record",
".",
"each",
"{",
"|",
"field",
"|",
"if",
"field",
".",
"is_a?",
"(",
"REXML",
"::",
"Element",
")",
"and",
"field",
".",
"name",
"==",
"\"f\"",
"and",
"field",
".",
"attributes",
"[",
"\"id\"",
"]",
"@field",
"=",
"field",
"yield",
"field",
"end",
"}",
"end",
"nil",
"end"
] | Iterate record XML and yield only 'f' elements. | [
"Iterate",
"record",
"XML",
"and",
"yield",
"only",
"f",
"elements",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L4987-L4997 |
4,158 | garethlatwork/quickbase_client | lib/QuickBaseClient.rb | QuickBase.Client.alias_methods | def alias_methods
aliased_methods = []
public_methods.each{|old_method|
if old_method.match(/[A-Z]+/)
new_method = old_method.gsub(/[A-Z]+/){|uc| "_#{uc.downcase}"}
aliased_methods << new_method
instance_eval( "alias #{new_method} #{old_method}")
end
}
aliased_methods
end | ruby | def alias_methods
aliased_methods = []
public_methods.each{|old_method|
if old_method.match(/[A-Z]+/)
new_method = old_method.gsub(/[A-Z]+/){|uc| "_#{uc.downcase}"}
aliased_methods << new_method
instance_eval( "alias #{new_method} #{old_method}")
end
}
aliased_methods
end | [
"def",
"alias_methods",
"aliased_methods",
"=",
"[",
"]",
"public_methods",
".",
"each",
"{",
"|",
"old_method",
"|",
"if",
"old_method",
".",
"match",
"(",
"/",
"/",
")",
"new_method",
"=",
"old_method",
".",
"gsub",
"(",
"/",
"/",
")",
"{",
"|",
"uc",
"|",
"\"_#{uc.downcase}\"",
"}",
"aliased_methods",
"<<",
"new_method",
"instance_eval",
"(",
"\"alias #{new_method} #{old_method}\"",
")",
"end",
"}",
"aliased_methods",
"end"
] | Add method aliases that follow the ruby method naming convention.
E.g. sendRequest will be aliased as send_request. | [
"Add",
"method",
"aliases",
"that",
"follow",
"the",
"ruby",
"method",
"naming",
"convention",
".",
"E",
".",
"g",
".",
"sendRequest",
"will",
"be",
"aliased",
"as",
"send_request",
"."
] | 13d754de1f22a466806c5a0da74b0ded26c23f05 | https://github.com/garethlatwork/quickbase_client/blob/13d754de1f22a466806c5a0da74b0ded26c23f05/lib/QuickBaseClient.rb#L5007-L5017 |
4,159 | sethvargo/community-zero | lib/community_zero/objects/cookbook.rb | CommunityZero.Cookbook.to_hash | def to_hash
methods = instance_variables.map { |i| i.to_s.gsub('@', '') }
Hash[*methods.map { |m| [m, send(m.to_sym)] }.flatten]
end | ruby | def to_hash
methods = instance_variables.map { |i| i.to_s.gsub('@', '') }
Hash[*methods.map { |m| [m, send(m.to_sym)] }.flatten]
end | [
"def",
"to_hash",
"methods",
"=",
"instance_variables",
".",
"map",
"{",
"|",
"i",
"|",
"i",
".",
"to_s",
".",
"gsub",
"(",
"'@'",
",",
"''",
")",
"}",
"Hash",
"[",
"methods",
".",
"map",
"{",
"|",
"m",
"|",
"[",
"m",
",",
"send",
"(",
"m",
".",
"to_sym",
")",
"]",
"}",
".",
"flatten",
"]",
"end"
] | Create a new cookbook from the given hash.
@param [Hash] hash
the hash from which to create the cookbook
Dump this cookbook to a hash.
@return [Hash]
the hash representation of this cookbook | [
"Create",
"a",
"new",
"cookbook",
"from",
"the",
"given",
"hash",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/objects/cookbook.rb#L36-L39 |
4,160 | scrapper/perobs | lib/perobs/Array.rb | PEROBS.Array._referenced_object_ids | def _referenced_object_ids
@data.each.select do |v|
v && v.respond_to?(:is_poxreference?)
end.map { |o| o.id }
end | ruby | def _referenced_object_ids
@data.each.select do |v|
v && v.respond_to?(:is_poxreference?)
end.map { |o| o.id }
end | [
"def",
"_referenced_object_ids",
"@data",
".",
"each",
".",
"select",
"do",
"|",
"v",
"|",
"v",
"&&",
"v",
".",
"respond_to?",
"(",
":is_poxreference?",
")",
"end",
".",
"map",
"{",
"|",
"o",
"|",
"o",
".",
"id",
"}",
"end"
] | Return a list of all object IDs of all persistend objects that this Array
is referencing.
@return [Array of Integer] IDs of referenced objects | [
"Return",
"a",
"list",
"of",
"all",
"object",
"IDs",
"of",
"all",
"persistend",
"objects",
"that",
"this",
"Array",
"is",
"referencing",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Array.rb#L145-L149 |
4,161 | pupeno/assert_difference | lib/assert_difference/expectation.rb | AssertDifference.Expectation.generate_expected_value | def generate_expected_value
if expected_difference.is_a? Range
(before_value + expected_difference.first)..(before_value + expected_difference.end)
else
before_value + expected_difference
end
end | ruby | def generate_expected_value
if expected_difference.is_a? Range
(before_value + expected_difference.first)..(before_value + expected_difference.end)
else
before_value + expected_difference
end
end | [
"def",
"generate_expected_value",
"if",
"expected_difference",
".",
"is_a?",
"Range",
"(",
"before_value",
"+",
"expected_difference",
".",
"first",
")",
"..",
"(",
"before_value",
"+",
"expected_difference",
".",
"end",
")",
"else",
"before_value",
"+",
"expected_difference",
"end",
"end"
] | Generate the expected value.
@return [Integer, Range] Generate the expected value. | [
"Generate",
"the",
"expected",
"value",
"."
] | 56490e7157dd975caed8080abd910a559e3bd785 | https://github.com/pupeno/assert_difference/blob/56490e7157dd975caed8080abd910a559e3bd785/lib/assert_difference/expectation.rb#L77-L83 |
4,162 | PublicHealthEngland/ndr_support | lib/ndr_support/obfuscator.rb | NdrSupport.Obfuscator.obfuscate | def obfuscate(name, seed = nil)
rnd = Random.new(seed || @seed)
vowels = %w(A E I O U)
consonants = ('A'..'Z').to_a - vowels
digits = ('0'..'9').to_a
dict = Hash[(vowels + consonants + digits).zip(vowels.shuffle(random: rnd) +
consonants.shuffle(random: rnd) +
digits.shuffle(random: rnd))]
name.upcase.split(//).map { |s| dict[s] || s }.join
end | ruby | def obfuscate(name, seed = nil)
rnd = Random.new(seed || @seed)
vowels = %w(A E I O U)
consonants = ('A'..'Z').to_a - vowels
digits = ('0'..'9').to_a
dict = Hash[(vowels + consonants + digits).zip(vowels.shuffle(random: rnd) +
consonants.shuffle(random: rnd) +
digits.shuffle(random: rnd))]
name.upcase.split(//).map { |s| dict[s] || s }.join
end | [
"def",
"obfuscate",
"(",
"name",
",",
"seed",
"=",
"nil",
")",
"rnd",
"=",
"Random",
".",
"new",
"(",
"seed",
"||",
"@seed",
")",
"vowels",
"=",
"%w(",
"A",
"E",
"I",
"O",
"U",
")",
"consonants",
"=",
"(",
"'A'",
"..",
"'Z'",
")",
".",
"to_a",
"-",
"vowels",
"digits",
"=",
"(",
"'0'",
"..",
"'9'",
")",
".",
"to_a",
"dict",
"=",
"Hash",
"[",
"(",
"vowels",
"+",
"consonants",
"+",
"digits",
")",
".",
"zip",
"(",
"vowels",
".",
"shuffle",
"(",
"random",
":",
"rnd",
")",
"+",
"consonants",
".",
"shuffle",
"(",
"random",
":",
"rnd",
")",
"+",
"digits",
".",
"shuffle",
"(",
"random",
":",
"rnd",
")",
")",
"]",
"name",
".",
"upcase",
".",
"split",
"(",
"/",
"/",
")",
".",
"map",
"{",
"|",
"s",
"|",
"dict",
"[",
"s",
"]",
"||",
"s",
"}",
".",
"join",
"end"
] | Obfuscate a name or address, either with the given seed, or default seed | [
"Obfuscate",
"a",
"name",
"or",
"address",
"either",
"with",
"the",
"given",
"seed",
"or",
"default",
"seed"
] | 6daf98ca972e79de1c8457eb720f058b03ead21c | https://github.com/PublicHealthEngland/ndr_support/blob/6daf98ca972e79de1c8457eb720f058b03ead21c/lib/ndr_support/obfuscator.rb#L13-L22 |
4,163 | sethvargo/community-zero | lib/community_zero/server.rb | CommunityZero.Server.start_background | def start_background(wait = 5)
@server = WEBrick::HTTPServer.new(
:BindAddress => @options[:host],
:Port => @options[:port],
:AccessLog => [],
:Logger => WEBrick::Log.new(StringIO.new, 7)
)
@server.mount('/', Rack::Handler::WEBrick, app)
@thread = Thread.new { @server.start }
@thread.abort_on_exception = true
@thread
end | ruby | def start_background(wait = 5)
@server = WEBrick::HTTPServer.new(
:BindAddress => @options[:host],
:Port => @options[:port],
:AccessLog => [],
:Logger => WEBrick::Log.new(StringIO.new, 7)
)
@server.mount('/', Rack::Handler::WEBrick, app)
@thread = Thread.new { @server.start }
@thread.abort_on_exception = true
@thread
end | [
"def",
"start_background",
"(",
"wait",
"=",
"5",
")",
"@server",
"=",
"WEBrick",
"::",
"HTTPServer",
".",
"new",
"(",
":BindAddress",
"=>",
"@options",
"[",
":host",
"]",
",",
":Port",
"=>",
"@options",
"[",
":port",
"]",
",",
":AccessLog",
"=>",
"[",
"]",
",",
":Logger",
"=>",
"WEBrick",
"::",
"Log",
".",
"new",
"(",
"StringIO",
".",
"new",
",",
"7",
")",
")",
"@server",
".",
"mount",
"(",
"'/'",
",",
"Rack",
"::",
"Handler",
"::",
"WEBrick",
",",
"app",
")",
"@thread",
"=",
"Thread",
".",
"new",
"{",
"@server",
".",
"start",
"}",
"@thread",
".",
"abort_on_exception",
"=",
"true",
"@thread",
"end"
] | Start a Community Zero server in a forked process. This method returns
the PID to the forked process.
@param [Fixnum] wait
the number of seconds to wait for the server to start
@return [Thread]
the thread the background process is running in | [
"Start",
"a",
"Community",
"Zero",
"server",
"in",
"a",
"forked",
"process",
".",
"This",
"method",
"returns",
"the",
"PID",
"to",
"the",
"forked",
"process",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/server.rb#L121-L133 |
4,164 | sethvargo/community-zero | lib/community_zero/server.rb | CommunityZero.Server.running? | def running?
if @server.nil? || @server.status != :Running
return false
end
uri = URI.join(url, 'cookbooks')
headers = { 'Accept' => 'application/json' }
Timeout.timeout(0.1) { !open(uri, headers).nil? }
rescue SocketError, Errno::ECONNREFUSED, Timeout::Error
false
end | ruby | def running?
if @server.nil? || @server.status != :Running
return false
end
uri = URI.join(url, 'cookbooks')
headers = { 'Accept' => 'application/json' }
Timeout.timeout(0.1) { !open(uri, headers).nil? }
rescue SocketError, Errno::ECONNREFUSED, Timeout::Error
false
end | [
"def",
"running?",
"if",
"@server",
".",
"nil?",
"||",
"@server",
".",
"status",
"!=",
":Running",
"return",
"false",
"end",
"uri",
"=",
"URI",
".",
"join",
"(",
"url",
",",
"'cookbooks'",
")",
"headers",
"=",
"{",
"'Accept'",
"=>",
"'application/json'",
"}",
"Timeout",
".",
"timeout",
"(",
"0.1",
")",
"{",
"!",
"open",
"(",
"uri",
",",
"headers",
")",
".",
"nil?",
"}",
"rescue",
"SocketError",
",",
"Errno",
"::",
"ECONNREFUSED",
",",
"Timeout",
"::",
"Error",
"false",
"end"
] | Boolean method to determine if the server is currently ready to accept
requests. This method will attempt to make an HTTP request against the
server. If this method returns true, you are safe to make a request.
@return [Boolean]
true if the server is accepting requests, false otherwise | [
"Boolean",
"method",
"to",
"determine",
"if",
"the",
"server",
"is",
"currently",
"ready",
"to",
"accept",
"requests",
".",
"This",
"method",
"will",
"attempt",
"to",
"make",
"an",
"HTTP",
"request",
"against",
"the",
"server",
".",
"If",
"this",
"method",
"returns",
"true",
"you",
"are",
"safe",
"to",
"make",
"a",
"request",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/server.rb#L143-L154 |
4,165 | sethvargo/community-zero | lib/community_zero/server.rb | CommunityZero.Server.stop | def stop(wait = 5)
Timeout.timeout(wait) do
@server.shutdown
@thread.join(wait) if @thread
end
rescue Timeout::Error
if @thread
$stderr.puts("Community Zero did not stop within #{wait} seconds! Killing...")
@thread.kill
end
ensure
@server = nil
@thread = nil
end | ruby | def stop(wait = 5)
Timeout.timeout(wait) do
@server.shutdown
@thread.join(wait) if @thread
end
rescue Timeout::Error
if @thread
$stderr.puts("Community Zero did not stop within #{wait} seconds! Killing...")
@thread.kill
end
ensure
@server = nil
@thread = nil
end | [
"def",
"stop",
"(",
"wait",
"=",
"5",
")",
"Timeout",
".",
"timeout",
"(",
"wait",
")",
"do",
"@server",
".",
"shutdown",
"@thread",
".",
"join",
"(",
"wait",
")",
"if",
"@thread",
"end",
"rescue",
"Timeout",
"::",
"Error",
"if",
"@thread",
"$stderr",
".",
"puts",
"(",
"\"Community Zero did not stop within #{wait} seconds! Killing...\"",
")",
"@thread",
".",
"kill",
"end",
"ensure",
"@server",
"=",
"nil",
"@thread",
"=",
"nil",
"end"
] | Gracefully stop the Community Zero server.
@param [Fixnum] wait
the number of seconds to wait before raising force-terminating the
server | [
"Gracefully",
"stop",
"the",
"Community",
"Zero",
"server",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/server.rb#L163-L176 |
4,166 | sethvargo/community-zero | lib/community_zero/server.rb | CommunityZero.Server.app | def app
lambda do |env|
request = Request.new(env)
response = router.call(request)
response[-1] = Array(response[-1])
response
end
end | ruby | def app
lambda do |env|
request = Request.new(env)
response = router.call(request)
response[-1] = Array(response[-1])
response
end
end | [
"def",
"app",
"lambda",
"do",
"|",
"env",
"|",
"request",
"=",
"Request",
".",
"new",
"(",
"env",
")",
"response",
"=",
"router",
".",
"call",
"(",
"request",
")",
"response",
"[",
"-",
"1",
"]",
"=",
"Array",
"(",
"response",
"[",
"-",
"1",
"]",
")",
"response",
"end",
"end"
] | The actual application the server will respond to.
@return [RackApp] | [
"The",
"actual",
"application",
"the",
"server",
"will",
"respond",
"to",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/server.rb#L199-L207 |
4,167 | sethvargo/community-zero | lib/community_zero/endpoints/cookbooks_endpoint.rb | CommunityZero.CookbooksEndpoint.create_cookbook | def create_cookbook(metadata, overrides = {})
cookbook = Cookbook.new({
:name => metadata.name,
:category => nil,
:maintainer => metadata.maintainer,
:description => metadata.description,
:version => metadata.version
}.merge(overrides))
store.add(cookbook)
cookbook
end | ruby | def create_cookbook(metadata, overrides = {})
cookbook = Cookbook.new({
:name => metadata.name,
:category => nil,
:maintainer => metadata.maintainer,
:description => metadata.description,
:version => metadata.version
}.merge(overrides))
store.add(cookbook)
cookbook
end | [
"def",
"create_cookbook",
"(",
"metadata",
",",
"overrides",
"=",
"{",
"}",
")",
"cookbook",
"=",
"Cookbook",
".",
"new",
"(",
"{",
":name",
"=>",
"metadata",
".",
"name",
",",
":category",
"=>",
"nil",
",",
":maintainer",
"=>",
"metadata",
".",
"maintainer",
",",
":description",
"=>",
"metadata",
".",
"description",
",",
":version",
"=>",
"metadata",
".",
"version",
"}",
".",
"merge",
"(",
"overrides",
")",
")",
"store",
".",
"add",
"(",
"cookbook",
")",
"cookbook",
"end"
] | Create the cookbook from the metadata.
@param [CommunityZero::Metadata] metadata
the metadata to create the cookbook from | [
"Create",
"the",
"cookbook",
"from",
"the",
"metadata",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/endpoints/cookbooks_endpoint.rb#L71-L83 |
4,168 | sethvargo/community-zero | lib/community_zero/endpoints/cookbooks_endpoint.rb | CommunityZero.CookbooksEndpoint.find_metadata | def find_metadata(tarball)
gzip = Zlib::GzipReader.new(tarball[:tempfile])
tar = Gem::Package::TarReader.new(gzip)
tar.each do |entry|
if entry.full_name =~ /metadata\.json$/
return Metadata.from_json(entry.read)
elsif entry.full_name =~ /metadata\.rb$/
return Metadata.from_ruby(entry.read)
end
end
ensure
tar.close
end | ruby | def find_metadata(tarball)
gzip = Zlib::GzipReader.new(tarball[:tempfile])
tar = Gem::Package::TarReader.new(gzip)
tar.each do |entry|
if entry.full_name =~ /metadata\.json$/
return Metadata.from_json(entry.read)
elsif entry.full_name =~ /metadata\.rb$/
return Metadata.from_ruby(entry.read)
end
end
ensure
tar.close
end | [
"def",
"find_metadata",
"(",
"tarball",
")",
"gzip",
"=",
"Zlib",
"::",
"GzipReader",
".",
"new",
"(",
"tarball",
"[",
":tempfile",
"]",
")",
"tar",
"=",
"Gem",
"::",
"Package",
"::",
"TarReader",
".",
"new",
"(",
"gzip",
")",
"tar",
".",
"each",
"do",
"|",
"entry",
"|",
"if",
"entry",
".",
"full_name",
"=~",
"/",
"\\.",
"/",
"return",
"Metadata",
".",
"from_json",
"(",
"entry",
".",
"read",
")",
"elsif",
"entry",
".",
"full_name",
"=~",
"/",
"\\.",
"/",
"return",
"Metadata",
".",
"from_ruby",
"(",
"entry",
".",
"read",
")",
"end",
"end",
"ensure",
"tar",
".",
"close",
"end"
] | Parse the metadata from the tarball.
@param [Tempfile] tarball
the temporarily uploaded file
@return [Metadata] | [
"Parse",
"the",
"metadata",
"from",
"the",
"tarball",
"."
] | 08a22c47c865deb6a5f931cb4d9f747a2b9d3459 | https://github.com/sethvargo/community-zero/blob/08a22c47c865deb6a5f931cb4d9f747a2b9d3459/lib/community_zero/endpoints/cookbooks_endpoint.rb#L91-L104 |
4,169 | holtrop/ruby-gnucash | lib/gnucash/account.rb | Gnucash.Account.finalize | def finalize
@transactions.sort! { |a, b| a.date <=> b.date }
balance = Value.new(0)
@balances = @transactions.map do |act_txn|
balance += act_txn.value
{
date: act_txn.date,
value: balance,
}
end
end | ruby | def finalize
@transactions.sort! { |a, b| a.date <=> b.date }
balance = Value.new(0)
@balances = @transactions.map do |act_txn|
balance += act_txn.value
{
date: act_txn.date,
value: balance,
}
end
end | [
"def",
"finalize",
"@transactions",
".",
"sort!",
"{",
"|",
"a",
",",
"b",
"|",
"a",
".",
"date",
"<=>",
"b",
".",
"date",
"}",
"balance",
"=",
"Value",
".",
"new",
"(",
"0",
")",
"@balances",
"=",
"@transactions",
".",
"map",
"do",
"|",
"act_txn",
"|",
"balance",
"+=",
"act_txn",
".",
"value",
"{",
"date",
":",
"act_txn",
".",
"date",
",",
"value",
":",
"balance",
",",
"}",
"end",
"end"
] | Internal method used to complete initialization of the Account after
all transactions have been associated with it.
@return [void] | [
"Internal",
"method",
"used",
"to",
"complete",
"initialization",
"of",
"the",
"Account",
"after",
"all",
"transactions",
"have",
"been",
"associated",
"with",
"it",
"."
] | a233cc4da0f36b13bc3f7a17264adb82c8a12c6b | https://github.com/holtrop/ruby-gnucash/blob/a233cc4da0f36b13bc3f7a17264adb82c8a12c6b/lib/gnucash/account.rb#L78-L88 |
4,170 | snowplow/iglu-ruby-client | lib/iglu-client/resolver.rb | Iglu.Resolver.lookup_schema | def lookup_schema(schema_key)
lookup_time = Time.now.getutc
if schema_key.is_a?(String)
schema_key = SchemaKey.parse_key(schema_key)
end
failures = []
cache_result = @cache[schema_key]
if not cache_result.nil?
if not @cacheTtl.nil?
store_time = cache_result[1]
time_diff = (lookup_time - store_time).round
if time_diff >= @cacheTtl
@cache.delete(schema_key)
cache_result = nil
else
return cache_result[0]
end
else
return cache_result[0]
end
end
if cache_result.nil? # Fetch from every registry
for registry in prioritize_repos(schema_key, @registries) do
begin
lookup_result = registry.lookup_schema(schema_key)
rescue StandardError => e
failures.push(Registries::LookupFailure.new(registry.config.name, e))
else
if lookup_result.nil?
failures.push(Registries::NotFound.new(registry.config.name))
else
break
end
end
end
if lookup_result.nil?
raise Registries::ResolverError.new(failures, schema_key)
else
store_time = Time.now.getutc
@cache[schema_key] = [lookup_result, store_time]
lookup_result
end
end
end | ruby | def lookup_schema(schema_key)
lookup_time = Time.now.getutc
if schema_key.is_a?(String)
schema_key = SchemaKey.parse_key(schema_key)
end
failures = []
cache_result = @cache[schema_key]
if not cache_result.nil?
if not @cacheTtl.nil?
store_time = cache_result[1]
time_diff = (lookup_time - store_time).round
if time_diff >= @cacheTtl
@cache.delete(schema_key)
cache_result = nil
else
return cache_result[0]
end
else
return cache_result[0]
end
end
if cache_result.nil? # Fetch from every registry
for registry in prioritize_repos(schema_key, @registries) do
begin
lookup_result = registry.lookup_schema(schema_key)
rescue StandardError => e
failures.push(Registries::LookupFailure.new(registry.config.name, e))
else
if lookup_result.nil?
failures.push(Registries::NotFound.new(registry.config.name))
else
break
end
end
end
if lookup_result.nil?
raise Registries::ResolverError.new(failures, schema_key)
else
store_time = Time.now.getutc
@cache[schema_key] = [lookup_result, store_time]
lookup_result
end
end
end | [
"def",
"lookup_schema",
"(",
"schema_key",
")",
"lookup_time",
"=",
"Time",
".",
"now",
".",
"getutc",
"if",
"schema_key",
".",
"is_a?",
"(",
"String",
")",
"schema_key",
"=",
"SchemaKey",
".",
"parse_key",
"(",
"schema_key",
")",
"end",
"failures",
"=",
"[",
"]",
"cache_result",
"=",
"@cache",
"[",
"schema_key",
"]",
"if",
"not",
"cache_result",
".",
"nil?",
"if",
"not",
"@cacheTtl",
".",
"nil?",
"store_time",
"=",
"cache_result",
"[",
"1",
"]",
"time_diff",
"=",
"(",
"lookup_time",
"-",
"store_time",
")",
".",
"round",
"if",
"time_diff",
">=",
"@cacheTtl",
"@cache",
".",
"delete",
"(",
"schema_key",
")",
"cache_result",
"=",
"nil",
"else",
"return",
"cache_result",
"[",
"0",
"]",
"end",
"else",
"return",
"cache_result",
"[",
"0",
"]",
"end",
"end",
"if",
"cache_result",
".",
"nil?",
"# Fetch from every registry",
"for",
"registry",
"in",
"prioritize_repos",
"(",
"schema_key",
",",
"@registries",
")",
"do",
"begin",
"lookup_result",
"=",
"registry",
".",
"lookup_schema",
"(",
"schema_key",
")",
"rescue",
"StandardError",
"=>",
"e",
"failures",
".",
"push",
"(",
"Registries",
"::",
"LookupFailure",
".",
"new",
"(",
"registry",
".",
"config",
".",
"name",
",",
"e",
")",
")",
"else",
"if",
"lookup_result",
".",
"nil?",
"failures",
".",
"push",
"(",
"Registries",
"::",
"NotFound",
".",
"new",
"(",
"registry",
".",
"config",
".",
"name",
")",
")",
"else",
"break",
"end",
"end",
"end",
"if",
"lookup_result",
".",
"nil?",
"raise",
"Registries",
"::",
"ResolverError",
".",
"new",
"(",
"failures",
",",
"schema_key",
")",
"else",
"store_time",
"=",
"Time",
".",
"now",
".",
"getutc",
"@cache",
"[",
"schema_key",
"]",
"=",
"[",
"lookup_result",
",",
"store_time",
"]",
"lookup_result",
"end",
"end",
"end"
] | Lookup schema in cache or try to fetch | [
"Lookup",
"schema",
"in",
"cache",
"or",
"try",
"to",
"fetch"
] | 6d41668dc3e5615e3358a952e193812b5c4b3d6b | https://github.com/snowplow/iglu-ruby-client/blob/6d41668dc3e5615e3358a952e193812b5c4b3d6b/lib/iglu-client/resolver.rb#L28-L74 |
4,171 | snowplow/iglu-ruby-client | lib/iglu-client/resolver.rb | Iglu.Resolver.validate | def validate(json)
schema_key = Resolver.get_schema_key json
data = Resolver.get_data json
schema = lookup_schema schema_key
JSON::Validator.validate!(schema, data)
end | ruby | def validate(json)
schema_key = Resolver.get_schema_key json
data = Resolver.get_data json
schema = lookup_schema schema_key
JSON::Validator.validate!(schema, data)
end | [
"def",
"validate",
"(",
"json",
")",
"schema_key",
"=",
"Resolver",
".",
"get_schema_key",
"json",
"data",
"=",
"Resolver",
".",
"get_data",
"json",
"schema",
"=",
"lookup_schema",
"schema_key",
"JSON",
"::",
"Validator",
".",
"validate!",
"(",
"schema",
",",
"data",
")",
"end"
] | Return true or throw exception | [
"Return",
"true",
"or",
"throw",
"exception"
] | 6d41668dc3e5615e3358a952e193812b5c4b3d6b | https://github.com/snowplow/iglu-ruby-client/blob/6d41668dc3e5615e3358a952e193812b5c4b3d6b/lib/iglu-client/resolver.rb#L119-L124 |
4,172 | code-and-effect/effective_pages | app/models/effective/menu_item.rb | Effective.MenuItem.visible_for? | def visible_for?(user)
can_view_page = (
if dropdown?
true
elsif menuable.kind_of?(Effective::Page)
menuable.roles_permit?(user)
else
true
end
)
can_view_menu_item = (
if roles_mask == nil
true
elsif roles_mask == -1 # Am I logged out?
user.blank?
elsif roles_mask == 0 # Am I logged in?
user.present?
else
roles_permit?(user)
end
)
can_view_page && can_view_menu_item
end | ruby | def visible_for?(user)
can_view_page = (
if dropdown?
true
elsif menuable.kind_of?(Effective::Page)
menuable.roles_permit?(user)
else
true
end
)
can_view_menu_item = (
if roles_mask == nil
true
elsif roles_mask == -1 # Am I logged out?
user.blank?
elsif roles_mask == 0 # Am I logged in?
user.present?
else
roles_permit?(user)
end
)
can_view_page && can_view_menu_item
end | [
"def",
"visible_for?",
"(",
"user",
")",
"can_view_page",
"=",
"(",
"if",
"dropdown?",
"true",
"elsif",
"menuable",
".",
"kind_of?",
"(",
"Effective",
"::",
"Page",
")",
"menuable",
".",
"roles_permit?",
"(",
"user",
")",
"else",
"true",
"end",
")",
"can_view_menu_item",
"=",
"(",
"if",
"roles_mask",
"==",
"nil",
"true",
"elsif",
"roles_mask",
"==",
"-",
"1",
"# Am I logged out?",
"user",
".",
"blank?",
"elsif",
"roles_mask",
"==",
"0",
"# Am I logged in?",
"user",
".",
"present?",
"else",
"roles_permit?",
"(",
"user",
")",
"end",
")",
"can_view_page",
"&&",
"can_view_menu_item",
"end"
] | For now it's just logged in or not?
This will work with effective_roles one day... | [
"For",
"now",
"it",
"s",
"just",
"logged",
"in",
"or",
"not?",
"This",
"will",
"work",
"with",
"effective_roles",
"one",
"day",
"..."
] | ff00e2d76055985ab65f570747bc9a5f2748f817 | https://github.com/code-and-effect/effective_pages/blob/ff00e2d76055985ab65f570747bc9a5f2748f817/app/models/effective/menu_item.rb#L51-L75 |
4,173 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.copy | def copy(dir, options = {})
# Make sure all objects are persisted.
sync
# Create a new store with the specified directory and options.
new_db = Store.new(dir, options)
# Clear the cache.
new_db.sync
# Copy all objects of the existing store to the new store.
i = 0
each do |ref_obj|
obj = ref_obj._referenced_object
obj._transfer(new_db)
obj._sync
i += 1
end
PEROBS.log.debug "Copied #{i} objects into new database at #{dir}"
# Flush the new store and close it.
new_db.exit
true
end | ruby | def copy(dir, options = {})
# Make sure all objects are persisted.
sync
# Create a new store with the specified directory and options.
new_db = Store.new(dir, options)
# Clear the cache.
new_db.sync
# Copy all objects of the existing store to the new store.
i = 0
each do |ref_obj|
obj = ref_obj._referenced_object
obj._transfer(new_db)
obj._sync
i += 1
end
PEROBS.log.debug "Copied #{i} objects into new database at #{dir}"
# Flush the new store and close it.
new_db.exit
true
end | [
"def",
"copy",
"(",
"dir",
",",
"options",
"=",
"{",
"}",
")",
"# Make sure all objects are persisted.",
"sync",
"# Create a new store with the specified directory and options.",
"new_db",
"=",
"Store",
".",
"new",
"(",
"dir",
",",
"options",
")",
"# Clear the cache.",
"new_db",
".",
"sync",
"# Copy all objects of the existing store to the new store.",
"i",
"=",
"0",
"each",
"do",
"|",
"ref_obj",
"|",
"obj",
"=",
"ref_obj",
".",
"_referenced_object",
"obj",
".",
"_transfer",
"(",
"new_db",
")",
"obj",
".",
"_sync",
"i",
"+=",
"1",
"end",
"PEROBS",
".",
"log",
".",
"debug",
"\"Copied #{i} objects into new database at #{dir}\"",
"# Flush the new store and close it.",
"new_db",
".",
"exit",
"true",
"end"
] | Create a new Store.
@param data_base [String] the name of the database
@param options [Hash] various options to affect the operation of the
database. Currently the following options are supported:
:engine : The class that provides the back-end storage
engine. By default FlatFileDB is used. A user
can provide it's own storage engine that must
conform to the same API exposed by FlatFileDB.
:cache_bits : the number of bits used for cache indexing. The
cache will hold 2 to the power of bits number of
objects. We have separate caches for reading and
writing. The default value is 16. It probably makes
little sense to use much larger numbers than that.
:serializer : select the format used to serialize the data. There
are 3 different options:
:marshal : Native Ruby serializer. Fastest option
that can handle most Ruby data types. Big
disadvantate is the stability of the format. Data
written with one Ruby version may not be readable
with another version.
:json : About half as fast as marshal, but the
format is rock solid and portable between
languages. It only supports basic Ruby data types
like String, Integer, Float, Array, Hash. This is
the default option.
:yaml : Can also handle most Ruby data types and is
portable between Ruby versions (1.9 and later).
Unfortunately, it is 10x slower than marshal.
:progressmeter : reference to a ProgressMeter object that receives
progress information during longer running tasks.
It defaults to ProgressMeter which only logs into
the log. Use ConsoleProgressMeter or a derived
class for more fancy progress reporting.
Copy the store content into a new Store. The arguments are identical to
Store.new().
@param options [Hash] various options to affect the operation of the | [
"Create",
"a",
"new",
"Store",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L183-L204 |
4,174 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.exit | def exit
if @cache && @cache.in_transaction?
@cache.abort_transaction
@cache.flush
@db.close if @db
PEROBS.log.fatal "You cannot call exit() during a transaction: #{Kernel.caller}"
end
@cache.flush if @cache
@db.close if @db
@db = @class_map = @in_memory_objects = @stats = @cache = @root_objects =
nil
end | ruby | def exit
if @cache && @cache.in_transaction?
@cache.abort_transaction
@cache.flush
@db.close if @db
PEROBS.log.fatal "You cannot call exit() during a transaction: #{Kernel.caller}"
end
@cache.flush if @cache
@db.close if @db
@db = @class_map = @in_memory_objects = @stats = @cache = @root_objects =
nil
end | [
"def",
"exit",
"if",
"@cache",
"&&",
"@cache",
".",
"in_transaction?",
"@cache",
".",
"abort_transaction",
"@cache",
".",
"flush",
"@db",
".",
"close",
"if",
"@db",
"PEROBS",
".",
"log",
".",
"fatal",
"\"You cannot call exit() during a transaction: #{Kernel.caller}\"",
"end",
"@cache",
".",
"flush",
"if",
"@cache",
"@db",
".",
"close",
"if",
"@db",
"@db",
"=",
"@class_map",
"=",
"@in_memory_objects",
"=",
"@stats",
"=",
"@cache",
"=",
"@root_objects",
"=",
"nil",
"end"
] | Close the store and ensure that all in-memory objects are written out to
the storage backend. The Store object is no longer usable after this
method was called. | [
"Close",
"the",
"store",
"and",
"ensure",
"that",
"all",
"in",
"-",
"memory",
"objects",
"are",
"written",
"out",
"to",
"the",
"storage",
"backend",
".",
"The",
"Store",
"object",
"is",
"no",
"longer",
"usable",
"after",
"this",
"method",
"was",
"called",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L210-L221 |
4,175 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.new | def new(klass, *args)
unless klass.is_a?(BasicObject)
PEROBS.log.fatal "#{klass} is not a BasicObject derivative"
end
obj = _construct_po(klass, _new_id, *args)
# Mark the new object as modified so it gets pushed into the database.
@cache.cache_write(obj)
# Return a POXReference proxy for the newly created object.
obj.myself
end | ruby | def new(klass, *args)
unless klass.is_a?(BasicObject)
PEROBS.log.fatal "#{klass} is not a BasicObject derivative"
end
obj = _construct_po(klass, _new_id, *args)
# Mark the new object as modified so it gets pushed into the database.
@cache.cache_write(obj)
# Return a POXReference proxy for the newly created object.
obj.myself
end | [
"def",
"new",
"(",
"klass",
",",
"*",
"args",
")",
"unless",
"klass",
".",
"is_a?",
"(",
"BasicObject",
")",
"PEROBS",
".",
"log",
".",
"fatal",
"\"#{klass} is not a BasicObject derivative\"",
"end",
"obj",
"=",
"_construct_po",
"(",
"klass",
",",
"_new_id",
",",
"args",
")",
"# Mark the new object as modified so it gets pushed into the database.",
"@cache",
".",
"cache_write",
"(",
"obj",
")",
"# Return a POXReference proxy for the newly created object.",
"obj",
".",
"myself",
"end"
] | You need to call this method to create new PEROBS objects that belong to
this Store.
@param klass [Class] The class of the object you want to create. This
must be a derivative of ObjectBase.
@param args Optional list of other arguments that are passed to the
constructor of the specified class.
@return [POXReference] A reference to the newly created object. | [
"You",
"need",
"to",
"call",
"this",
"method",
"to",
"create",
"new",
"PEROBS",
"objects",
"that",
"belong",
"to",
"this",
"Store",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L231-L241 |
4,176 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store._construct_po | def _construct_po(klass, id, *args)
klass.new(Handle.new(self, id), *args)
end | ruby | def _construct_po(klass, id, *args)
klass.new(Handle.new(self, id), *args)
end | [
"def",
"_construct_po",
"(",
"klass",
",",
"id",
",",
"*",
"args",
")",
"klass",
".",
"new",
"(",
"Handle",
".",
"new",
"(",
"self",
",",
"id",
")",
",",
"args",
")",
"end"
] | For library internal use only!
This method will create a new PEROBS object.
@param klass [BasicObject] Class of the object to create
@param id [Integer] Requested object ID
@param args [Array] Arguments to pass to the object constructor.
@return [BasicObject] Newly constructed PEROBS object | [
"For",
"library",
"internal",
"use",
"only!",
"This",
"method",
"will",
"create",
"a",
"new",
"PEROBS",
"object",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L249-L251 |
4,177 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.sync | def sync
if @cache.in_transaction?
@cache.abort_transaction
@cache.flush
PEROBS.log.fatal "You cannot call sync() during a transaction: \n" +
Kernel.caller.join("\n")
end
@cache.flush
end | ruby | def sync
if @cache.in_transaction?
@cache.abort_transaction
@cache.flush
PEROBS.log.fatal "You cannot call sync() during a transaction: \n" +
Kernel.caller.join("\n")
end
@cache.flush
end | [
"def",
"sync",
"if",
"@cache",
".",
"in_transaction?",
"@cache",
".",
"abort_transaction",
"@cache",
".",
"flush",
"PEROBS",
".",
"log",
".",
"fatal",
"\"You cannot call sync() during a transaction: \\n\"",
"+",
"Kernel",
".",
"caller",
".",
"join",
"(",
"\"\\n\"",
")",
"end",
"@cache",
".",
"flush",
"end"
] | Flush out all modified objects to disk and shrink the in-memory list if
needed. | [
"Flush",
"out",
"all",
"modified",
"objects",
"to",
"disk",
"and",
"shrink",
"the",
"in",
"-",
"memory",
"list",
"if",
"needed",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L313-L321 |
4,178 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.object_by_id | def object_by_id(id)
if (ruby_object_id = @in_memory_objects[id])
# We have the object in memory so we can just return it.
begin
object = ObjectSpace._id2ref(ruby_object_id)
# Let's make sure the object is really the object we are looking
# for. The GC might have recycled it already and the Ruby object ID
# could now be used for another object.
if object.is_a?(ObjectBase) && object._id == id
return object
end
rescue RangeError => e
# Due to a race condition the object can still be in the
# @in_memory_objects list but has been collected already by the Ruby
# GC. In that case we need to load it again. In this case the
# _collect() call will happen much later, potentially after we have
# registered a new object with the same ID.
@in_memory_objects.delete(id)
end
end
if (obj = @cache.object_by_id(id))
PEROBS.log.fatal "Object #{id} with Ruby #{obj.object_id} is in cache but not in_memory"
end
# We don't have the object in memory. Let's find it in the storage.
if @db.include?(id)
# Great, object found. Read it into memory and return it.
obj = ObjectBase::read(self, id)
# Add the object to the in-memory storage list.
@cache.cache_read(obj)
return obj
end
# The requested object does not exist. Return nil.
nil
end | ruby | def object_by_id(id)
if (ruby_object_id = @in_memory_objects[id])
# We have the object in memory so we can just return it.
begin
object = ObjectSpace._id2ref(ruby_object_id)
# Let's make sure the object is really the object we are looking
# for. The GC might have recycled it already and the Ruby object ID
# could now be used for another object.
if object.is_a?(ObjectBase) && object._id == id
return object
end
rescue RangeError => e
# Due to a race condition the object can still be in the
# @in_memory_objects list but has been collected already by the Ruby
# GC. In that case we need to load it again. In this case the
# _collect() call will happen much later, potentially after we have
# registered a new object with the same ID.
@in_memory_objects.delete(id)
end
end
if (obj = @cache.object_by_id(id))
PEROBS.log.fatal "Object #{id} with Ruby #{obj.object_id} is in cache but not in_memory"
end
# We don't have the object in memory. Let's find it in the storage.
if @db.include?(id)
# Great, object found. Read it into memory and return it.
obj = ObjectBase::read(self, id)
# Add the object to the in-memory storage list.
@cache.cache_read(obj)
return obj
end
# The requested object does not exist. Return nil.
nil
end | [
"def",
"object_by_id",
"(",
"id",
")",
"if",
"(",
"ruby_object_id",
"=",
"@in_memory_objects",
"[",
"id",
"]",
")",
"# We have the object in memory so we can just return it.",
"begin",
"object",
"=",
"ObjectSpace",
".",
"_id2ref",
"(",
"ruby_object_id",
")",
"# Let's make sure the object is really the object we are looking",
"# for. The GC might have recycled it already and the Ruby object ID",
"# could now be used for another object.",
"if",
"object",
".",
"is_a?",
"(",
"ObjectBase",
")",
"&&",
"object",
".",
"_id",
"==",
"id",
"return",
"object",
"end",
"rescue",
"RangeError",
"=>",
"e",
"# Due to a race condition the object can still be in the",
"# @in_memory_objects list but has been collected already by the Ruby",
"# GC. In that case we need to load it again. In this case the",
"# _collect() call will happen much later, potentially after we have",
"# registered a new object with the same ID.",
"@in_memory_objects",
".",
"delete",
"(",
"id",
")",
"end",
"end",
"if",
"(",
"obj",
"=",
"@cache",
".",
"object_by_id",
"(",
"id",
")",
")",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Object #{id} with Ruby #{obj.object_id} is in cache but not in_memory\"",
"end",
"# We don't have the object in memory. Let's find it in the storage.",
"if",
"@db",
".",
"include?",
"(",
"id",
")",
"# Great, object found. Read it into memory and return it.",
"obj",
"=",
"ObjectBase",
"::",
"read",
"(",
"self",
",",
"id",
")",
"# Add the object to the in-memory storage list.",
"@cache",
".",
"cache_read",
"(",
"obj",
")",
"return",
"obj",
"end",
"# The requested object does not exist. Return nil.",
"nil",
"end"
] | Return the object with the provided ID. This method is not part of the
public API and should never be called by outside users. It's purely
intended for internal use. | [
"Return",
"the",
"object",
"with",
"the",
"provided",
"ID",
".",
"This",
"method",
"is",
"not",
"part",
"of",
"the",
"public",
"API",
"and",
"should",
"never",
"be",
"called",
"by",
"outside",
"users",
".",
"It",
"s",
"purely",
"intended",
"for",
"internal",
"use",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L347-L384 |
4,179 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.check | def check(repair = false)
stats = { :errors => 0, :object_cnt => 0 }
# All objects must have in-db version.
sync
# Run basic consistency checks first.
stats[:errors] += @db.check_db(repair)
# We will use the mark to mark all objects that we have checked already.
# Before we start, we need to clear all marks.
@db.clear_marks
@progressmeter.start("Checking object link structure",
@db.item_counter) do
@root_objects.each do |name, id|
check_object(id, repair, stats)
end
end
# Delete all broken root objects.
if repair
@root_objects.delete_if do |name, id|
unless @db.check(id, repair)
PEROBS.log.error "Discarding broken root object '#{name}' " +
"with ID #{id}"
stats[:errors] += 1
end
end
end
if stats[:errors] > 0
if repair
PEROBS.log.error "#{stats[:errors]} errors found in " +
"#{stats[:object_cnt]} objects"
else
PEROBS.log.fatal "#{stats[:errors]} errors found in " +
"#{stats[:object_cnt]} objects"
end
else
PEROBS.log.debug "No errors found"
end
# Ensure that any fixes are written into the DB.
sync if repair
stats[:errors]
end | ruby | def check(repair = false)
stats = { :errors => 0, :object_cnt => 0 }
# All objects must have in-db version.
sync
# Run basic consistency checks first.
stats[:errors] += @db.check_db(repair)
# We will use the mark to mark all objects that we have checked already.
# Before we start, we need to clear all marks.
@db.clear_marks
@progressmeter.start("Checking object link structure",
@db.item_counter) do
@root_objects.each do |name, id|
check_object(id, repair, stats)
end
end
# Delete all broken root objects.
if repair
@root_objects.delete_if do |name, id|
unless @db.check(id, repair)
PEROBS.log.error "Discarding broken root object '#{name}' " +
"with ID #{id}"
stats[:errors] += 1
end
end
end
if stats[:errors] > 0
if repair
PEROBS.log.error "#{stats[:errors]} errors found in " +
"#{stats[:object_cnt]} objects"
else
PEROBS.log.fatal "#{stats[:errors]} errors found in " +
"#{stats[:object_cnt]} objects"
end
else
PEROBS.log.debug "No errors found"
end
# Ensure that any fixes are written into the DB.
sync if repair
stats[:errors]
end | [
"def",
"check",
"(",
"repair",
"=",
"false",
")",
"stats",
"=",
"{",
":errors",
"=>",
"0",
",",
":object_cnt",
"=>",
"0",
"}",
"# All objects must have in-db version.",
"sync",
"# Run basic consistency checks first.",
"stats",
"[",
":errors",
"]",
"+=",
"@db",
".",
"check_db",
"(",
"repair",
")",
"# We will use the mark to mark all objects that we have checked already.",
"# Before we start, we need to clear all marks.",
"@db",
".",
"clear_marks",
"@progressmeter",
".",
"start",
"(",
"\"Checking object link structure\"",
",",
"@db",
".",
"item_counter",
")",
"do",
"@root_objects",
".",
"each",
"do",
"|",
"name",
",",
"id",
"|",
"check_object",
"(",
"id",
",",
"repair",
",",
"stats",
")",
"end",
"end",
"# Delete all broken root objects.",
"if",
"repair",
"@root_objects",
".",
"delete_if",
"do",
"|",
"name",
",",
"id",
"|",
"unless",
"@db",
".",
"check",
"(",
"id",
",",
"repair",
")",
"PEROBS",
".",
"log",
".",
"error",
"\"Discarding broken root object '#{name}' \"",
"+",
"\"with ID #{id}\"",
"stats",
"[",
":errors",
"]",
"+=",
"1",
"end",
"end",
"end",
"if",
"stats",
"[",
":errors",
"]",
">",
"0",
"if",
"repair",
"PEROBS",
".",
"log",
".",
"error",
"\"#{stats[:errors]} errors found in \"",
"+",
"\"#{stats[:object_cnt]} objects\"",
"else",
"PEROBS",
".",
"log",
".",
"fatal",
"\"#{stats[:errors]} errors found in \"",
"+",
"\"#{stats[:object_cnt]} objects\"",
"end",
"else",
"PEROBS",
".",
"log",
".",
"debug",
"\"No errors found\"",
"end",
"# Ensure that any fixes are written into the DB.",
"sync",
"if",
"repair",
"stats",
"[",
":errors",
"]",
"end"
] | This method can be used to check the database and optionally repair it.
The repair is a pure structural repair. It cannot ensure that the stored
data is still correct. E. g. if a reference to a non-existing or
unreadable object is found, the reference will simply be deleted.
@param repair [TrueClass/FalseClass] true if a repair attempt should be
made.
@return [Integer] The number of references to bad objects found. | [
"This",
"method",
"can",
"be",
"used",
"to",
"check",
"the",
"database",
"and",
"optionally",
"repair",
"it",
".",
"The",
"repair",
"is",
"a",
"pure",
"structural",
"repair",
".",
"It",
"cannot",
"ensure",
"that",
"the",
"stored",
"data",
"is",
"still",
"correct",
".",
"E",
".",
"g",
".",
"if",
"a",
"reference",
"to",
"a",
"non",
"-",
"existing",
"or",
"unreadable",
"object",
"is",
"found",
"the",
"reference",
"will",
"simply",
"be",
"deleted",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L393-L439 |
4,180 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.each | def each
@db.clear_marks
# Start with the object 0 and the indexes of the root objects. Push them
# onto the work stack.
stack = [ 0 ] + @root_objects.values
while !stack.empty?
# Get an object index from the stack.
id = stack.pop
next if @db.is_marked?(id)
unless (obj = object_by_id(id))
PEROBS.log.fatal "Database is corrupted. Object with ID #{id} " +
"not found."
end
# Mark the object so it will never be pushed to the stack again.
@db.mark(id)
yield(obj.myself) if block_given?
# Push the IDs of all unmarked referenced objects onto the stack
obj._referenced_object_ids.each do |r_id|
stack << r_id unless @db.is_marked?(r_id)
end
end
end | ruby | def each
@db.clear_marks
# Start with the object 0 and the indexes of the root objects. Push them
# onto the work stack.
stack = [ 0 ] + @root_objects.values
while !stack.empty?
# Get an object index from the stack.
id = stack.pop
next if @db.is_marked?(id)
unless (obj = object_by_id(id))
PEROBS.log.fatal "Database is corrupted. Object with ID #{id} " +
"not found."
end
# Mark the object so it will never be pushed to the stack again.
@db.mark(id)
yield(obj.myself) if block_given?
# Push the IDs of all unmarked referenced objects onto the stack
obj._referenced_object_ids.each do |r_id|
stack << r_id unless @db.is_marked?(r_id)
end
end
end | [
"def",
"each",
"@db",
".",
"clear_marks",
"# Start with the object 0 and the indexes of the root objects. Push them",
"# onto the work stack.",
"stack",
"=",
"[",
"0",
"]",
"+",
"@root_objects",
".",
"values",
"while",
"!",
"stack",
".",
"empty?",
"# Get an object index from the stack.",
"id",
"=",
"stack",
".",
"pop",
"next",
"if",
"@db",
".",
"is_marked?",
"(",
"id",
")",
"unless",
"(",
"obj",
"=",
"object_by_id",
"(",
"id",
")",
")",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Database is corrupted. Object with ID #{id} \"",
"+",
"\"not found.\"",
"end",
"# Mark the object so it will never be pushed to the stack again.",
"@db",
".",
"mark",
"(",
"id",
")",
"yield",
"(",
"obj",
".",
"myself",
")",
"if",
"block_given?",
"# Push the IDs of all unmarked referenced objects onto the stack",
"obj",
".",
"_referenced_object_ids",
".",
"each",
"do",
"|",
"r_id",
"|",
"stack",
"<<",
"r_id",
"unless",
"@db",
".",
"is_marked?",
"(",
"r_id",
")",
"end",
"end",
"end"
] | Calls the given block once for each object, passing that object as a
parameter. | [
"Calls",
"the",
"given",
"block",
"once",
"for",
"each",
"object",
"passing",
"that",
"object",
"as",
"a",
"parameter",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L460-L482 |
4,181 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.mark | def mark
classes = Set.new
marked_objects = 0
@progressmeter.start("Marking linked objects", @db.item_counter) do
each do |obj|
classes.add(obj.class)
@progressmeter.update(marked_objects += 1)
end
end
@class_map.keep(classes.map { |c| c.to_s })
# The root_objects object is included in the count, but we only want to
# count user objects here.
PEROBS.log.debug "#{marked_objects - 1} of #{@db.item_counter} " +
"objects marked"
@stats.marked_objects = marked_objects - 1
end | ruby | def mark
classes = Set.new
marked_objects = 0
@progressmeter.start("Marking linked objects", @db.item_counter) do
each do |obj|
classes.add(obj.class)
@progressmeter.update(marked_objects += 1)
end
end
@class_map.keep(classes.map { |c| c.to_s })
# The root_objects object is included in the count, but we only want to
# count user objects here.
PEROBS.log.debug "#{marked_objects - 1} of #{@db.item_counter} " +
"objects marked"
@stats.marked_objects = marked_objects - 1
end | [
"def",
"mark",
"classes",
"=",
"Set",
".",
"new",
"marked_objects",
"=",
"0",
"@progressmeter",
".",
"start",
"(",
"\"Marking linked objects\"",
",",
"@db",
".",
"item_counter",
")",
"do",
"each",
"do",
"|",
"obj",
"|",
"classes",
".",
"add",
"(",
"obj",
".",
"class",
")",
"@progressmeter",
".",
"update",
"(",
"marked_objects",
"+=",
"1",
")",
"end",
"end",
"@class_map",
".",
"keep",
"(",
"classes",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"to_s",
"}",
")",
"# The root_objects object is included in the count, but we only want to",
"# count user objects here.",
"PEROBS",
".",
"log",
".",
"debug",
"\"#{marked_objects - 1} of #{@db.item_counter} \"",
"+",
"\"objects marked\"",
"@stats",
".",
"marked_objects",
"=",
"marked_objects",
"-",
"1",
"end"
] | Mark phase of a mark-and-sweep garbage collector. It will mark all
objects that are reachable from the root objects. | [
"Mark",
"phase",
"of",
"a",
"mark",
"-",
"and",
"-",
"sweep",
"garbage",
"collector",
".",
"It",
"will",
"mark",
"all",
"objects",
"that",
"are",
"reachable",
"from",
"the",
"root",
"objects",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L538-L554 |
4,182 | scrapper/perobs | lib/perobs/Store.rb | PEROBS.Store.check_object | def check_object(start_id, repair, stats)
@db.mark(start_id)
# The todo list holds a touple for each object that still needs to be
# checked. The first item is the referring object and the second is the
# ID of the object to check.
todo_list = [ [ nil, start_id ] ]
while !todo_list.empty?
# Get the next PEROBS object to check
ref_obj, id = todo_list.pop
begin
obj = object_by_id(id)
rescue PEROBS::FatalError
obj = nil
end
if obj
# The object exists and is OK. Mark is as checked.
@db.mark(id)
# Now look at all other objects referenced by this object.
obj._referenced_object_ids.each do |refd_id|
# Push them onto the todo list unless they have been marked
# already.
todo_list << [ obj, refd_id ] unless @db.is_marked?(refd_id, true)
end
else
# Remove references to bad objects.
if ref_obj
if repair
PEROBS.log.error "Removing reference to " +
"#{obj ? 'broken' : 'non-existing'} object #{id} from:\n" +
ref_obj.inspect
ref_obj._delete_reference_to_id(id)
else
PEROBS.log.error "The following object references a " +
"#{obj ? 'broken' : 'non-existing'} object #{id}:\n" +
ref_obj.inspect
end
end
stats[:errors] += 1
end
@progressmeter.update(stats[:object_cnt] += 1)
end
end | ruby | def check_object(start_id, repair, stats)
@db.mark(start_id)
# The todo list holds a touple for each object that still needs to be
# checked. The first item is the referring object and the second is the
# ID of the object to check.
todo_list = [ [ nil, start_id ] ]
while !todo_list.empty?
# Get the next PEROBS object to check
ref_obj, id = todo_list.pop
begin
obj = object_by_id(id)
rescue PEROBS::FatalError
obj = nil
end
if obj
# The object exists and is OK. Mark is as checked.
@db.mark(id)
# Now look at all other objects referenced by this object.
obj._referenced_object_ids.each do |refd_id|
# Push them onto the todo list unless they have been marked
# already.
todo_list << [ obj, refd_id ] unless @db.is_marked?(refd_id, true)
end
else
# Remove references to bad objects.
if ref_obj
if repair
PEROBS.log.error "Removing reference to " +
"#{obj ? 'broken' : 'non-existing'} object #{id} from:\n" +
ref_obj.inspect
ref_obj._delete_reference_to_id(id)
else
PEROBS.log.error "The following object references a " +
"#{obj ? 'broken' : 'non-existing'} object #{id}:\n" +
ref_obj.inspect
end
end
stats[:errors] += 1
end
@progressmeter.update(stats[:object_cnt] += 1)
end
end | [
"def",
"check_object",
"(",
"start_id",
",",
"repair",
",",
"stats",
")",
"@db",
".",
"mark",
"(",
"start_id",
")",
"# The todo list holds a touple for each object that still needs to be",
"# checked. The first item is the referring object and the second is the",
"# ID of the object to check.",
"todo_list",
"=",
"[",
"[",
"nil",
",",
"start_id",
"]",
"]",
"while",
"!",
"todo_list",
".",
"empty?",
"# Get the next PEROBS object to check",
"ref_obj",
",",
"id",
"=",
"todo_list",
".",
"pop",
"begin",
"obj",
"=",
"object_by_id",
"(",
"id",
")",
"rescue",
"PEROBS",
"::",
"FatalError",
"obj",
"=",
"nil",
"end",
"if",
"obj",
"# The object exists and is OK. Mark is as checked.",
"@db",
".",
"mark",
"(",
"id",
")",
"# Now look at all other objects referenced by this object.",
"obj",
".",
"_referenced_object_ids",
".",
"each",
"do",
"|",
"refd_id",
"|",
"# Push them onto the todo list unless they have been marked",
"# already.",
"todo_list",
"<<",
"[",
"obj",
",",
"refd_id",
"]",
"unless",
"@db",
".",
"is_marked?",
"(",
"refd_id",
",",
"true",
")",
"end",
"else",
"# Remove references to bad objects.",
"if",
"ref_obj",
"if",
"repair",
"PEROBS",
".",
"log",
".",
"error",
"\"Removing reference to \"",
"+",
"\"#{obj ? 'broken' : 'non-existing'} object #{id} from:\\n\"",
"+",
"ref_obj",
".",
"inspect",
"ref_obj",
".",
"_delete_reference_to_id",
"(",
"id",
")",
"else",
"PEROBS",
".",
"log",
".",
"error",
"\"The following object references a \"",
"+",
"\"#{obj ? 'broken' : 'non-existing'} object #{id}:\\n\"",
"+",
"ref_obj",
".",
"inspect",
"end",
"end",
"stats",
"[",
":errors",
"]",
"+=",
"1",
"end",
"@progressmeter",
".",
"update",
"(",
"stats",
"[",
":object_cnt",
"]",
"+=",
"1",
")",
"end",
"end"
] | Check the object with the given start_id and all other objects that are
somehow reachable from the start object.
@param start_id [Integer] ID of the top-level object to start
with
@param repair [Boolean] Delete refernces to broken objects if true
@return [Integer] The number of references to bad objects. | [
"Check",
"the",
"object",
"with",
"the",
"given",
"start_id",
"and",
"all",
"other",
"objects",
"that",
"are",
"somehow",
"reachable",
"from",
"the",
"start",
"object",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Store.rb#L571-L616 |
4,183 | scrapper/perobs | lib/perobs/Object.rb | PEROBS.Object._referenced_object_ids | def _referenced_object_ids
ids = []
_all_attributes.each do |attr|
value = instance_variable_get(('@' + attr.to_s).to_sym)
ids << value.id if value && value.respond_to?(:is_poxreference?)
end
ids
end | ruby | def _referenced_object_ids
ids = []
_all_attributes.each do |attr|
value = instance_variable_get(('@' + attr.to_s).to_sym)
ids << value.id if value && value.respond_to?(:is_poxreference?)
end
ids
end | [
"def",
"_referenced_object_ids",
"ids",
"=",
"[",
"]",
"_all_attributes",
".",
"each",
"do",
"|",
"attr",
"|",
"value",
"=",
"instance_variable_get",
"(",
"(",
"'@'",
"+",
"attr",
".",
"to_s",
")",
".",
"to_sym",
")",
"ids",
"<<",
"value",
".",
"id",
"if",
"value",
"&&",
"value",
".",
"respond_to?",
"(",
":is_poxreference?",
")",
"end",
"ids",
"end"
] | Return a list of all object IDs that the attributes of this instance are
referencing.
@return [Array of Integer] IDs of referenced objects | [
"Return",
"a",
"list",
"of",
"all",
"object",
"IDs",
"that",
"the",
"attributes",
"of",
"this",
"instance",
"are",
"referencing",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Object.rb#L149-L156 |
4,184 | scrapper/perobs | lib/perobs/Object.rb | PEROBS.Object._delete_reference_to_id | def _delete_reference_to_id(id)
_all_attributes.each do |attr|
ivar = ('@' + attr.to_s).to_sym
value = instance_variable_get(ivar)
if value && value.respond_to?(:is_poxreference?) && value.id == id
instance_variable_set(ivar, nil)
end
end
mark_as_modified
end | ruby | def _delete_reference_to_id(id)
_all_attributes.each do |attr|
ivar = ('@' + attr.to_s).to_sym
value = instance_variable_get(ivar)
if value && value.respond_to?(:is_poxreference?) && value.id == id
instance_variable_set(ivar, nil)
end
end
mark_as_modified
end | [
"def",
"_delete_reference_to_id",
"(",
"id",
")",
"_all_attributes",
".",
"each",
"do",
"|",
"attr",
"|",
"ivar",
"=",
"(",
"'@'",
"+",
"attr",
".",
"to_s",
")",
".",
"to_sym",
"value",
"=",
"instance_variable_get",
"(",
"ivar",
")",
"if",
"value",
"&&",
"value",
".",
"respond_to?",
"(",
":is_poxreference?",
")",
"&&",
"value",
".",
"id",
"==",
"id",
"instance_variable_set",
"(",
"ivar",
",",
"nil",
")",
"end",
"end",
"mark_as_modified",
"end"
] | This method should only be used during store repair operations. It will
delete all references to the given object ID.
@param id [Integer] targeted object ID | [
"This",
"method",
"should",
"only",
"be",
"used",
"during",
"store",
"repair",
"operations",
".",
"It",
"will",
"delete",
"all",
"references",
"to",
"the",
"given",
"object",
"ID",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Object.rb#L161-L170 |
4,185 | scrapper/perobs | lib/perobs/Object.rb | PEROBS.Object.inspect | def inspect
"<#{self.class}:#{@_id}>\n{\n" +
_all_attributes.map do |attr|
ivar = ('@' + attr.to_s).to_sym
if (value = instance_variable_get(ivar)).respond_to?(:is_poxreference?)
" #{attr} => <PEROBS::ObjectBase:#{value._id}>"
else
" #{attr} => #{value.inspect}"
end
end.join(",\n") +
"\n}\n"
end | ruby | def inspect
"<#{self.class}:#{@_id}>\n{\n" +
_all_attributes.map do |attr|
ivar = ('@' + attr.to_s).to_sym
if (value = instance_variable_get(ivar)).respond_to?(:is_poxreference?)
" #{attr} => <PEROBS::ObjectBase:#{value._id}>"
else
" #{attr} => #{value.inspect}"
end
end.join(",\n") +
"\n}\n"
end | [
"def",
"inspect",
"\"<#{self.class}:#{@_id}>\\n{\\n\"",
"+",
"_all_attributes",
".",
"map",
"do",
"|",
"attr",
"|",
"ivar",
"=",
"(",
"'@'",
"+",
"attr",
".",
"to_s",
")",
".",
"to_sym",
"if",
"(",
"value",
"=",
"instance_variable_get",
"(",
"ivar",
")",
")",
".",
"respond_to?",
"(",
":is_poxreference?",
")",
"\" #{attr} => <PEROBS::ObjectBase:#{value._id}>\"",
"else",
"\" #{attr} => #{value.inspect}\"",
"end",
"end",
".",
"join",
"(",
"\",\\n\"",
")",
"+",
"\"\\n}\\n\"",
"end"
] | Textual dump for debugging purposes
@return [String] | [
"Textual",
"dump",
"for",
"debugging",
"purposes"
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Object.rb#L186-L197 |
4,186 | scrapper/perobs | lib/perobs/Object.rb | PEROBS.Object._serialize | def _serialize
attributes = {}
_all_attributes.each do |attr|
ivar = ('@' + attr.to_s).to_sym
value = instance_variable_get(ivar)
attributes[attr.to_s] = value.respond_to?(:is_poxreference?) ?
POReference.new(value.id) : value
end
attributes
end | ruby | def _serialize
attributes = {}
_all_attributes.each do |attr|
ivar = ('@' + attr.to_s).to_sym
value = instance_variable_get(ivar)
attributes[attr.to_s] = value.respond_to?(:is_poxreference?) ?
POReference.new(value.id) : value
end
attributes
end | [
"def",
"_serialize",
"attributes",
"=",
"{",
"}",
"_all_attributes",
".",
"each",
"do",
"|",
"attr",
"|",
"ivar",
"=",
"(",
"'@'",
"+",
"attr",
".",
"to_s",
")",
".",
"to_sym",
"value",
"=",
"instance_variable_get",
"(",
"ivar",
")",
"attributes",
"[",
"attr",
".",
"to_s",
"]",
"=",
"value",
".",
"respond_to?",
"(",
":is_poxreference?",
")",
"?",
"POReference",
".",
"new",
"(",
"value",
".",
"id",
")",
":",
"value",
"end",
"attributes",
"end"
] | Return a single data structure that holds all persistent data for this
class. | [
"Return",
"a",
"single",
"data",
"structure",
"that",
"holds",
"all",
"persistent",
"data",
"for",
"this",
"class",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/Object.rb#L203-L212 |
4,187 | danielpclark/PolyBelongsTo | lib/poly_belongs_to/singleton_set.rb | PolyBelongsTo.SingletonSet.add? | def add?(record)
result = @set.add?( formatted_name( record ) )
return result if result
flag(record)
result
end | ruby | def add?(record)
result = @set.add?( formatted_name( record ) )
return result if result
flag(record)
result
end | [
"def",
"add?",
"(",
"record",
")",
"result",
"=",
"@set",
".",
"add?",
"(",
"formatted_name",
"(",
"record",
")",
")",
"return",
"result",
"if",
"result",
"flag",
"(",
"record",
")",
"result",
"end"
] | Add record to set. Flag if covered already.
@param record [Object] ActiveRecord object instance
@return [Object, nil] Object if added safely, nil otherwise | [
"Add",
"record",
"to",
"set",
".",
"Flag",
"if",
"covered",
"already",
"."
] | 38d51d37f9148613519d6b6d56bdf4d0884f0e86 | https://github.com/danielpclark/PolyBelongsTo/blob/38d51d37f9148613519d6b6d56bdf4d0884f0e86/lib/poly_belongs_to/singleton_set.rb#L24-L29 |
4,188 | danielpclark/PolyBelongsTo | lib/poly_belongs_to/singleton_set.rb | PolyBelongsTo.SingletonSet.method_missing | def method_missing(mthd, *args, &block)
new_recs = args.reduce([]) {|a, i| a.push(formatted_name(i)) if i.class.ancestors.include?(ActiveRecord::Base); a}
result = @set.send(mthd,
*(args.map do |arg|
arg.class.ancestors.include?(ActiveRecord::Base) ? formatted_name(arg) : arg
end
),
&block
)
@set.to_a.select {|i| new_recs.include? i }.each {|f| @flagged << f}
result
end | ruby | def method_missing(mthd, *args, &block)
new_recs = args.reduce([]) {|a, i| a.push(formatted_name(i)) if i.class.ancestors.include?(ActiveRecord::Base); a}
result = @set.send(mthd,
*(args.map do |arg|
arg.class.ancestors.include?(ActiveRecord::Base) ? formatted_name(arg) : arg
end
),
&block
)
@set.to_a.select {|i| new_recs.include? i }.each {|f| @flagged << f}
result
end | [
"def",
"method_missing",
"(",
"mthd",
",",
"*",
"args",
",",
"&",
"block",
")",
"new_recs",
"=",
"args",
".",
"reduce",
"(",
"[",
"]",
")",
"{",
"|",
"a",
",",
"i",
"|",
"a",
".",
"push",
"(",
"formatted_name",
"(",
"i",
")",
")",
"if",
"i",
".",
"class",
".",
"ancestors",
".",
"include?",
"(",
"ActiveRecord",
"::",
"Base",
")",
";",
"a",
"}",
"result",
"=",
"@set",
".",
"send",
"(",
"mthd",
",",
"(",
"args",
".",
"map",
"do",
"|",
"arg",
"|",
"arg",
".",
"class",
".",
"ancestors",
".",
"include?",
"(",
"ActiveRecord",
"::",
"Base",
")",
"?",
"formatted_name",
"(",
"arg",
")",
":",
"arg",
"end",
")",
",",
"block",
")",
"@set",
".",
"to_a",
".",
"select",
"{",
"|",
"i",
"|",
"new_recs",
".",
"include?",
"i",
"}",
".",
"each",
"{",
"|",
"f",
"|",
"@flagged",
"<<",
"f",
"}",
"result",
"end"
] | method_missing will transform any record argument into a formatted string and pass the
method and arguments on to the internal Set. Also will flag any existing records covered. | [
"method_missing",
"will",
"transform",
"any",
"record",
"argument",
"into",
"a",
"formatted",
"string",
"and",
"pass",
"the",
"method",
"and",
"arguments",
"on",
"to",
"the",
"internal",
"Set",
".",
"Also",
"will",
"flag",
"any",
"existing",
"records",
"covered",
"."
] | 38d51d37f9148613519d6b6d56bdf4d0884f0e86 | https://github.com/danielpclark/PolyBelongsTo/blob/38d51d37f9148613519d6b6d56bdf4d0884f0e86/lib/poly_belongs_to/singleton_set.rb#L56-L67 |
4,189 | Absolight/epp-client | lib/epp-client/xml.rb | EPPClient.XML.get_result | def get_result(args)
xml = case args
when Hash
args.delete(:xml)
else
xml = args
args = {}
xml
end
args[:range] ||= 1000..1999
if !(mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).empty?
@msgQ_count = mq.attribute('count').value.to_i
@msgQ_id = mq.attribute('id').value
puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
else
@msgQ_count = 0
@msgQ_id = nil
end
unless (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).empty?
@trID = get_trid(trID)
end
res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL)
code = res.attribute('code').value.to_i
raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text) unless args[:range].include?(code)
return true unless args.key?(:callback)
case cb = args[:callback]
when Symbol
return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
else
raise ArgumentError, 'Invalid callback type'
end
end | ruby | def get_result(args)
xml = case args
when Hash
args.delete(:xml)
else
xml = args
args = {}
xml
end
args[:range] ||= 1000..1999
if !(mq = xml.xpath('epp:epp/epp:response/epp:msgQ', EPPClient::SCHEMAS_URL)).empty?
@msgQ_count = mq.attribute('count').value.to_i
@msgQ_id = mq.attribute('id').value
puts "DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\n" if debug
else
@msgQ_count = 0
@msgQ_id = nil
end
unless (trID = xml.xpath('epp:epp/epp:response/epp:trID', EPPClient::SCHEMAS_URL)).empty?
@trID = get_trid(trID)
end
res = xml.xpath('epp:epp/epp:response/epp:result', EPPClient::SCHEMAS_URL)
code = res.attribute('code').value.to_i
raise EPPClient::EPPErrorResponse.new(:xml => xml, :code => code, :message => res.xpath('epp:msg', EPPClient::SCHEMAS_URL).text) unless args[:range].include?(code)
return true unless args.key?(:callback)
case cb = args[:callback]
when Symbol
return send(cb, xml.xpath('epp:epp/epp:response', EPPClient::SCHEMAS_URL))
else
raise ArgumentError, 'Invalid callback type'
end
end | [
"def",
"get_result",
"(",
"args",
")",
"xml",
"=",
"case",
"args",
"when",
"Hash",
"args",
".",
"delete",
"(",
":xml",
")",
"else",
"xml",
"=",
"args",
"args",
"=",
"{",
"}",
"xml",
"end",
"args",
"[",
":range",
"]",
"||=",
"1000",
"..",
"1999",
"if",
"!",
"(",
"mq",
"=",
"xml",
".",
"xpath",
"(",
"'epp:epp/epp:response/epp:msgQ'",
",",
"EPPClient",
"::",
"SCHEMAS_URL",
")",
")",
".",
"empty?",
"@msgQ_count",
"=",
"mq",
".",
"attribute",
"(",
"'count'",
")",
".",
"value",
".",
"to_i",
"@msgQ_id",
"=",
"mq",
".",
"attribute",
"(",
"'id'",
")",
".",
"value",
"puts",
"\"DEBUG: MSGQ : count=#{@msgQ_count}, id=#{@msgQ_id}\\n\"",
"if",
"debug",
"else",
"@msgQ_count",
"=",
"0",
"@msgQ_id",
"=",
"nil",
"end",
"unless",
"(",
"trID",
"=",
"xml",
".",
"xpath",
"(",
"'epp:epp/epp:response/epp:trID'",
",",
"EPPClient",
"::",
"SCHEMAS_URL",
")",
")",
".",
"empty?",
"@trID",
"=",
"get_trid",
"(",
"trID",
")",
"end",
"res",
"=",
"xml",
".",
"xpath",
"(",
"'epp:epp/epp:response/epp:result'",
",",
"EPPClient",
"::",
"SCHEMAS_URL",
")",
"code",
"=",
"res",
".",
"attribute",
"(",
"'code'",
")",
".",
"value",
".",
"to_i",
"raise",
"EPPClient",
"::",
"EPPErrorResponse",
".",
"new",
"(",
":xml",
"=>",
"xml",
",",
":code",
"=>",
"code",
",",
":message",
"=>",
"res",
".",
"xpath",
"(",
"'epp:msg'",
",",
"EPPClient",
"::",
"SCHEMAS_URL",
")",
".",
"text",
")",
"unless",
"args",
"[",
":range",
"]",
".",
"include?",
"(",
"code",
")",
"return",
"true",
"unless",
"args",
".",
"key?",
"(",
":callback",
")",
"case",
"cb",
"=",
"args",
"[",
":callback",
"]",
"when",
"Symbol",
"return",
"send",
"(",
"cb",
",",
"xml",
".",
"xpath",
"(",
"'epp:epp/epp:response'",
",",
"EPPClient",
"::",
"SCHEMAS_URL",
")",
")",
"else",
"raise",
"ArgumentError",
",",
"'Invalid callback type'",
"end",
"end"
] | Takes a xml response and checks that the result is in the right range of
results, that is, between 1000 and 1999, which are results meaning all
went well.
In case all went well, it either calls the callback if given, or returns
true.
In case there was a problem, an EPPErrorResponse exception is raised. | [
"Takes",
"a",
"xml",
"response",
"and",
"checks",
"that",
"the",
"result",
"is",
"in",
"the",
"right",
"range",
"of",
"results",
"that",
"is",
"between",
"1000",
"and",
"1999",
"which",
"are",
"results",
"meaning",
"all",
"went",
"well",
"."
] | c0025daee5e7087f60b654595a8e7d92e966c54e | https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/xml.rb#L50-L88 |
4,190 | Absolight/epp-client | lib/epp-client/xml.rb | EPPClient.XML.command | def command(*args, &_block)
builder do |xml|
xml.command do
if block_given?
yield xml
else
command = args.shift
command.call(xml)
args.each do |ext|
xml.extension do
ext.call(xml)
end
end
end
xml.clTRID(clTRID)
end
end
end | ruby | def command(*args, &_block)
builder do |xml|
xml.command do
if block_given?
yield xml
else
command = args.shift
command.call(xml)
args.each do |ext|
xml.extension do
ext.call(xml)
end
end
end
xml.clTRID(clTRID)
end
end
end | [
"def",
"command",
"(",
"*",
"args",
",",
"&",
"_block",
")",
"builder",
"do",
"|",
"xml",
"|",
"xml",
".",
"command",
"do",
"if",
"block_given?",
"yield",
"xml",
"else",
"command",
"=",
"args",
".",
"shift",
"command",
".",
"call",
"(",
"xml",
")",
"args",
".",
"each",
"do",
"|",
"ext",
"|",
"xml",
".",
"extension",
"do",
"ext",
".",
"call",
"(",
"xml",
")",
"end",
"end",
"end",
"xml",
".",
"clTRID",
"(",
"clTRID",
")",
"end",
"end",
"end"
] | Creates the xml for the command.
You can either pass a block to it, in that case, it's the command body,
or a series of procs, the first one being the commands, the other ones
being the extensions.
command do |xml|
xml.logout
end
or
command(lambda do |xml|
xml.logout
end, lambda do |xml|
xml.extension
end) | [
"Creates",
"the",
"xml",
"for",
"the",
"command",
"."
] | c0025daee5e7087f60b654595a8e7d92e966c54e | https://github.com/Absolight/epp-client/blob/c0025daee5e7087f60b654595a8e7d92e966c54e/lib/epp-client/xml.rb#L114-L131 |
4,191 | regru/reg_api2-ruby | lib/reg_api2/action.rb | RegApi2.Action.create_http | def create_http
http = Net::HTTP.new(
API_URI.host,
API_URI.port
)
http.use_ssl = true
apply_ca_cert_path(http)
apply_pem(http)
http
end | ruby | def create_http
http = Net::HTTP.new(
API_URI.host,
API_URI.port
)
http.use_ssl = true
apply_ca_cert_path(http)
apply_pem(http)
http
end | [
"def",
"create_http",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"API_URI",
".",
"host",
",",
"API_URI",
".",
"port",
")",
"http",
".",
"use_ssl",
"=",
"true",
"apply_ca_cert_path",
"(",
"http",
")",
"apply_pem",
"(",
"http",
")",
"http",
"end"
] | Creates HTTPS handler.
@return [Net::HTTP] HTTPS handler.
@see #http | [
"Creates",
"HTTPS",
"handler",
"."
] | 82fadffc9da6534761003b8a33edb77ab617df70 | https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/action.rb#L48-L57 |
4,192 | regru/reg_api2-ruby | lib/reg_api2/action.rb | RegApi2.Action.get_form_data | def get_form_data(defopts, opts)
# HACK: REG.API doesn't know about utf-8.
io_encoding = 'utf8' if !io_encoding || io_encoding == DEFAULT_IO_ENCODING
opts = opts.to_hash if opts.respond_to?(:to_hash)
req_contract = RegApi2::RequestContract.new(defopts)
opts = req_contract.validate(opts)
form = {
'username' => username || DEFAULT_USERNAME,
'password' => password || DEFAULT_PASSWORD,
'io_encoding' => io_encoding,
'lang' => lang || DEFAULT_LANG,
'output_format' => 'json',
'input_format' => 'json',
'show_input_params' => 0,
'input_data' => Yajl::Encoder.encode(opts)
}
form
end | ruby | def get_form_data(defopts, opts)
# HACK: REG.API doesn't know about utf-8.
io_encoding = 'utf8' if !io_encoding || io_encoding == DEFAULT_IO_ENCODING
opts = opts.to_hash if opts.respond_to?(:to_hash)
req_contract = RegApi2::RequestContract.new(defopts)
opts = req_contract.validate(opts)
form = {
'username' => username || DEFAULT_USERNAME,
'password' => password || DEFAULT_PASSWORD,
'io_encoding' => io_encoding,
'lang' => lang || DEFAULT_LANG,
'output_format' => 'json',
'input_format' => 'json',
'show_input_params' => 0,
'input_data' => Yajl::Encoder.encode(opts)
}
form
end | [
"def",
"get_form_data",
"(",
"defopts",
",",
"opts",
")",
"# HACK: REG.API doesn't know about utf-8.",
"io_encoding",
"=",
"'utf8'",
"if",
"!",
"io_encoding",
"||",
"io_encoding",
"==",
"DEFAULT_IO_ENCODING",
"opts",
"=",
"opts",
".",
"to_hash",
"if",
"opts",
".",
"respond_to?",
"(",
":to_hash",
")",
"req_contract",
"=",
"RegApi2",
"::",
"RequestContract",
".",
"new",
"(",
"defopts",
")",
"opts",
"=",
"req_contract",
".",
"validate",
"(",
"opts",
")",
"form",
"=",
"{",
"'username'",
"=>",
"username",
"||",
"DEFAULT_USERNAME",
",",
"'password'",
"=>",
"password",
"||",
"DEFAULT_PASSWORD",
",",
"'io_encoding'",
"=>",
"io_encoding",
",",
"'lang'",
"=>",
"lang",
"||",
"DEFAULT_LANG",
",",
"'output_format'",
"=>",
"'json'",
",",
"'input_format'",
"=>",
"'json'",
",",
"'show_input_params'",
"=>",
"0",
",",
"'input_data'",
"=>",
"Yajl",
"::",
"Encoder",
".",
"encode",
"(",
"opts",
")",
"}",
"form",
"end"
] | Gets form data for POST request
@param [Hash] defopts
@param [Hash] opts
@return [Hash] Form data to be sent.
@raise [ContractError] | [
"Gets",
"form",
"data",
"for",
"POST",
"request"
] | 82fadffc9da6534761003b8a33edb77ab617df70 | https://github.com/regru/reg_api2-ruby/blob/82fadffc9da6534761003b8a33edb77ab617df70/lib/reg_api2/action.rb#L83-L102 |
4,193 | radar/summer | lib/summer.rb | Summer.Connection.startup! | def startup!
@started = true
try(:did_start_up)
if config['nickserv_password']
privmsg("identify #{config['nickserv_password']}", "nickserv")
# Wait 10 seconds for nickserv to get back to us.
Thread.new do
sleep(10)
finalize_startup
end
else
finalize_startup
end
end | ruby | def startup!
@started = true
try(:did_start_up)
if config['nickserv_password']
privmsg("identify #{config['nickserv_password']}", "nickserv")
# Wait 10 seconds for nickserv to get back to us.
Thread.new do
sleep(10)
finalize_startup
end
else
finalize_startup
end
end | [
"def",
"startup!",
"@started",
"=",
"true",
"try",
"(",
":did_start_up",
")",
"if",
"config",
"[",
"'nickserv_password'",
"]",
"privmsg",
"(",
"\"identify #{config['nickserv_password']}\"",
",",
"\"nickserv\"",
")",
"# Wait 10 seconds for nickserv to get back to us.",
"Thread",
".",
"new",
"do",
"sleep",
"(",
"10",
")",
"finalize_startup",
"end",
"else",
"finalize_startup",
"end",
"end"
] | Will join channels specified in configuration. | [
"Will",
"join",
"channels",
"specified",
"in",
"configuration",
"."
] | 7c08c6a8b2e986030db3718ca71daf2ca8dd668d | https://github.com/radar/summer/blob/7c08c6a8b2e986030db3718ca71daf2ca8dd668d/lib/summer.rb#L69-L83 |
4,194 | radar/summer | lib/summer.rb | Summer.Connection.parse | def parse(message)
puts "<< #{message.to_s.strip}"
words = message.split(" ")
sender = words[0]
raw = words[1]
channel = words[2]
# Handling pings
if /^PING (.*?)\s$/.match(message)
response("PONG #{$1}")
# Handling raws
elsif /\d+/.match(raw)
send("handle_#{raw}", message) if raws_to_handle.include?(raw)
# Privmsgs
elsif raw == "PRIVMSG"
message = words[3..-1].clean
# Parse commands
if /^!(\w+)\s*(.*)/.match(message) && respond_to?("#{$1}_command")
try("#{$1}_command", parse_sender(sender), channel, $2)
# Plain and boring message
else
sender = parse_sender(sender)
method, channel = channel == me ? [:private_message, sender[:nick]] : [:channel_message, channel]
try(method, sender, channel, message)
end
# Joins
elsif raw == "JOIN"
try(:join_event, parse_sender(sender), channel)
elsif raw == "PART"
try(:part_event, parse_sender(sender), channel, words[3..-1].clean)
elsif raw == "QUIT"
try(:quit_event, parse_sender(sender), words[2..-1].clean)
elsif raw == "KICK"
try(:kick_event, parse_sender(sender), channel, words[3], words[4..-1].clean)
join(channel) if words[3] == me && config[:auto_rejoin]
elsif raw == "MODE"
try(:mode_event, parse_sender(sender), channel, words[3], words[4..-1].clean)
end
end | ruby | def parse(message)
puts "<< #{message.to_s.strip}"
words = message.split(" ")
sender = words[0]
raw = words[1]
channel = words[2]
# Handling pings
if /^PING (.*?)\s$/.match(message)
response("PONG #{$1}")
# Handling raws
elsif /\d+/.match(raw)
send("handle_#{raw}", message) if raws_to_handle.include?(raw)
# Privmsgs
elsif raw == "PRIVMSG"
message = words[3..-1].clean
# Parse commands
if /^!(\w+)\s*(.*)/.match(message) && respond_to?("#{$1}_command")
try("#{$1}_command", parse_sender(sender), channel, $2)
# Plain and boring message
else
sender = parse_sender(sender)
method, channel = channel == me ? [:private_message, sender[:nick]] : [:channel_message, channel]
try(method, sender, channel, message)
end
# Joins
elsif raw == "JOIN"
try(:join_event, parse_sender(sender), channel)
elsif raw == "PART"
try(:part_event, parse_sender(sender), channel, words[3..-1].clean)
elsif raw == "QUIT"
try(:quit_event, parse_sender(sender), words[2..-1].clean)
elsif raw == "KICK"
try(:kick_event, parse_sender(sender), channel, words[3], words[4..-1].clean)
join(channel) if words[3] == me && config[:auto_rejoin]
elsif raw == "MODE"
try(:mode_event, parse_sender(sender), channel, words[3], words[4..-1].clean)
end
end | [
"def",
"parse",
"(",
"message",
")",
"puts",
"\"<< #{message.to_s.strip}\"",
"words",
"=",
"message",
".",
"split",
"(",
"\" \"",
")",
"sender",
"=",
"words",
"[",
"0",
"]",
"raw",
"=",
"words",
"[",
"1",
"]",
"channel",
"=",
"words",
"[",
"2",
"]",
"# Handling pings",
"if",
"/",
"\\s",
"/",
".",
"match",
"(",
"message",
")",
"response",
"(",
"\"PONG #{$1}\"",
")",
"# Handling raws",
"elsif",
"/",
"\\d",
"/",
".",
"match",
"(",
"raw",
")",
"send",
"(",
"\"handle_#{raw}\"",
",",
"message",
")",
"if",
"raws_to_handle",
".",
"include?",
"(",
"raw",
")",
"# Privmsgs",
"elsif",
"raw",
"==",
"\"PRIVMSG\"",
"message",
"=",
"words",
"[",
"3",
"..",
"-",
"1",
"]",
".",
"clean",
"# Parse commands",
"if",
"/",
"\\w",
"\\s",
"/",
".",
"match",
"(",
"message",
")",
"&&",
"respond_to?",
"(",
"\"#{$1}_command\"",
")",
"try",
"(",
"\"#{$1}_command\"",
",",
"parse_sender",
"(",
"sender",
")",
",",
"channel",
",",
"$2",
")",
"# Plain and boring message",
"else",
"sender",
"=",
"parse_sender",
"(",
"sender",
")",
"method",
",",
"channel",
"=",
"channel",
"==",
"me",
"?",
"[",
":private_message",
",",
"sender",
"[",
":nick",
"]",
"]",
":",
"[",
":channel_message",
",",
"channel",
"]",
"try",
"(",
"method",
",",
"sender",
",",
"channel",
",",
"message",
")",
"end",
"# Joins",
"elsif",
"raw",
"==",
"\"JOIN\"",
"try",
"(",
":join_event",
",",
"parse_sender",
"(",
"sender",
")",
",",
"channel",
")",
"elsif",
"raw",
"==",
"\"PART\"",
"try",
"(",
":part_event",
",",
"parse_sender",
"(",
"sender",
")",
",",
"channel",
",",
"words",
"[",
"3",
"..",
"-",
"1",
"]",
".",
"clean",
")",
"elsif",
"raw",
"==",
"\"QUIT\"",
"try",
"(",
":quit_event",
",",
"parse_sender",
"(",
"sender",
")",
",",
"words",
"[",
"2",
"..",
"-",
"1",
"]",
".",
"clean",
")",
"elsif",
"raw",
"==",
"\"KICK\"",
"try",
"(",
":kick_event",
",",
"parse_sender",
"(",
"sender",
")",
",",
"channel",
",",
"words",
"[",
"3",
"]",
",",
"words",
"[",
"4",
"..",
"-",
"1",
"]",
".",
"clean",
")",
"join",
"(",
"channel",
")",
"if",
"words",
"[",
"3",
"]",
"==",
"me",
"&&",
"config",
"[",
":auto_rejoin",
"]",
"elsif",
"raw",
"==",
"\"MODE\"",
"try",
"(",
":mode_event",
",",
"parse_sender",
"(",
"sender",
")",
",",
"channel",
",",
"words",
"[",
"3",
"]",
",",
"words",
"[",
"4",
"..",
"-",
"1",
"]",
".",
"clean",
")",
"end",
"end"
] | What did they say? | [
"What",
"did",
"they",
"say?"
] | 7c08c6a8b2e986030db3718ca71daf2ca8dd668d | https://github.com/radar/summer/blob/7c08c6a8b2e986030db3718ca71daf2ca8dd668d/lib/summer.rb#L107-L145 |
4,195 | apeiros/swissmatch-location | lib/swissmatch/zipcodes.rb | SwissMatch.ZipCodes.[] | def [](key, add_on=nil)
case key
when /\A(\d{4})(\d\d)\z/
by_code_and_add_on($1.to_i, $2.to_i)
when 100_000..999_999
by_code_and_add_on(*key.divmod(100))
when 0..9999, /\A\d{4}\z/
case add_on
when nil
by_code(key.to_i)
when 0..99, /\A\d+\z/
by_code_and_add_on(key.to_i, add_on.to_i)
when String
by_code_and_name(key.to_i, add_on)
else
raise ArgumentError,
"Expected a String, an Integer between 0 and 99, or a String containing an integer between 0 and 99, " \
"but got #{key.class}: #{key.inspect}"
end
when String
by_name(key)
else
raise ArgumentError,
"Expected a String, an Integer between 1000 and 9999, or an " \
"Integer between 100_000 and 999_999, but got #{key.class}:" \
"#{key.inspect}"
end
end | ruby | def [](key, add_on=nil)
case key
when /\A(\d{4})(\d\d)\z/
by_code_and_add_on($1.to_i, $2.to_i)
when 100_000..999_999
by_code_and_add_on(*key.divmod(100))
when 0..9999, /\A\d{4}\z/
case add_on
when nil
by_code(key.to_i)
when 0..99, /\A\d+\z/
by_code_and_add_on(key.to_i, add_on.to_i)
when String
by_code_and_name(key.to_i, add_on)
else
raise ArgumentError,
"Expected a String, an Integer between 0 and 99, or a String containing an integer between 0 and 99, " \
"but got #{key.class}: #{key.inspect}"
end
when String
by_name(key)
else
raise ArgumentError,
"Expected a String, an Integer between 1000 and 9999, or an " \
"Integer between 100_000 and 999_999, but got #{key.class}:" \
"#{key.inspect}"
end
end | [
"def",
"[]",
"(",
"key",
",",
"add_on",
"=",
"nil",
")",
"case",
"key",
"when",
"/",
"\\A",
"\\d",
"\\d",
"\\d",
"\\z",
"/",
"by_code_and_add_on",
"(",
"$1",
".",
"to_i",
",",
"$2",
".",
"to_i",
")",
"when",
"100_000",
"..",
"999_999",
"by_code_and_add_on",
"(",
"key",
".",
"divmod",
"(",
"100",
")",
")",
"when",
"0",
"..",
"9999",
",",
"/",
"\\A",
"\\d",
"\\z",
"/",
"case",
"add_on",
"when",
"nil",
"by_code",
"(",
"key",
".",
"to_i",
")",
"when",
"0",
"..",
"99",
",",
"/",
"\\A",
"\\d",
"\\z",
"/",
"by_code_and_add_on",
"(",
"key",
".",
"to_i",
",",
"add_on",
".",
"to_i",
")",
"when",
"String",
"by_code_and_name",
"(",
"key",
".",
"to_i",
",",
"add_on",
")",
"else",
"raise",
"ArgumentError",
",",
"\"Expected a String, an Integer between 0 and 99, or a String containing an integer between 0 and 99, \"",
"\"but got #{key.class}: #{key.inspect}\"",
"end",
"when",
"String",
"by_name",
"(",
"key",
")",
"else",
"raise",
"ArgumentError",
",",
"\"Expected a String, an Integer between 1000 and 9999, or an \"",
"\"Integer between 100_000 and 999_999, but got #{key.class}:\"",
"\"#{key.inspect}\"",
"end",
"end"
] | A convenience method to get one or many zip codes by code, code and add-on, code and city or just
city.
There are various allowed styles to pass those values.
All numeric values can be passed either as Integer or String.
You can pass the code and add-on as six-digit number, or you can pass the code
as four digit number plus either the add-on or name as second parameter. Or you can
pass the code alone, or the name alone.
@example All usage styles
zip_codes[805200] # zip code 8052, add-on 0
zip_codes["805200"] # zip code 8052, add-on 0
zip_codes[8052, 0] # zip code 8052, add-on 0
zip_codes["8052", 0] # zip code 8052, add-on 0
zip_codes[8052, "0"] # zip code 8052, add-on 0
zip_codes["8052", 0] # zip code 8052, add-on 0
zip_codes[8052, "Zürich"] # zip code 8052, add-on 0
zip_codes["8052", "Zürich"] # zip code 8052, add-on 0
zip_codes[8052] # all zip codes with code 8052
zip_codes["8052"] # all zip codes with code 8052
zip_codes["Zürich"] # all zip codes with name "Zürich"
@see #by_code_and_add_on Get a zip code by code and add-on directly
@see #by_code_and_name Get a zip code by code and name directly
@see #by_name Get a collection of zip codes by name directly
@see #by_ordering_number Get a zip code by its ONRP directly (#[] can't do that)
@param [String, Integer] key
Either the zip code, zip code and add-on
@return [SwissMatch::ZipCode, SwissMatch::ZipCodes]
Either a SwissMatch::ZipCodes collection of zip codes or a single SwissMatch::ZipCode, depending on
the argument you pass. | [
"A",
"convenience",
"method",
"to",
"get",
"one",
"or",
"many",
"zip",
"codes",
"by",
"code",
"code",
"and",
"add",
"-",
"on",
"code",
"and",
"city",
"or",
"just",
"city",
".",
"There",
"are",
"various",
"allowed",
"styles",
"to",
"pass",
"those",
"values",
".",
"All",
"numeric",
"values",
"can",
"be",
"passed",
"either",
"as",
"Integer",
"or",
"String",
".",
"You",
"can",
"pass",
"the",
"code",
"and",
"add",
"-",
"on",
"as",
"six",
"-",
"digit",
"number",
"or",
"you",
"can",
"pass",
"the",
"code",
"as",
"four",
"digit",
"number",
"plus",
"either",
"the",
"add",
"-",
"on",
"or",
"name",
"as",
"second",
"parameter",
".",
"Or",
"you",
"can",
"pass",
"the",
"code",
"alone",
"or",
"the",
"name",
"alone",
"."
] | 9d360149f29a3e876a55338833e5e6fe89e3622f | https://github.com/apeiros/swissmatch-location/blob/9d360149f29a3e876a55338833e5e6fe89e3622f/lib/swissmatch/zipcodes.rb#L67-L94 |
4,196 | pboling/csv_pirate | lib/csv_pirate/the_capn.rb | CsvPirate.TheCapn.poop_deck | def poop_deck(brig)
if BRIGANTINE_OPTIONS.include?(brig) && !self.flies.empty?
self.old_csv_dump(brig)
elsif brig.is_a?(String)
"#{self.analemma}#{brig}"
else
"#{self.analemma}#{self.swabbie}#{self.aft}"
end
end | ruby | def poop_deck(brig)
if BRIGANTINE_OPTIONS.include?(brig) && !self.flies.empty?
self.old_csv_dump(brig)
elsif brig.is_a?(String)
"#{self.analemma}#{brig}"
else
"#{self.analemma}#{self.swabbie}#{self.aft}"
end
end | [
"def",
"poop_deck",
"(",
"brig",
")",
"if",
"BRIGANTINE_OPTIONS",
".",
"include?",
"(",
"brig",
")",
"&&",
"!",
"self",
".",
"flies",
".",
"empty?",
"self",
".",
"old_csv_dump",
"(",
"brig",
")",
"elsif",
"brig",
".",
"is_a?",
"(",
"String",
")",
"\"#{self.analemma}#{brig}\"",
"else",
"\"#{self.analemma}#{self.swabbie}#{self.aft}\"",
"end",
"end"
] | complete file path | [
"complete",
"file",
"path"
] | 3fb0bde9a49b3894bde45d2668fc258eebd61049 | https://github.com/pboling/csv_pirate/blob/3fb0bde9a49b3894bde45d2668fc258eebd61049/lib/csv_pirate/the_capn.rb#L277-L285 |
4,197 | pboling/csv_pirate | lib/csv_pirate/the_capn.rb | CsvPirate.TheCapn.unfurl | def unfurl
wibbly = self.waggoner == '' ? '' : Regexp.escape(self.waggoner)
timey = self.sand_glass == '' ? '' : '\.\d+'
wimey = self.gibbet == '' ? '' : Regexp.escape(self.gibbet)
Regexp.new("#{wibbly}#{timey}#{wimey}")
end | ruby | def unfurl
wibbly = self.waggoner == '' ? '' : Regexp.escape(self.waggoner)
timey = self.sand_glass == '' ? '' : '\.\d+'
wimey = self.gibbet == '' ? '' : Regexp.escape(self.gibbet)
Regexp.new("#{wibbly}#{timey}#{wimey}")
end | [
"def",
"unfurl",
"wibbly",
"=",
"self",
".",
"waggoner",
"==",
"''",
"?",
"''",
":",
"Regexp",
".",
"escape",
"(",
"self",
".",
"waggoner",
")",
"timey",
"=",
"self",
".",
"sand_glass",
"==",
"''",
"?",
"''",
":",
"'\\.\\d+'",
"wimey",
"=",
"self",
".",
"gibbet",
"==",
"''",
"?",
"''",
":",
"Regexp",
".",
"escape",
"(",
"self",
".",
"gibbet",
")",
"Regexp",
".",
"new",
"(",
"\"#{wibbly}#{timey}#{wimey}\"",
")",
"end"
] | Regex for matching dumped CSVs | [
"Regex",
"for",
"matching",
"dumped",
"CSVs"
] | 3fb0bde9a49b3894bde45d2668fc258eebd61049 | https://github.com/pboling/csv_pirate/blob/3fb0bde9a49b3894bde45d2668fc258eebd61049/lib/csv_pirate/the_capn.rb#L432-L437 |
4,198 | pboling/csv_pirate | lib/csv_pirate/the_capn.rb | CsvPirate.TheCapn.binnacle | def binnacle(join_value, humanize = true)
self.booty.map do |compass|
string = compass.is_a?(Hash) ?
self.run_through(compass, join_value) :
compass.is_a?(String) ?
compass :
compass.is_a?(Symbol) ?
compass.to_s :
compass.to_s
humanize ? string.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize : string
end
end | ruby | def binnacle(join_value, humanize = true)
self.booty.map do |compass|
string = compass.is_a?(Hash) ?
self.run_through(compass, join_value) :
compass.is_a?(String) ?
compass :
compass.is_a?(Symbol) ?
compass.to_s :
compass.to_s
humanize ? string.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize : string
end
end | [
"def",
"binnacle",
"(",
"join_value",
",",
"humanize",
"=",
"true",
")",
"self",
".",
"booty",
".",
"map",
"do",
"|",
"compass",
"|",
"string",
"=",
"compass",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"self",
".",
"run_through",
"(",
"compass",
",",
"join_value",
")",
":",
"compass",
".",
"is_a?",
"(",
"String",
")",
"?",
"compass",
":",
"compass",
".",
"is_a?",
"(",
"Symbol",
")",
"?",
"compass",
".",
"to_s",
":",
"compass",
".",
"to_s",
"humanize",
"?",
"string",
".",
"to_s",
".",
"gsub",
"(",
"/",
"/",
",",
"\"\"",
")",
".",
"gsub",
"(",
"/",
"/",
",",
"\" \"",
")",
".",
"capitalize",
":",
"string",
"end",
"end"
] | returns an array of strings for CSV header based on booty | [
"returns",
"an",
"array",
"of",
"strings",
"for",
"CSV",
"header",
"based",
"on",
"booty"
] | 3fb0bde9a49b3894bde45d2668fc258eebd61049 | https://github.com/pboling/csv_pirate/blob/3fb0bde9a49b3894bde45d2668fc258eebd61049/lib/csv_pirate/the_capn.rb#L457-L468 |
4,199 | pboling/csv_pirate | lib/csv_pirate/the_capn.rb | CsvPirate.TheCapn.boatswain | def boatswain
return self.swabbie unless self.swabbie.nil?
highval = 0
self.axe.each do |flotsam|
counter = self.filibuster(flotsam)
highval = ((highval <=> counter) == 1) ? highval : counter
end
".#{highval + 1}"
end | ruby | def boatswain
return self.swabbie unless self.swabbie.nil?
highval = 0
self.axe.each do |flotsam|
counter = self.filibuster(flotsam)
highval = ((highval <=> counter) == 1) ? highval : counter
end
".#{highval + 1}"
end | [
"def",
"boatswain",
"return",
"self",
".",
"swabbie",
"unless",
"self",
".",
"swabbie",
".",
"nil?",
"highval",
"=",
"0",
"self",
".",
"axe",
".",
"each",
"do",
"|",
"flotsam",
"|",
"counter",
"=",
"self",
".",
"filibuster",
"(",
"flotsam",
")",
"highval",
"=",
"(",
"(",
"highval",
"<=>",
"counter",
")",
"==",
"1",
")",
"?",
"highval",
":",
"counter",
"end",
"\".#{highval + 1}\"",
"end"
] | File increment for next CSV to dump | [
"File",
"increment",
"for",
"next",
"CSV",
"to",
"dump"
] | 3fb0bde9a49b3894bde45d2668fc258eebd61049 | https://github.com/pboling/csv_pirate/blob/3fb0bde9a49b3894bde45d2668fc258eebd61049/lib/csv_pirate/the_capn.rb#L517-L525 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.