repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
scrapper/perobs | lib/perobs/IDListPageFile.rb | PEROBS.IDListPageFile.page | def page(record)
p = @pages.get(record.page_idx, record) || load(record.page_idx, record)
unless p.uid == record.page_idx
raise RuntimeError, "Page reference mismatch. Record " +
"#{record.page_idx} points to page #{p.uid}"
end
p
end | ruby | def page(record)
p = @pages.get(record.page_idx, record) || load(record.page_idx, record)
unless p.uid == record.page_idx
raise RuntimeError, "Page reference mismatch. Record " +
"#{record.page_idx} points to page #{p.uid}"
end
p
end | [
"def",
"page",
"(",
"record",
")",
"p",
"=",
"@pages",
".",
"get",
"(",
"record",
".",
"page_idx",
",",
"record",
")",
"||",
"load",
"(",
"record",
".",
"page_idx",
",",
"record",
")",
"unless",
"p",
".",
"uid",
"==",
"record",
".",
"page_idx",
"raise",
"RuntimeError",
",",
"\"Page reference mismatch. Record \"",
"+",
"\"#{record.page_idx} points to page #{p.uid}\"",
"end",
"p",
"end"
] | Return the IDListPage object with the given index.
@param record [IDListPageRecord] the corresponding IDListPageRecord
@return [IDListPage] The page corresponding to the index. | [
"Return",
"the",
"IDListPage",
"object",
"with",
"the",
"given",
"index",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/IDListPageFile.rb#L105-L113 | train |
scrapper/perobs | lib/perobs/IDListPageFile.rb | PEROBS.IDListPageFile.save_page | def save_page(p)
if p.record.page_entries != p.values.length
raise RuntimeError, "page_entries mismatch for node #{p.uid}"
end
begin
@f.seek(p.uid * @page_size * 8)
@f.write(p.values.pack('Q*'))
rescue IOError => e
PEROBS.log.fatal "Cannot write cache file #{@file_name}: #{e.message}"
end
end | ruby | def save_page(p)
if p.record.page_entries != p.values.length
raise RuntimeError, "page_entries mismatch for node #{p.uid}"
end
begin
@f.seek(p.uid * @page_size * 8)
@f.write(p.values.pack('Q*'))
rescue IOError => e
PEROBS.log.fatal "Cannot write cache file #{@file_name}: #{e.message}"
end
end | [
"def",
"save_page",
"(",
"p",
")",
"if",
"p",
".",
"record",
".",
"page_entries",
"!=",
"p",
".",
"values",
".",
"length",
"raise",
"RuntimeError",
",",
"\"page_entries mismatch for node #{p.uid}\"",
"end",
"begin",
"@f",
".",
"seek",
"(",
"p",
".",
"uid",
"*",
"@page_size",
"*",
"8",
")",
"@f",
".",
"write",
"(",
"p",
".",
"values",
".",
"pack",
"(",
"'Q*'",
")",
")",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot write cache file #{@file_name}: #{e.message}\"",
"end",
"end"
] | Save the given IDListPage into the cache file.
@param p [IDListPage] page to store | [
"Save",
"the",
"given",
"IDListPage",
"into",
"the",
"cache",
"file",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/IDListPageFile.rb#L144-L154 | train |
THECALLR/sdk-ruby | lib/callr.rb | CALLR.Api.send | def send(method, params = [], id = nil)
check_auth()
json = {
:id => id.nil? || id.is_a?(Integer) == false ? rand(999 - 100) + 100 : id,
:jsonrpc => "2.0",
:method => method,
:params => params.is_a?(Array) ? params : []
}.to_json
uri = URI.parse(API_URL)
http = http_or_http_proxy(uri)
req = Net::HTTP::Post.new(uri.request_uri, @headers)
req.basic_auth(@login, @password)
req.add_field('User-Agent', "sdk=RUBY; sdk-version=#{SDK_VERSION}; lang-version=#{RUBY_VERSION}; platform=#{RUBY_PLATFORM}")
req.add_field('CALLR-Login-As', @login_as) unless @login_as.to_s.empty?
begin
res = http.request(req, json)
if res.code.to_i != 200
raise CallrException.new("HTTP_CODE_ERROR", -1, {:http_code => res.code.to_i, :http_message => res.message})
end
return parse_response(res)
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Errno::ECONNREFUSED,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
raise CallrException.new("HTTP_EXCEPTION", -2, {:exception => e})
end
end | ruby | def send(method, params = [], id = nil)
check_auth()
json = {
:id => id.nil? || id.is_a?(Integer) == false ? rand(999 - 100) + 100 : id,
:jsonrpc => "2.0",
:method => method,
:params => params.is_a?(Array) ? params : []
}.to_json
uri = URI.parse(API_URL)
http = http_or_http_proxy(uri)
req = Net::HTTP::Post.new(uri.request_uri, @headers)
req.basic_auth(@login, @password)
req.add_field('User-Agent', "sdk=RUBY; sdk-version=#{SDK_VERSION}; lang-version=#{RUBY_VERSION}; platform=#{RUBY_PLATFORM}")
req.add_field('CALLR-Login-As', @login_as) unless @login_as.to_s.empty?
begin
res = http.request(req, json)
if res.code.to_i != 200
raise CallrException.new("HTTP_CODE_ERROR", -1, {:http_code => res.code.to_i, :http_message => res.message})
end
return parse_response(res)
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Errno::ECONNREFUSED,
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
raise CallrException.new("HTTP_EXCEPTION", -2, {:exception => e})
end
end | [
"def",
"send",
"(",
"method",
",",
"params",
"=",
"[",
"]",
",",
"id",
"=",
"nil",
")",
"check_auth",
"(",
")",
"json",
"=",
"{",
":id",
"=>",
"id",
".",
"nil?",
"||",
"id",
".",
"is_a?",
"(",
"Integer",
")",
"==",
"false",
"?",
"rand",
"(",
"999",
"-",
"100",
")",
"+",
"100",
":",
"id",
",",
":jsonrpc",
"=>",
"\"2.0\"",
",",
":method",
"=>",
"method",
",",
":params",
"=>",
"params",
".",
"is_a?",
"(",
"Array",
")",
"?",
"params",
":",
"[",
"]",
"}",
".",
"to_json",
"uri",
"=",
"URI",
".",
"parse",
"(",
"API_URL",
")",
"http",
"=",
"http_or_http_proxy",
"(",
"uri",
")",
"req",
"=",
"Net",
"::",
"HTTP",
"::",
"Post",
".",
"new",
"(",
"uri",
".",
"request_uri",
",",
"@headers",
")",
"req",
".",
"basic_auth",
"(",
"@login",
",",
"@password",
")",
"req",
".",
"add_field",
"(",
"'User-Agent'",
",",
"\"sdk=RUBY; sdk-version=#{SDK_VERSION}; lang-version=#{RUBY_VERSION}; platform=#{RUBY_PLATFORM}\"",
")",
"req",
".",
"add_field",
"(",
"'CALLR-Login-As'",
",",
"@login_as",
")",
"unless",
"@login_as",
".",
"to_s",
".",
"empty?",
"begin",
"res",
"=",
"http",
".",
"request",
"(",
"req",
",",
"json",
")",
"if",
"res",
".",
"code",
".",
"to_i",
"!=",
"200",
"raise",
"CallrException",
".",
"new",
"(",
"\"HTTP_CODE_ERROR\"",
",",
"-",
"1",
",",
"{",
":http_code",
"=>",
"res",
".",
"code",
".",
"to_i",
",",
":http_message",
"=>",
"res",
".",
"message",
"}",
")",
"end",
"return",
"parse_response",
"(",
"res",
")",
"rescue",
"Timeout",
"::",
"Error",
",",
"Errno",
"::",
"EINVAL",
",",
"Errno",
"::",
"ECONNRESET",
",",
"EOFError",
",",
"Errno",
"::",
"ETIMEDOUT",
",",
"Errno",
"::",
"ECONNREFUSED",
",",
"Net",
"::",
"HTTPBadResponse",
",",
"Net",
"::",
"HTTPHeaderSyntaxError",
",",
"Net",
"::",
"ProtocolError",
"=>",
"e",
"raise",
"CallrException",
".",
"new",
"(",
"\"HTTP_EXCEPTION\"",
",",
"-",
"2",
",",
"{",
":exception",
"=>",
"e",
"}",
")",
"end",
"end"
] | Send a request to CALLR webservice | [
"Send",
"a",
"request",
"to",
"CALLR",
"webservice"
] | e10f5fe527ab378b4b298045b0c49397b8f8df8b | https://github.com/THECALLR/sdk-ruby/blob/e10f5fe527ab378b4b298045b0c49397b8f8df8b/lib/callr.rb#L80-L108 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.write_object | def write_object(id, raw)
if @entries.length > @btreedb.max_blob_size
# The blob has reached the maximum size. Replace the blob with a BTree
# node directory and distribute the blob entires into the sub-blobs of
# the new BTree node.
split_blob
# Insert the passed object into the newly created BTree node.
@btreedb.put_raw_object(raw, id)
else
bytes = raw.bytesize
crc32 = Zlib.crc32(raw, 0)
start_address = reserve_bytes(id, bytes, crc32)
if write_to_blobs_file(raw, start_address) != bytes
PEROBS.log.fatal 'Object length does not match written bytes'
end
write_index
end
end | ruby | def write_object(id, raw)
if @entries.length > @btreedb.max_blob_size
# The blob has reached the maximum size. Replace the blob with a BTree
# node directory and distribute the blob entires into the sub-blobs of
# the new BTree node.
split_blob
# Insert the passed object into the newly created BTree node.
@btreedb.put_raw_object(raw, id)
else
bytes = raw.bytesize
crc32 = Zlib.crc32(raw, 0)
start_address = reserve_bytes(id, bytes, crc32)
if write_to_blobs_file(raw, start_address) != bytes
PEROBS.log.fatal 'Object length does not match written bytes'
end
write_index
end
end | [
"def",
"write_object",
"(",
"id",
",",
"raw",
")",
"if",
"@entries",
".",
"length",
">",
"@btreedb",
".",
"max_blob_size",
"split_blob",
"@btreedb",
".",
"put_raw_object",
"(",
"raw",
",",
"id",
")",
"else",
"bytes",
"=",
"raw",
".",
"bytesize",
"crc32",
"=",
"Zlib",
".",
"crc32",
"(",
"raw",
",",
"0",
")",
"start_address",
"=",
"reserve_bytes",
"(",
"id",
",",
"bytes",
",",
"crc32",
")",
"if",
"write_to_blobs_file",
"(",
"raw",
",",
"start_address",
")",
"!=",
"bytes",
"PEROBS",
".",
"log",
".",
"fatal",
"'Object length does not match written bytes'",
"end",
"write_index",
"end",
"end"
] | Create a new BTreeBlob object.
@param dir [String] Fully qualified directory name
@param btreedb [BTreeDB] Reference to the DB that owns this blob
Write the given bytes with the given ID into the DB.
@param id [Integer] ID
@param raw [String] sequence of bytes | [
"Create",
"a",
"new",
"BTreeBlob",
"object",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L70-L87 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.mark | def mark(id)
found = false
@entries.each do |entry|
if entry[ID] == id
entry[MARKED] = 1
found = true
break
end
end
unless found
PEROBS.log.fatal "Cannot find an entry for ID #{'%016X' % id} " +
"#{id} to mark"
end
write_index
end | ruby | def mark(id)
found = false
@entries.each do |entry|
if entry[ID] == id
entry[MARKED] = 1
found = true
break
end
end
unless found
PEROBS.log.fatal "Cannot find an entry for ID #{'%016X' % id} " +
"#{id} to mark"
end
write_index
end | [
"def",
"mark",
"(",
"id",
")",
"found",
"=",
"false",
"@entries",
".",
"each",
"do",
"|",
"entry",
"|",
"if",
"entry",
"[",
"ID",
"]",
"==",
"id",
"entry",
"[",
"MARKED",
"]",
"=",
"1",
"found",
"=",
"true",
"break",
"end",
"end",
"unless",
"found",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot find an entry for ID #{'%016X' % id} \"",
"+",
"\"#{id} to mark\"",
"end",
"write_index",
"end"
] | Set a mark on the entry with the given ID.
@param id [Integer] ID of the entry | [
"Set",
"a",
"mark",
"on",
"the",
"entry",
"with",
"the",
"given",
"ID",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L113-L129 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.is_marked? | def is_marked?(id, ignore_errors = false)
@entries.each do |entry|
return entry[MARKED] != 0 if entry[ID] == id
end
return false if ignore_errors
PEROBS.log.fatal "Cannot find an entry for ID #{'%016X' % id} to check"
end | ruby | def is_marked?(id, ignore_errors = false)
@entries.each do |entry|
return entry[MARKED] != 0 if entry[ID] == id
end
return false if ignore_errors
PEROBS.log.fatal "Cannot find an entry for ID #{'%016X' % id} to check"
end | [
"def",
"is_marked?",
"(",
"id",
",",
"ignore_errors",
"=",
"false",
")",
"@entries",
".",
"each",
"do",
"|",
"entry",
"|",
"return",
"entry",
"[",
"MARKED",
"]",
"!=",
"0",
"if",
"entry",
"[",
"ID",
"]",
"==",
"id",
"end",
"return",
"false",
"if",
"ignore_errors",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot find an entry for ID #{'%016X' % id} to check\"",
"end"
] | Check if the entry for a given ID is marked.
@param id [Integer] ID of the entry
@param ignore_errors [Boolean] If set to true no errors will be raised
for non-existing objects.
@return [TrueClass or FalseClass] true if marked, false otherwise | [
"Check",
"if",
"the",
"entry",
"for",
"a",
"given",
"ID",
"is",
"marked",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L136-L143 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.delete_unmarked_entries | def delete_unmarked_entries
deleted_ids = []
# First remove the entry from the hash table.
@entries_by_id.delete_if do |id, e|
if e[MARKED] == 0
deleted_ids << id
true
else
false
end
end
# Then delete the entry itself.
@entries.delete_if { |e| e[MARKED] == 0 }
write_index
deleted_ids
end | ruby | def delete_unmarked_entries
deleted_ids = []
# First remove the entry from the hash table.
@entries_by_id.delete_if do |id, e|
if e[MARKED] == 0
deleted_ids << id
true
else
false
end
end
# Then delete the entry itself.
@entries.delete_if { |e| e[MARKED] == 0 }
write_index
deleted_ids
end | [
"def",
"delete_unmarked_entries",
"deleted_ids",
"=",
"[",
"]",
"@entries_by_id",
".",
"delete_if",
"do",
"|",
"id",
",",
"e",
"|",
"if",
"e",
"[",
"MARKED",
"]",
"==",
"0",
"deleted_ids",
"<<",
"id",
"true",
"else",
"false",
"end",
"end",
"@entries",
".",
"delete_if",
"{",
"|",
"e",
"|",
"e",
"[",
"MARKED",
"]",
"==",
"0",
"}",
"write_index",
"deleted_ids",
"end"
] | Remove all entries from the index that have not been marked.
@return [Array] List of deleted object IDs. | [
"Remove",
"all",
"entries",
"from",
"the",
"index",
"that",
"have",
"not",
"been",
"marked",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L147-L163 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.check | def check(repair = false)
# Determine size of the data blobs file.
data_file_size = File.exist?(@blobs_file_name) ?
File.size(@blobs_file_name) : 0
next_start = 0
prev_entry = nil
@entries.each do |entry|
# Entries should never overlap
if prev_entry && next_start > entry[START]
PEROBS.log.fatal
"#{@dir}: Index entries are overlapping\n" +
"ID: #{'%016X' % prev_entry[ID]} " +
"Start: #{prev_entry[START]} " +
"Bytes: #{prev_entry[BYTES]}\n" +
"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} " +
"Bytes: #{entry[BYTES]}"
end
next_start = entry[START] + entry[BYTES]
# Entries must fit within the data file
if next_start > data_file_size
PEROBS.log.fatal
"#{@dir}: Entry for ID #{'%016X' % entry[ID]} " +
"goes beyond 'data' file " +
"size (#{data_file_size})\n" +
"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} " +
"Bytes: #{entry[BYTES]}"
end
prev_entry = entry
end
true
end | ruby | def check(repair = false)
# Determine size of the data blobs file.
data_file_size = File.exist?(@blobs_file_name) ?
File.size(@blobs_file_name) : 0
next_start = 0
prev_entry = nil
@entries.each do |entry|
# Entries should never overlap
if prev_entry && next_start > entry[START]
PEROBS.log.fatal
"#{@dir}: Index entries are overlapping\n" +
"ID: #{'%016X' % prev_entry[ID]} " +
"Start: #{prev_entry[START]} " +
"Bytes: #{prev_entry[BYTES]}\n" +
"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} " +
"Bytes: #{entry[BYTES]}"
end
next_start = entry[START] + entry[BYTES]
# Entries must fit within the data file
if next_start > data_file_size
PEROBS.log.fatal
"#{@dir}: Entry for ID #{'%016X' % entry[ID]} " +
"goes beyond 'data' file " +
"size (#{data_file_size})\n" +
"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} " +
"Bytes: #{entry[BYTES]}"
end
prev_entry = entry
end
true
end | [
"def",
"check",
"(",
"repair",
"=",
"false",
")",
"data_file_size",
"=",
"File",
".",
"exist?",
"(",
"@blobs_file_name",
")",
"?",
"File",
".",
"size",
"(",
"@blobs_file_name",
")",
":",
"0",
"next_start",
"=",
"0",
"prev_entry",
"=",
"nil",
"@entries",
".",
"each",
"do",
"|",
"entry",
"|",
"if",
"prev_entry",
"&&",
"next_start",
">",
"entry",
"[",
"START",
"]",
"PEROBS",
".",
"log",
".",
"fatal",
"\"#{@dir}: Index entries are overlapping\\n\"",
"+",
"\"ID: #{'%016X' % prev_entry[ID]} \"",
"+",
"\"Start: #{prev_entry[START]} \"",
"+",
"\"Bytes: #{prev_entry[BYTES]}\\n\"",
"+",
"\"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} \"",
"+",
"\"Bytes: #{entry[BYTES]}\"",
"end",
"next_start",
"=",
"entry",
"[",
"START",
"]",
"+",
"entry",
"[",
"BYTES",
"]",
"if",
"next_start",
">",
"data_file_size",
"PEROBS",
".",
"log",
".",
"fatal",
"\"#{@dir}: Entry for ID #{'%016X' % entry[ID]} \"",
"+",
"\"goes beyond 'data' file \"",
"+",
"\"size (#{data_file_size})\\n\"",
"+",
"\"ID: #{'%016X' % entry[ID]} Start: #{entry[START]} \"",
"+",
"\"Bytes: #{entry[BYTES]}\"",
"end",
"prev_entry",
"=",
"entry",
"end",
"true",
"end"
] | Run a basic consistency check.
@param repair [TrueClass/FalseClass] Not used right now
@return [TrueClass/FalseClass] Always true right now | [
"Run",
"a",
"basic",
"consistency",
"check",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L168-L202 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.write_to_blobs_file | def write_to_blobs_file(raw, address)
begin
File.write(@blobs_file_name, raw, address)
rescue IOError => e
PEROBS.log.fatal "Cannot write blobs file #{@blobs_file_name}: " +
e.message
end
end | ruby | def write_to_blobs_file(raw, address)
begin
File.write(@blobs_file_name, raw, address)
rescue IOError => e
PEROBS.log.fatal "Cannot write blobs file #{@blobs_file_name}: " +
e.message
end
end | [
"def",
"write_to_blobs_file",
"(",
"raw",
",",
"address",
")",
"begin",
"File",
".",
"write",
"(",
"@blobs_file_name",
",",
"raw",
",",
"address",
")",
"rescue",
"IOError",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot write blobs file #{@blobs_file_name}: \"",
"+",
"e",
".",
"message",
"end",
"end"
] | Write a string of bytes into the file at the given address.
@param raw [String] bytes to write
@param address [Integer] offset in the file
@return [Integer] number of bytes written | [
"Write",
"a",
"string",
"of",
"bytes",
"into",
"the",
"file",
"at",
"the",
"given",
"address",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L210-L217 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.read_from_blobs_file | def read_from_blobs_file(entry)
begin
raw = File.read(@blobs_file_name, entry[BYTES], entry[START])
rescue => e
PEROBS.log.fatal "Cannot read blobs file #{@blobs_file_name}: " +
e.message
end
if Zlib.crc32(raw, 0) != entry[CRC]
PEROBS.log.fatal "BTreeBlob for object #{entry[ID]} has been " +
"corrupted: Checksum mismatch"
end
raw
end | ruby | def read_from_blobs_file(entry)
begin
raw = File.read(@blobs_file_name, entry[BYTES], entry[START])
rescue => e
PEROBS.log.fatal "Cannot read blobs file #{@blobs_file_name}: " +
e.message
end
if Zlib.crc32(raw, 0) != entry[CRC]
PEROBS.log.fatal "BTreeBlob for object #{entry[ID]} has been " +
"corrupted: Checksum mismatch"
end
raw
end | [
"def",
"read_from_blobs_file",
"(",
"entry",
")",
"begin",
"raw",
"=",
"File",
".",
"read",
"(",
"@blobs_file_name",
",",
"entry",
"[",
"BYTES",
"]",
",",
"entry",
"[",
"START",
"]",
")",
"rescue",
"=>",
"e",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Cannot read blobs file #{@blobs_file_name}: \"",
"+",
"e",
".",
"message",
"end",
"if",
"Zlib",
".",
"crc32",
"(",
"raw",
",",
"0",
")",
"!=",
"entry",
"[",
"CRC",
"]",
"PEROBS",
".",
"log",
".",
"fatal",
"\"BTreeBlob for object #{entry[ID]} has been \"",
"+",
"\"corrupted: Checksum mismatch\"",
"end",
"raw",
"end"
] | Read _bytes_ bytes from the file starting at offset _address_.
@param entry [Array] Index entry for the object
@return [String] Raw bytes of the blob. | [
"Read",
"_bytes_",
"bytes",
"from",
"the",
"file",
"starting",
"at",
"offset",
"_address_",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L222-L235 | train |
scrapper/perobs | lib/perobs/BTreeBlob.rb | PEROBS.BTreeBlob.reserve_bytes | def reserve_bytes(id, bytes, crc32)
# index of first blob after the last seen entry
end_of_last_entry = 0
# blob index of best fit segment
best_fit_start = nil
# best fir segment size in bytes
best_fit_bytes = nil
# Index where to insert the new entry. Append by default.
best_fit_index = -1
# If there is already an entry for an object with the _id_, we mark it
# for deletion.
entry_to_delete = nil
@entries.each.with_index do |entry, i|
if entry[ID] == id
# We've found an old entry for this ID. Mark it for deletion.
entry_to_delete = entry
next
end
gap = entry[START] - end_of_last_entry
if gap >= bytes &&
(best_fit_bytes.nil? || gap < best_fit_bytes)
# We've found a segment that fits the requested bytes and fits
# better than any previous find.
best_fit_start = end_of_last_entry
best_fit_bytes = gap
# The old entry gets deleted before the new one gets inserted. We
# need to correct the index appropriately.
best_fit_index = i - (entry_to_delete ? 1 : 0)
end
end_of_last_entry = entry[START] + entry[BYTES]
end
# Delete the old entry if requested.
@entries.delete(entry_to_delete) if entry_to_delete
# Create a new entry and insert it. The order must match the above
# defined constants!
# Object reads can trigger creation of new objects. As the marking
# process triggers reads as well, all newly created objects are always
# marked to prevent them from being collected right after creation.
entry = [ id, bytes, best_fit_start || end_of_last_entry, 1, crc32 ]
@entries.insert(best_fit_index, entry)
@entries_by_id[id] = entry
entry[START]
end | ruby | def reserve_bytes(id, bytes, crc32)
# index of first blob after the last seen entry
end_of_last_entry = 0
# blob index of best fit segment
best_fit_start = nil
# best fir segment size in bytes
best_fit_bytes = nil
# Index where to insert the new entry. Append by default.
best_fit_index = -1
# If there is already an entry for an object with the _id_, we mark it
# for deletion.
entry_to_delete = nil
@entries.each.with_index do |entry, i|
if entry[ID] == id
# We've found an old entry for this ID. Mark it for deletion.
entry_to_delete = entry
next
end
gap = entry[START] - end_of_last_entry
if gap >= bytes &&
(best_fit_bytes.nil? || gap < best_fit_bytes)
# We've found a segment that fits the requested bytes and fits
# better than any previous find.
best_fit_start = end_of_last_entry
best_fit_bytes = gap
# The old entry gets deleted before the new one gets inserted. We
# need to correct the index appropriately.
best_fit_index = i - (entry_to_delete ? 1 : 0)
end
end_of_last_entry = entry[START] + entry[BYTES]
end
# Delete the old entry if requested.
@entries.delete(entry_to_delete) if entry_to_delete
# Create a new entry and insert it. The order must match the above
# defined constants!
# Object reads can trigger creation of new objects. As the marking
# process triggers reads as well, all newly created objects are always
# marked to prevent them from being collected right after creation.
entry = [ id, bytes, best_fit_start || end_of_last_entry, 1, crc32 ]
@entries.insert(best_fit_index, entry)
@entries_by_id[id] = entry
entry[START]
end | [
"def",
"reserve_bytes",
"(",
"id",
",",
"bytes",
",",
"crc32",
")",
"end_of_last_entry",
"=",
"0",
"best_fit_start",
"=",
"nil",
"best_fit_bytes",
"=",
"nil",
"best_fit_index",
"=",
"-",
"1",
"entry_to_delete",
"=",
"nil",
"@entries",
".",
"each",
".",
"with_index",
"do",
"|",
"entry",
",",
"i",
"|",
"if",
"entry",
"[",
"ID",
"]",
"==",
"id",
"entry_to_delete",
"=",
"entry",
"next",
"end",
"gap",
"=",
"entry",
"[",
"START",
"]",
"-",
"end_of_last_entry",
"if",
"gap",
">=",
"bytes",
"&&",
"(",
"best_fit_bytes",
".",
"nil?",
"||",
"gap",
"<",
"best_fit_bytes",
")",
"best_fit_start",
"=",
"end_of_last_entry",
"best_fit_bytes",
"=",
"gap",
"best_fit_index",
"=",
"i",
"-",
"(",
"entry_to_delete",
"?",
"1",
":",
"0",
")",
"end",
"end_of_last_entry",
"=",
"entry",
"[",
"START",
"]",
"+",
"entry",
"[",
"BYTES",
"]",
"end",
"@entries",
".",
"delete",
"(",
"entry_to_delete",
")",
"if",
"entry_to_delete",
"entry",
"=",
"[",
"id",
",",
"bytes",
",",
"best_fit_start",
"||",
"end_of_last_entry",
",",
"1",
",",
"crc32",
"]",
"@entries",
".",
"insert",
"(",
"best_fit_index",
",",
"entry",
")",
"@entries_by_id",
"[",
"id",
"]",
"=",
"entry",
"entry",
"[",
"START",
"]",
"end"
] | Reserve the bytes needed for the specified number of bytes with the
given ID.
@param id [Integer] ID of the entry
@param bytes [Integer] number of bytes for this entry
@return [Integer] the start address of the reserved blob | [
"Reserve",
"the",
"bytes",
"needed",
"for",
"the",
"specified",
"number",
"of",
"bytes",
"with",
"the",
"given",
"ID",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTreeBlob.rb#L242-L289 | train |
scrapper/perobs | lib/perobs/PersistentObjectCache.rb | PEROBS.PersistentObjectCache.get | def get(uid, ref = nil)
# First check if it's a modified object.
if (object = @modified_entries[uid])
return object
end
# Then check the unmodified object list.
if (object = @unmodified_entries[uid % @size]) && object.uid == uid
return object
end
# If we don't have it in memory we need to load it.
@klass::load(@collection, uid, ref)
end | ruby | def get(uid, ref = nil)
# First check if it's a modified object.
if (object = @modified_entries[uid])
return object
end
# Then check the unmodified object list.
if (object = @unmodified_entries[uid % @size]) && object.uid == uid
return object
end
# If we don't have it in memory we need to load it.
@klass::load(@collection, uid, ref)
end | [
"def",
"get",
"(",
"uid",
",",
"ref",
"=",
"nil",
")",
"if",
"(",
"object",
"=",
"@modified_entries",
"[",
"uid",
"]",
")",
"return",
"object",
"end",
"if",
"(",
"object",
"=",
"@unmodified_entries",
"[",
"uid",
"%",
"@size",
"]",
")",
"&&",
"object",
".",
"uid",
"==",
"uid",
"return",
"object",
"end",
"@klass",
"::",
"load",
"(",
"@collection",
",",
"uid",
",",
"ref",
")",
"end"
] | Retrieve a object reference from the cache.
@param uid [Integer] uid of the object to retrieve.
@param ref [Object] optional reference to be used by the load method | [
"Retrieve",
"a",
"object",
"reference",
"from",
"the",
"cache",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/PersistentObjectCache.rb#L84-L97 | train |
scrapper/perobs | lib/perobs/PersistentObjectCache.rb | PEROBS.PersistentObjectCache.delete | def delete(uid)
@modified_entries.delete(uid)
index = uid % @size
if (object = @unmodified_entries[index]) && object.uid == uid
@unmodified_entries[index] = nil
end
end | ruby | def delete(uid)
@modified_entries.delete(uid)
index = uid % @size
if (object = @unmodified_entries[index]) && object.uid == uid
@unmodified_entries[index] = nil
end
end | [
"def",
"delete",
"(",
"uid",
")",
"@modified_entries",
".",
"delete",
"(",
"uid",
")",
"index",
"=",
"uid",
"%",
"@size",
"if",
"(",
"object",
"=",
"@unmodified_entries",
"[",
"index",
"]",
")",
"&&",
"object",
".",
"uid",
"==",
"uid",
"@unmodified_entries",
"[",
"index",
"]",
"=",
"nil",
"end",
"end"
] | Remove a object from the cache.
@param uid [Integer] unique ID of object to remove. | [
"Remove",
"a",
"object",
"from",
"the",
"cache",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/PersistentObjectCache.rb#L101-L108 | train |
scrapper/perobs | lib/perobs/PersistentObjectCache.rb | PEROBS.PersistentObjectCache.flush | def flush(now = false)
if now || (@flush_counter -= 1) <= 0
@modified_entries.each do |id, object|
object.save
end
@modified_entries = ::Hash.new
@flush_counter = @flush_delay
end
@flush_times += 1
end | ruby | def flush(now = false)
if now || (@flush_counter -= 1) <= 0
@modified_entries.each do |id, object|
object.save
end
@modified_entries = ::Hash.new
@flush_counter = @flush_delay
end
@flush_times += 1
end | [
"def",
"flush",
"(",
"now",
"=",
"false",
")",
"if",
"now",
"||",
"(",
"@flush_counter",
"-=",
"1",
")",
"<=",
"0",
"@modified_entries",
".",
"each",
"do",
"|",
"id",
",",
"object",
"|",
"object",
".",
"save",
"end",
"@modified_entries",
"=",
"::",
"Hash",
".",
"new",
"@flush_counter",
"=",
"@flush_delay",
"end",
"@flush_times",
"+=",
"1",
"end"
] | Write all excess modified objects into the backing store. If now is true
all modified objects will be written.
@param now [Boolean] | [
"Write",
"all",
"excess",
"modified",
"objects",
"into",
"the",
"backing",
"store",
".",
"If",
"now",
"is",
"true",
"all",
"modified",
"objects",
"will",
"be",
"written",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/PersistentObjectCache.rb#L113-L122 | train |
PublicHealthEngland/ndr_support | lib/ndr_support/utf8_encoding/control_characters.rb | UTF8Encoding.ControlCharacters.escape_control_chars_in_object! | def escape_control_chars_in_object!(object)
case object
when String
escape_control_chars!(object)
when Hash
escape_control_chars_in_hash!(object)
when Array
escape_control_chars_in_array!(object)
else
object
end
end | ruby | def escape_control_chars_in_object!(object)
case object
when String
escape_control_chars!(object)
when Hash
escape_control_chars_in_hash!(object)
when Array
escape_control_chars_in_array!(object)
else
object
end
end | [
"def",
"escape_control_chars_in_object!",
"(",
"object",
")",
"case",
"object",
"when",
"String",
"escape_control_chars!",
"(",
"object",
")",
"when",
"Hash",
"escape_control_chars_in_hash!",
"(",
"object",
")",
"when",
"Array",
"escape_control_chars_in_array!",
"(",
"object",
")",
"else",
"object",
"end",
"end"
] | Recursively escape any control characters in `object`. | [
"Recursively",
"escape",
"any",
"control",
"characters",
"in",
"object",
"."
] | 6daf98ca972e79de1c8457eb720f058b03ead21c | https://github.com/PublicHealthEngland/ndr_support/blob/6daf98ca972e79de1c8457eb720f058b03ead21c/lib/ndr_support/utf8_encoding/control_characters.rb#L11-L22 | train |
PublicHealthEngland/ndr_support | lib/ndr_support/utf8_encoding/control_characters.rb | UTF8Encoding.ControlCharacters.escape_control_chars! | def escape_control_chars!(string)
string.gsub!(CONTROL_CHARACTERS) do |character|
UTF8Encoding::REPLACEMENT_SCHEME[character]
end
string
end | ruby | def escape_control_chars!(string)
string.gsub!(CONTROL_CHARACTERS) do |character|
UTF8Encoding::REPLACEMENT_SCHEME[character]
end
string
end | [
"def",
"escape_control_chars!",
"(",
"string",
")",
"string",
".",
"gsub!",
"(",
"CONTROL_CHARACTERS",
")",
"do",
"|",
"character",
"|",
"UTF8Encoding",
"::",
"REPLACEMENT_SCHEME",
"[",
"character",
"]",
"end",
"string",
"end"
] | Escapes in-place any control characters in `string`, before returning it. | [
"Escapes",
"in",
"-",
"place",
"any",
"control",
"characters",
"in",
"string",
"before",
"returning",
"it",
"."
] | 6daf98ca972e79de1c8457eb720f058b03ead21c | https://github.com/PublicHealthEngland/ndr_support/blob/6daf98ca972e79de1c8457eb720f058b03ead21c/lib/ndr_support/utf8_encoding/control_characters.rb#L30-L35 | train |
ghempton/state_manager | lib/state_manager/state.rb | StateManager.State.find_states | def find_states(path)
state = self
parts = path.split('.')
ret = []
parts.each do |name|
state = state.states[name.to_sym]
ret << state
return unless state
end
ret
end | ruby | def find_states(path)
state = self
parts = path.split('.')
ret = []
parts.each do |name|
state = state.states[name.to_sym]
ret << state
return unless state
end
ret
end | [
"def",
"find_states",
"(",
"path",
")",
"state",
"=",
"self",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
"ret",
"=",
"[",
"]",
"parts",
".",
"each",
"do",
"|",
"name",
"|",
"state",
"=",
"state",
".",
"states",
"[",
"name",
".",
"to_sym",
"]",
"ret",
"<<",
"state",
"return",
"unless",
"state",
"end",
"ret",
"end"
] | Find all the states along the path | [
"Find",
"all",
"the",
"states",
"along",
"the",
"path"
] | 0e10fbb3c4b7718aa6602e240f4d8adf9cd72008 | https://github.com/ghempton/state_manager/blob/0e10fbb3c4b7718aa6602e240f4d8adf9cd72008/lib/state_manager/state.rb#L108-L118 | train |
ghempton/state_manager | lib/state_manager/state.rb | StateManager.State.initial_state | def initial_state
if state = self.class.specification.initial_state
find_state(state.to_s)
elsif leaf?
self
else
states.values.first.initial_state
end
end | ruby | def initial_state
if state = self.class.specification.initial_state
find_state(state.to_s)
elsif leaf?
self
else
states.values.first.initial_state
end
end | [
"def",
"initial_state",
"if",
"state",
"=",
"self",
".",
"class",
".",
"specification",
".",
"initial_state",
"find_state",
"(",
"state",
".",
"to_s",
")",
"elsif",
"leaf?",
"self",
"else",
"states",
".",
"values",
".",
"first",
".",
"initial_state",
"end",
"end"
] | If an initial state is not explicitly specified, we choose the first leaf
state | [
"If",
"an",
"initial",
"state",
"is",
"not",
"explicitly",
"specified",
"we",
"choose",
"the",
"first",
"leaf",
"state"
] | 0e10fbb3c4b7718aa6602e240f4d8adf9cd72008 | https://github.com/ghempton/state_manager/blob/0e10fbb3c4b7718aa6602e240f4d8adf9cd72008/lib/state_manager/state.rb#L132-L140 | train |
scrapper/perobs | lib/perobs/BTree.rb | PEROBS.BTree.open | def open(file_must_exist = false)
if @dirty_flag.is_locked?
PEROBS.log.fatal "Index file #{@nodes.file_name} is already " +
"locked"
end
if file_must_exist && [email protected]_exist?
PEROBS.log.fatal "Index file #{@nodes.file_name} does not exist"
end
@node_cache.clear
@nodes.open
if @nodes.total_entries == 0
# We've created a new nodes file
node = BTreeNode::create(self)
else
# We are loading an existing tree.
node = BTreeNode::load_and_link(self, @nodes.first_entry)
@first_leaf = BTreeNode::load_and_link(
self, @nodes.get_custom_data('first_leaf'))
@last_leaf = BTreeNode::load_and_link(
self, @nodes.get_custom_data('last_leaf'))
end
set_root(node)
# Get the total number of entries that are stored in the tree.
@size = @nodes.get_custom_data('btree_size')
end | ruby | def open(file_must_exist = false)
if @dirty_flag.is_locked?
PEROBS.log.fatal "Index file #{@nodes.file_name} is already " +
"locked"
end
if file_must_exist && [email protected]_exist?
PEROBS.log.fatal "Index file #{@nodes.file_name} does not exist"
end
@node_cache.clear
@nodes.open
if @nodes.total_entries == 0
# We've created a new nodes file
node = BTreeNode::create(self)
else
# We are loading an existing tree.
node = BTreeNode::load_and_link(self, @nodes.first_entry)
@first_leaf = BTreeNode::load_and_link(
self, @nodes.get_custom_data('first_leaf'))
@last_leaf = BTreeNode::load_and_link(
self, @nodes.get_custom_data('last_leaf'))
end
set_root(node)
# Get the total number of entries that are stored in the tree.
@size = @nodes.get_custom_data('btree_size')
end | [
"def",
"open",
"(",
"file_must_exist",
"=",
"false",
")",
"if",
"@dirty_flag",
".",
"is_locked?",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Index file #{@nodes.file_name} is already \"",
"+",
"\"locked\"",
"end",
"if",
"file_must_exist",
"&&",
"!",
"@nodes",
".",
"file_exist?",
"PEROBS",
".",
"log",
".",
"fatal",
"\"Index file #{@nodes.file_name} does not exist\"",
"end",
"@node_cache",
".",
"clear",
"@nodes",
".",
"open",
"if",
"@nodes",
".",
"total_entries",
"==",
"0",
"node",
"=",
"BTreeNode",
"::",
"create",
"(",
"self",
")",
"else",
"node",
"=",
"BTreeNode",
"::",
"load_and_link",
"(",
"self",
",",
"@nodes",
".",
"first_entry",
")",
"@first_leaf",
"=",
"BTreeNode",
"::",
"load_and_link",
"(",
"self",
",",
"@nodes",
".",
"get_custom_data",
"(",
"'first_leaf'",
")",
")",
"@last_leaf",
"=",
"BTreeNode",
"::",
"load_and_link",
"(",
"self",
",",
"@nodes",
".",
"get_custom_data",
"(",
"'last_leaf'",
")",
")",
"end",
"set_root",
"(",
"node",
")",
"@size",
"=",
"@nodes",
".",
"get_custom_data",
"(",
"'btree_size'",
")",
"end"
] | Create a new BTree object.
@param dir [String] Directory to store the tree file
@param name [String] Base name of the BTree related files in 'dir'
@param order [Integer] The maximum number of keys per node. This number
must be odd and larger than 2 and smaller than 2**16 - 1.
@param progressmeter [ProgressMeter] reference to a ProgressMeter object
Open the tree file. | [
"Create",
"a",
"new",
"BTree",
"object",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTree.rb#L89-L116 | train |
scrapper/perobs | lib/perobs/BTree.rb | PEROBS.BTree.check | def check(&block)
sync
return false unless @nodes.check
entries = 0
res = true
@progressmeter.start('Checking index structure', @size) do |pm|
res = @root.check do |k, v|
pm.update(entries += 1)
block_given? ? yield(k, v) : true
end
end
unless entries == @size
PEROBS.log.error "The BTree size (#{@size}) and the number of " +
"found entries (#{entries}) don't match"
return false
end
res
end | ruby | def check(&block)
sync
return false unless @nodes.check
entries = 0
res = true
@progressmeter.start('Checking index structure', @size) do |pm|
res = @root.check do |k, v|
pm.update(entries += 1)
block_given? ? yield(k, v) : true
end
end
unless entries == @size
PEROBS.log.error "The BTree size (#{@size}) and the number of " +
"found entries (#{entries}) don't match"
return false
end
res
end | [
"def",
"check",
"(",
"&",
"block",
")",
"sync",
"return",
"false",
"unless",
"@nodes",
".",
"check",
"entries",
"=",
"0",
"res",
"=",
"true",
"@progressmeter",
".",
"start",
"(",
"'Checking index structure'",
",",
"@size",
")",
"do",
"|",
"pm",
"|",
"res",
"=",
"@root",
".",
"check",
"do",
"|",
"k",
",",
"v",
"|",
"pm",
".",
"update",
"(",
"entries",
"+=",
"1",
")",
"block_given?",
"?",
"yield",
"(",
"k",
",",
"v",
")",
":",
"true",
"end",
"end",
"unless",
"entries",
"==",
"@size",
"PEROBS",
".",
"log",
".",
"error",
"\"The BTree size (#{@size}) and the number of \"",
"+",
"\"found entries (#{entries}) don't match\"",
"return",
"false",
"end",
"res",
"end"
] | Check if the tree file contains any errors.
@return [Boolean] true if no erros were found, false otherwise | [
"Check",
"if",
"the",
"tree",
"file",
"contains",
"any",
"errors",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTree.rb#L163-L183 | train |
scrapper/perobs | lib/perobs/BTree.rb | PEROBS.BTree.remove | def remove(key)
@size -= 1 unless (removed_value = @root.remove(key)).nil?
# Check if the root node only contains one child link after the delete
# operation. Then we can delete that node and pull the tree one level
# up. This could happen for a sequence of nodes that all got merged to
# single child nodes.
while [email protected]_leaf && @root.children.size == 1
old_root = @root
set_root(@root.children.first)
@root.parent = nil
delete_node(old_root.node_address)
end
@node_cache.flush
removed_value
end | ruby | def remove(key)
@size -= 1 unless (removed_value = @root.remove(key)).nil?
# Check if the root node only contains one child link after the delete
# operation. Then we can delete that node and pull the tree one level
# up. This could happen for a sequence of nodes that all got merged to
# single child nodes.
while [email protected]_leaf && @root.children.size == 1
old_root = @root
set_root(@root.children.first)
@root.parent = nil
delete_node(old_root.node_address)
end
@node_cache.flush
removed_value
end | [
"def",
"remove",
"(",
"key",
")",
"@size",
"-=",
"1",
"unless",
"(",
"removed_value",
"=",
"@root",
".",
"remove",
"(",
"key",
")",
")",
".",
"nil?",
"while",
"!",
"@root",
".",
"is_leaf",
"&&",
"@root",
".",
"children",
".",
"size",
"==",
"1",
"old_root",
"=",
"@root",
"set_root",
"(",
"@root",
".",
"children",
".",
"first",
")",
"@root",
".",
"parent",
"=",
"nil",
"delete_node",
"(",
"old_root",
".",
"node_address",
")",
"end",
"@node_cache",
".",
"flush",
"removed_value",
"end"
] | Find and remove the value associated with the given key. If no entry was
found, return nil, otherwise the found value. | [
"Find",
"and",
"remove",
"the",
"value",
"associated",
"with",
"the",
"given",
"key",
".",
"If",
"no",
"entry",
"was",
"found",
"return",
"nil",
"otherwise",
"the",
"found",
"value",
"."
] | 1c9327656912cf96683849f92d260546af856adf | https://github.com/scrapper/perobs/blob/1c9327656912cf96683849f92d260546af856adf/lib/perobs/BTree.rb#L225-L241 | train |
proglottis/glicko2 | lib/glicko2/rater.rb | Glicko2.Rater.add | def add(other_rating, score)
g, e = other_rating.gravity_expected_score(rating.mean)
@v_pre += g**2 * e * (1 - e)
@delta_pre += g * (score - e)
end | ruby | def add(other_rating, score)
g, e = other_rating.gravity_expected_score(rating.mean)
@v_pre += g**2 * e * (1 - e)
@delta_pre += g * (score - e)
end | [
"def",
"add",
"(",
"other_rating",
",",
"score",
")",
"g",
",",
"e",
"=",
"other_rating",
".",
"gravity_expected_score",
"(",
"rating",
".",
"mean",
")",
"@v_pre",
"+=",
"g",
"**",
"2",
"*",
"e",
"*",
"(",
"1",
"-",
"e",
")",
"@delta_pre",
"+=",
"g",
"*",
"(",
"score",
"-",
"e",
")",
"end"
] | Add an outcome against the rating | [
"Add",
"an",
"outcome",
"against",
"the",
"rating"
] | 8ede9a758a1a35b2bc5e6d4706aad856ec8f7812 | https://github.com/proglottis/glicko2/blob/8ede9a758a1a35b2bc5e6d4706aad856ec8f7812/lib/glicko2/rater.rb#L13-L17 | train |
proglottis/glicko2 | lib/glicko2/rater.rb | Glicko2.Rater.rate | def rate(tau)
v = @v_pre**-1
delta2 = (@delta_pre * v)**2
sd2 = rating.sd**2
a = Math.log(rating.volatility**2)
if v.finite?
f = lambda do |x|
expX = Math.exp(x)
(expX * (delta2 - sd2 - v - expX)) / (2 * (sd2 + v + expX)**2) - (x - a) / tau**2
end
if delta2 > sd2 + v
b = Math.log(delta2 - sd2 - v)
else
k = 1
k += 1 while f.call(a - k * tau) < 0
b = a - k * tau
end
a = Util.illinois_method(a, b, &f)
end
volatility = Math.exp(a / 2.0)
sd_pre = Math.sqrt(sd2 + volatility**2)
sd = 1 / Math.sqrt(1.0 / sd_pre**2 + 1 / v)
mean = rating.mean + sd**2 * @delta_pre
Rating.new(mean, sd, volatility)
end | ruby | def rate(tau)
v = @v_pre**-1
delta2 = (@delta_pre * v)**2
sd2 = rating.sd**2
a = Math.log(rating.volatility**2)
if v.finite?
f = lambda do |x|
expX = Math.exp(x)
(expX * (delta2 - sd2 - v - expX)) / (2 * (sd2 + v + expX)**2) - (x - a) / tau**2
end
if delta2 > sd2 + v
b = Math.log(delta2 - sd2 - v)
else
k = 1
k += 1 while f.call(a - k * tau) < 0
b = a - k * tau
end
a = Util.illinois_method(a, b, &f)
end
volatility = Math.exp(a / 2.0)
sd_pre = Math.sqrt(sd2 + volatility**2)
sd = 1 / Math.sqrt(1.0 / sd_pre**2 + 1 / v)
mean = rating.mean + sd**2 * @delta_pre
Rating.new(mean, sd, volatility)
end | [
"def",
"rate",
"(",
"tau",
")",
"v",
"=",
"@v_pre",
"**",
"-",
"1",
"delta2",
"=",
"(",
"@delta_pre",
"*",
"v",
")",
"**",
"2",
"sd2",
"=",
"rating",
".",
"sd",
"**",
"2",
"a",
"=",
"Math",
".",
"log",
"(",
"rating",
".",
"volatility",
"**",
"2",
")",
"if",
"v",
".",
"finite?",
"f",
"=",
"lambda",
"do",
"|",
"x",
"|",
"expX",
"=",
"Math",
".",
"exp",
"(",
"x",
")",
"(",
"expX",
"*",
"(",
"delta2",
"-",
"sd2",
"-",
"v",
"-",
"expX",
")",
")",
"/",
"(",
"2",
"*",
"(",
"sd2",
"+",
"v",
"+",
"expX",
")",
"**",
"2",
")",
"-",
"(",
"x",
"-",
"a",
")",
"/",
"tau",
"**",
"2",
"end",
"if",
"delta2",
">",
"sd2",
"+",
"v",
"b",
"=",
"Math",
".",
"log",
"(",
"delta2",
"-",
"sd2",
"-",
"v",
")",
"else",
"k",
"=",
"1",
"k",
"+=",
"1",
"while",
"f",
".",
"call",
"(",
"a",
"-",
"k",
"*",
"tau",
")",
"<",
"0",
"b",
"=",
"a",
"-",
"k",
"*",
"tau",
"end",
"a",
"=",
"Util",
".",
"illinois_method",
"(",
"a",
",",
"b",
",",
"&",
"f",
")",
"end",
"volatility",
"=",
"Math",
".",
"exp",
"(",
"a",
"/",
"2.0",
")",
"sd_pre",
"=",
"Math",
".",
"sqrt",
"(",
"sd2",
"+",
"volatility",
"**",
"2",
")",
"sd",
"=",
"1",
"/",
"Math",
".",
"sqrt",
"(",
"1.0",
"/",
"sd_pre",
"**",
"2",
"+",
"1",
"/",
"v",
")",
"mean",
"=",
"rating",
".",
"mean",
"+",
"sd",
"**",
"2",
"*",
"@delta_pre",
"Rating",
".",
"new",
"(",
"mean",
",",
"sd",
",",
"volatility",
")",
"end"
] | Rate calculates Rating as at the start of the following period based on game outcomes | [
"Rate",
"calculates",
"Rating",
"as",
"at",
"the",
"start",
"of",
"the",
"following",
"period",
"based",
"on",
"game",
"outcomes"
] | 8ede9a758a1a35b2bc5e6d4706aad856ec8f7812 | https://github.com/proglottis/glicko2/blob/8ede9a758a1a35b2bc5e6d4706aad856ec8f7812/lib/glicko2/rater.rb#L20-L44 | train |
kristianmandrup/schemaker | lib/schemaker/models.rb | Schemaker.Models.configure | def configure
return quick_join if !join_model
[subject_model, object_model, join_model].compact.each do |model|
model.configure
end
end | ruby | def configure
return quick_join if !join_model
[subject_model, object_model, join_model].compact.each do |model|
model.configure
end
end | [
"def",
"configure",
"return",
"quick_join",
"if",
"!",
"join_model",
"[",
"subject_model",
",",
"object_model",
",",
"join_model",
"]",
".",
"compact",
".",
"each",
"do",
"|",
"model",
"|",
"model",
".",
"configure",
"end",
"end"
] | configure each model in turn | [
"configure",
"each",
"model",
"in",
"turn"
] | 47399410cc6785291c656cec6cc2b9aa47f3652a | https://github.com/kristianmandrup/schemaker/blob/47399410cc6785291c656cec6cc2b9aa47f3652a/lib/schemaker/models.rb#L47-L52 | train |
kristianmandrup/schemaker | lib/schemaker/models.rb | Schemaker.Models.get_class | def get_class type
case type
when Class
type
when BaseModel
type.my_class
when String, Symbol
return get_class send("#{type}_model") if [:subject, :object, :join].include?(type.to_sym)
type.to_s.constantize
else
raise "Can't determine a class from: #{type}"
end
end | ruby | def get_class type
case type
when Class
type
when BaseModel
type.my_class
when String, Symbol
return get_class send("#{type}_model") if [:subject, :object, :join].include?(type.to_sym)
type.to_s.constantize
else
raise "Can't determine a class from: #{type}"
end
end | [
"def",
"get_class",
"type",
"case",
"type",
"when",
"Class",
"type",
"when",
"BaseModel",
"type",
".",
"my_class",
"when",
"String",
",",
"Symbol",
"return",
"get_class",
"send",
"(",
"\"#{type}_model\"",
")",
"if",
"[",
":subject",
",",
":object",
",",
":join",
"]",
".",
"include?",
"(",
"type",
".",
"to_sym",
")",
"type",
".",
"to_s",
".",
"constantize",
"else",
"raise",
"\"Can't determine a class from: #{type}\"",
"end",
"end"
] | retrieves a given Class ie. a type of model
@param [Class, String, Symbol, BaseModel] which class to get
@return [Class] the Class (model) of interest | [
"retrieves",
"a",
"given",
"Class",
"ie",
".",
"a",
"type",
"of",
"model"
] | 47399410cc6785291c656cec6cc2b9aa47f3652a | https://github.com/kristianmandrup/schemaker/blob/47399410cc6785291c656cec6cc2b9aa47f3652a/lib/schemaker/models.rb#L84-L96 | train |
jcmuller/build_status_server | lib/build_status_server/config.rb | BuildStatusServer.Config.load_config_file | def load_config_file(config_file = nil)
curated_file = nil
if config_file
f = File.expand_path(config_file)
if File.exists?(f)
curated_file = f
else
raise "Supplied config file (#{config_file}) doesn't seem to exist"
end
else
locations_to_try.each do |possible_conf_file|
f = File.expand_path(possible_conf_file)
if File.exists?(f)
curated_file = f
break
end
end
if curated_file.nil?
show_config_file_suggestion
return YAML.load(get_example_config)
end
end
YAML.load_file(curated_file).tap do |config|
raise "This is an invalid configuration file!" unless config.class == Hash
end
end | ruby | def load_config_file(config_file = nil)
curated_file = nil
if config_file
f = File.expand_path(config_file)
if File.exists?(f)
curated_file = f
else
raise "Supplied config file (#{config_file}) doesn't seem to exist"
end
else
locations_to_try.each do |possible_conf_file|
f = File.expand_path(possible_conf_file)
if File.exists?(f)
curated_file = f
break
end
end
if curated_file.nil?
show_config_file_suggestion
return YAML.load(get_example_config)
end
end
YAML.load_file(curated_file).tap do |config|
raise "This is an invalid configuration file!" unless config.class == Hash
end
end | [
"def",
"load_config_file",
"(",
"config_file",
"=",
"nil",
")",
"curated_file",
"=",
"nil",
"if",
"config_file",
"f",
"=",
"File",
".",
"expand_path",
"(",
"config_file",
")",
"if",
"File",
".",
"exists?",
"(",
"f",
")",
"curated_file",
"=",
"f",
"else",
"raise",
"\"Supplied config file (#{config_file}) doesn't seem to exist\"",
"end",
"else",
"locations_to_try",
".",
"each",
"do",
"|",
"possible_conf_file",
"|",
"f",
"=",
"File",
".",
"expand_path",
"(",
"possible_conf_file",
")",
"if",
"File",
".",
"exists?",
"(",
"f",
")",
"curated_file",
"=",
"f",
"break",
"end",
"end",
"if",
"curated_file",
".",
"nil?",
"show_config_file_suggestion",
"return",
"YAML",
".",
"load",
"(",
"get_example_config",
")",
"end",
"end",
"YAML",
".",
"load_file",
"(",
"curated_file",
")",
".",
"tap",
"do",
"|",
"config",
"|",
"raise",
"\"This is an invalid configuration file!\"",
"unless",
"config",
".",
"class",
"==",
"Hash",
"end",
"end"
] | This is responsible to return a hash with the contents of a YAML file | [
"This",
"is",
"responsible",
"to",
"return",
"a",
"hash",
"with",
"the",
"contents",
"of",
"a",
"YAML",
"file"
] | 1a8329512ef6ee6dd01e886f5c7b68d0e22523df | https://github.com/jcmuller/build_status_server/blob/1a8329512ef6ee6dd01e886f5c7b68d0e22523df/lib/build_status_server/config.rb#L29-L58 | train |
thelabtech/questionnaire | app/helpers/qe/answer_pages_helper.rb | Qe.AnswerPagesHelper.li_page_active_if | def li_page_active_if(condition, attributes = {}, &block)
if condition
attributes[:class] ||= ''
attributes[:class] += " active"
end
content_tag("li", attributes, &block)
end | ruby | def li_page_active_if(condition, attributes = {}, &block)
if condition
attributes[:class] ||= ''
attributes[:class] += " active"
end
content_tag("li", attributes, &block)
end | [
"def",
"li_page_active_if",
"(",
"condition",
",",
"attributes",
"=",
"{",
"}",
",",
"&",
"block",
")",
"if",
"condition",
"attributes",
"[",
":class",
"]",
"||=",
"''",
"attributes",
"[",
":class",
"]",
"+=",
"\" active\"",
"end",
"content_tag",
"(",
"\"li\"",
",",
"attributes",
",",
"&",
"block",
")",
"end"
] | page sidebar navigation | [
"page",
"sidebar",
"navigation"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/helpers/qe/answer_pages_helper.rb#L7-L13 | train |
sleewoo/minispec | lib/minispec/api/class/after.rb | MiniSpec.ClassAPI.after | def after *matchers, &proc
proc || raise(ArgumentError, 'block is missing')
matchers.flatten!
matchers = [:*] if matchers.empty?
return if after?.find {|x| x[0] == matchers && x[1].source_location == proc.source_location}
after?.push([matchers, proc])
end | ruby | def after *matchers, &proc
proc || raise(ArgumentError, 'block is missing')
matchers.flatten!
matchers = [:*] if matchers.empty?
return if after?.find {|x| x[0] == matchers && x[1].source_location == proc.source_location}
after?.push([matchers, proc])
end | [
"def",
"after",
"*",
"matchers",
",",
"&",
"proc",
"proc",
"||",
"raise",
"(",
"ArgumentError",
",",
"'block is missing'",
")",
"matchers",
".",
"flatten!",
"matchers",
"=",
"[",
":*",
"]",
"if",
"matchers",
".",
"empty?",
"return",
"if",
"after?",
".",
"find",
"{",
"|",
"x",
"|",
"x",
"[",
"0",
"]",
"==",
"matchers",
"&&",
"x",
"[",
"1",
"]",
".",
"source_location",
"==",
"proc",
".",
"source_location",
"}",
"after?",
".",
"push",
"(",
"[",
"matchers",
",",
"proc",
"]",
")",
"end"
] | same as `before` except it will run after matched tests.
@note `after` hooks will run even on failed tests.
however it wont run if some exception arise inside test. | [
"same",
"as",
"before",
"except",
"it",
"will",
"run",
"after",
"matched",
"tests",
"."
] | 6dcdacd041cc031c21f2fe70b6e5b22c6af636c5 | https://github.com/sleewoo/minispec/blob/6dcdacd041cc031c21f2fe70b6e5b22c6af636c5/lib/minispec/api/class/after.rb#L7-L13 | train |
rossmeissl/bombshell | lib/bombshell/shell.rb | Bombshell.Shell._prompt | def _prompt
if self.class.bombshell_prompt.is_a? String
self.class.bombshell_prompt
elsif self.class.bombshell_prompt.is_a? Proc and self.class.bombshell_prompt.arity == 1
self.class.bombshell_prompt.call self
elsif self.class.bombshell_prompt.is_a? Proc
self.class.bombshell_prompt.call
else
'[Bombshell]'
end
end | ruby | def _prompt
if self.class.bombshell_prompt.is_a? String
self.class.bombshell_prompt
elsif self.class.bombshell_prompt.is_a? Proc and self.class.bombshell_prompt.arity == 1
self.class.bombshell_prompt.call self
elsif self.class.bombshell_prompt.is_a? Proc
self.class.bombshell_prompt.call
else
'[Bombshell]'
end
end | [
"def",
"_prompt",
"if",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"is_a?",
"String",
"self",
".",
"class",
".",
"bombshell_prompt",
"elsif",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"is_a?",
"Proc",
"and",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"arity",
"==",
"1",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"call",
"self",
"elsif",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"is_a?",
"Proc",
"self",
".",
"class",
".",
"bombshell_prompt",
".",
"call",
"else",
"'[Bombshell]'",
"end",
"end"
] | Render and return your shell's prompt.
You can define the prompt with <tt>MyShell.prompt_with</tt> and access it without rendering with <tt>MyShell.bombshell_prompt</tt>.
@see ClassMethods#prompt_with
@see ClassMethods#bombshell_prompt
@return String | [
"Render",
"and",
"return",
"your",
"shell",
"s",
"prompt",
"."
] | 542c855eb741095b1e88cc1bbfa1c1bacfcd9ebd | https://github.com/rossmeissl/bombshell/blob/542c855eb741095b1e88cc1bbfa1c1bacfcd9ebd/lib/bombshell/shell.rb#L26-L36 | train |
christianhellsten/guard-bundler-audit | lib/guard/bundler_audit.rb | Guard.BundlerAudit.audit | def audit
res = ::Bundler::Audit::Scanner.new.scan.to_a.map do |vuln|
case vuln
when ::Bundler::Audit::Scanner::InsecureSource
insecure_source_message vuln
when ::Bundler::Audit::Scanner::UnpatchedGem
insecure_gem_message vuln
else
insecure_message vuln
end
end
if res.any?
message = "Vulnerabilities found:\n" + res.join("\n")
color = :red
notify message
else
message = "No vulnerabilities found."
color = :green
end
UI.info(UI.send(:color, message, color))
end | ruby | def audit
res = ::Bundler::Audit::Scanner.new.scan.to_a.map do |vuln|
case vuln
when ::Bundler::Audit::Scanner::InsecureSource
insecure_source_message vuln
when ::Bundler::Audit::Scanner::UnpatchedGem
insecure_gem_message vuln
else
insecure_message vuln
end
end
if res.any?
message = "Vulnerabilities found:\n" + res.join("\n")
color = :red
notify message
else
message = "No vulnerabilities found."
color = :green
end
UI.info(UI.send(:color, message, color))
end | [
"def",
"audit",
"res",
"=",
"::",
"Bundler",
"::",
"Audit",
"::",
"Scanner",
".",
"new",
".",
"scan",
".",
"to_a",
".",
"map",
"do",
"|",
"vuln",
"|",
"case",
"vuln",
"when",
"::",
"Bundler",
"::",
"Audit",
"::",
"Scanner",
"::",
"InsecureSource",
"insecure_source_message",
"vuln",
"when",
"::",
"Bundler",
"::",
"Audit",
"::",
"Scanner",
"::",
"UnpatchedGem",
"insecure_gem_message",
"vuln",
"else",
"insecure_message",
"vuln",
"end",
"end",
"if",
"res",
".",
"any?",
"message",
"=",
"\"Vulnerabilities found:\\n\"",
"+",
"res",
".",
"join",
"(",
"\"\\n\"",
")",
"color",
"=",
":red",
"notify",
"message",
"else",
"message",
"=",
"\"No vulnerabilities found.\"",
"color",
"=",
":green",
"end",
"UI",
".",
"info",
"(",
"UI",
".",
"send",
"(",
":color",
",",
"message",
",",
"color",
")",
")",
"end"
] | Scans for vulnerabilities and reports them. | [
"Scans",
"for",
"vulnerabilities",
"and",
"reports",
"them",
"."
] | 0b9d51c8a3bdd08c8eb1406ef171da97633d4c72 | https://github.com/christianhellsten/guard-bundler-audit/blob/0b9d51c8a3bdd08c8eb1406ef171da97633d4c72/lib/guard/bundler_audit.rb#L35-L55 | train |
zerowidth/camper_van | lib/camper_van/ircd.rb | CamperVan.IRCD.receive_line | def receive_line(line)
if @active
cmd = parse(line)
handle cmd
end
rescue HandlerMissing
logger.info "ignoring irc command #{cmd.inspect}: no handler"
end | ruby | def receive_line(line)
if @active
cmd = parse(line)
handle cmd
end
rescue HandlerMissing
logger.info "ignoring irc command #{cmd.inspect}: no handler"
end | [
"def",
"receive_line",
"(",
"line",
")",
"if",
"@active",
"cmd",
"=",
"parse",
"(",
"line",
")",
"handle",
"cmd",
"end",
"rescue",
"HandlerMissing",
"logger",
".",
"info",
"\"ignoring irc command #{cmd.inspect}: no handler\"",
"end"
] | Handler for when a client sends an IRC command | [
"Handler",
"for",
"when",
"a",
"client",
"sends",
"an",
"IRC",
"command"
] | 984351a3b472e936a451f1d1cd987ca27d981d23 | https://github.com/zerowidth/camper_van/blob/984351a3b472e936a451f1d1cd987ca27d981d23/lib/camper_van/ircd.rb#L74-L81 | train |
zerowidth/camper_van | lib/camper_van/ircd.rb | CamperVan.IRCD.check_campfire_authentication | def check_campfire_authentication(&callback)
# invalid user only returns a nil result!
campfire.user("me") do |user|
if user.name
yield
else
command_reply :notice, "AUTH", "could not connect to campfire: invalid API key"
shutdown
end
end
rescue Firering::Connection::HTTPError => e
command_reply :notice, "AUTH", "could not connect to campfire: #{e.message}"
shutdown
end | ruby | def check_campfire_authentication(&callback)
# invalid user only returns a nil result!
campfire.user("me") do |user|
if user.name
yield
else
command_reply :notice, "AUTH", "could not connect to campfire: invalid API key"
shutdown
end
end
rescue Firering::Connection::HTTPError => e
command_reply :notice, "AUTH", "could not connect to campfire: #{e.message}"
shutdown
end | [
"def",
"check_campfire_authentication",
"(",
"&",
"callback",
")",
"campfire",
".",
"user",
"(",
"\"me\"",
")",
"do",
"|",
"user",
"|",
"if",
"user",
".",
"name",
"yield",
"else",
"command_reply",
":notice",
",",
"\"AUTH\"",
",",
"\"could not connect to campfire: invalid API key\"",
"shutdown",
"end",
"end",
"rescue",
"Firering",
"::",
"Connection",
"::",
"HTTPError",
"=>",
"e",
"command_reply",
":notice",
",",
"\"AUTH\"",
",",
"\"could not connect to campfire: #{e.message}\"",
"shutdown",
"end"
] | Checks that the campfire authentication is successful.
callback - a block to call if successful.
Yields to the callback on success (async)
If it fails, it replies with an error to the client and
disconnects. | [
"Checks",
"that",
"the",
"campfire",
"authentication",
"is",
"successful",
"."
] | 984351a3b472e936a451f1d1cd987ca27d981d23 | https://github.com/zerowidth/camper_van/blob/984351a3b472e936a451f1d1cd987ca27d981d23/lib/camper_van/ircd.rb#L308-L321 | train |
zerowidth/camper_van | lib/camper_van/ircd.rb | CamperVan.IRCD.check_nick_matches_authenticated_user | def check_nick_matches_authenticated_user
campfire.user("me") do |user|
name = irc_name user.name
if name != nick
user_reply :nick, name
@nick = name
end
end
end | ruby | def check_nick_matches_authenticated_user
campfire.user("me") do |user|
name = irc_name user.name
if name != nick
user_reply :nick, name
@nick = name
end
end
end | [
"def",
"check_nick_matches_authenticated_user",
"campfire",
".",
"user",
"(",
"\"me\"",
")",
"do",
"|",
"user",
"|",
"name",
"=",
"irc_name",
"user",
".",
"name",
"if",
"name",
"!=",
"nick",
"user_reply",
":nick",
",",
"name",
"@nick",
"=",
"name",
"end",
"end",
"end"
] | Check to see that the nick as provided during the registration
process matches the authenticated campfire user. If the nicks don't
match, send a nick change to the connected client. | [
"Check",
"to",
"see",
"that",
"the",
"nick",
"as",
"provided",
"during",
"the",
"registration",
"process",
"matches",
"the",
"authenticated",
"campfire",
"user",
".",
"If",
"the",
"nicks",
"don",
"t",
"match",
"send",
"a",
"nick",
"change",
"to",
"the",
"connected",
"client",
"."
] | 984351a3b472e936a451f1d1cd987ca27d981d23 | https://github.com/zerowidth/camper_van/blob/984351a3b472e936a451f1d1cd987ca27d981d23/lib/camper_van/ircd.rb#L326-L334 | train |
godfat/rest-more | lib/rest-core/util/rails_util_util.rb | RestCore::RailsUtilUtil.InstanceMethod.rc_setup | def rc_setup client, options={}
rc_options_ctl(client).merge!(
rc_options_extract(client.members, options, :reject))
rc_options_new(client).merge!(
rc_options_extract(client.members, options, :select))
end | ruby | def rc_setup client, options={}
rc_options_ctl(client).merge!(
rc_options_extract(client.members, options, :reject))
rc_options_new(client).merge!(
rc_options_extract(client.members, options, :select))
end | [
"def",
"rc_setup",
"client",
",",
"options",
"=",
"{",
"}",
"rc_options_ctl",
"(",
"client",
")",
".",
"merge!",
"(",
"rc_options_extract",
"(",
"client",
".",
"members",
",",
"options",
",",
":reject",
")",
")",
"rc_options_new",
"(",
"client",
")",
".",
"merge!",
"(",
"rc_options_extract",
"(",
"client",
".",
"members",
",",
"options",
",",
":select",
")",
")",
"end"
] | to mark below private in controllers | [
"to",
"mark",
"below",
"private",
"in",
"controllers"
] | 7a5faa6a5d3ec3bb2c5ccb447f78e2df0fa727c5 | https://github.com/godfat/rest-more/blob/7a5faa6a5d3ec3bb2c5ccb447f78e2df0fa727c5/lib/rest-core/util/rails_util_util.rb#L24-L30 | train |
flergl/java-properties-for-ruby | lib/java_properties.rb | JavaProperties.Properties.to_s | def to_s
string = ""
# Sort to make testing easier -> output will consistent
@props.sort_by do |key,val|
key.to_s
end.each do |key,val|
string << Encoding.encode(key.to_s) << "=" << Encoding.encode(val) << "\n"
end
string
end | ruby | def to_s
string = ""
# Sort to make testing easier -> output will consistent
@props.sort_by do |key,val|
key.to_s
end.each do |key,val|
string << Encoding.encode(key.to_s) << "=" << Encoding.encode(val) << "\n"
end
string
end | [
"def",
"to_s",
"string",
"=",
"\"\"",
"@props",
".",
"sort_by",
"do",
"|",
"key",
",",
"val",
"|",
"key",
".",
"to_s",
"end",
".",
"each",
"do",
"|",
"key",
",",
"val",
"|",
"string",
"<<",
"Encoding",
".",
"encode",
"(",
"key",
".",
"to_s",
")",
"<<",
"\"=\"",
"<<",
"Encoding",
".",
"encode",
"(",
"val",
")",
"<<",
"\"\\n\"",
"end",
"string",
"end"
] | Converts the properties contained in this object into a
string that can be saved directly as a Java properties
file. | [
"Converts",
"the",
"properties",
"contained",
"in",
"this",
"object",
"into",
"a",
"string",
"that",
"can",
"be",
"saved",
"directly",
"as",
"a",
"Java",
"properties",
"file",
"."
] | 2d25162ffd720d4f7c2602a0536924bda800b698 | https://github.com/flergl/java-properties-for-ruby/blob/2d25162ffd720d4f7c2602a0536924bda800b698/lib/java_properties.rb#L87-L96 | train |
thelabtech/questionnaire | app/presenters/qe/answer_pages_presenter.rb | Qe.AnswerPagesPresenter.page_list | def page_list(answer_sheets, a = nil, custom_pages = nil)
page_list = []
answer_sheets.each do |answer_sheet|
pages.each do |page|
page_list << new_page_link(answer_sheet, page, a)
end
end
page_list = page_list + custom_pages unless custom_pages.nil?
page_list
end | ruby | def page_list(answer_sheets, a = nil, custom_pages = nil)
page_list = []
answer_sheets.each do |answer_sheet|
pages.each do |page|
page_list << new_page_link(answer_sheet, page, a)
end
end
page_list = page_list + custom_pages unless custom_pages.nil?
page_list
end | [
"def",
"page_list",
"(",
"answer_sheets",
",",
"a",
"=",
"nil",
",",
"custom_pages",
"=",
"nil",
")",
"page_list",
"=",
"[",
"]",
"answer_sheets",
".",
"each",
"do",
"|",
"answer_sheet",
"|",
"pages",
".",
"each",
"do",
"|",
"page",
"|",
"page_list",
"<<",
"new_page_link",
"(",
"answer_sheet",
",",
"page",
",",
"a",
")",
"end",
"end",
"page_list",
"=",
"page_list",
"+",
"custom_pages",
"unless",
"custom_pages",
".",
"nil?",
"page_list",
"end"
] | for pages_list sidebar | [
"for",
"pages_list",
"sidebar"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/presenters/qe/answer_pages_presenter.rb#L88-L97 | train |
gregbell/inherited_views | lib/inherited_views/helpers.rb | InheritedViews.Helpers.render_partial_or_default | def render_partial_or_default(name, options = {})
render options.merge(:partial => name)
rescue ActionView::MissingTemplate
render options.merge(:partial => "#{controller.class.default_views}/#{name}")
end | ruby | def render_partial_or_default(name, options = {})
render options.merge(:partial => name)
rescue ActionView::MissingTemplate
render options.merge(:partial => "#{controller.class.default_views}/#{name}")
end | [
"def",
"render_partial_or_default",
"(",
"name",
",",
"options",
"=",
"{",
"}",
")",
"render",
"options",
".",
"merge",
"(",
":partial",
"=>",
"name",
")",
"rescue",
"ActionView",
"::",
"MissingTemplate",
"render",
"options",
".",
"merge",
"(",
":partial",
"=>",
"\"#{controller.class.default_views}/#{name}\"",
")",
"end"
] | Tries to render the partial, if it doesn't exist, we will
try to find the partial in the default views folder for this
controller.
Example:
in app/views/users/index.html.erb
<%= render_partial_or_default 'item', :collection => @items %>
First it will try to reder 'app/views/users/_item.html.erb'. If
this file doesn't exist, it will lookup _item.html.erb in the
default views folder. | [
"Tries",
"to",
"render",
"the",
"partial",
"if",
"it",
"doesn",
"t",
"exist",
"we",
"will",
"try",
"to",
"find",
"the",
"partial",
"in",
"the",
"default",
"views",
"folder",
"for",
"this",
"controller",
"."
] | 0905018bdf6fc07923792d66390e545888bf7cb8 | https://github.com/gregbell/inherited_views/blob/0905018bdf6fc07923792d66390e545888bf7cb8/lib/inherited_views/helpers.rb#L17-L21 | train |
ewannema/mm_json_client | lib/mm_json_client/client.rb | MmJsonClient.Client.client_objects_to_h | def client_objects_to_h(value)
case value.class.to_s
when /^MmJsonClient/
client_objects_to_h(value.to_h)
when 'Hash'
Hash[value.map { |k, v| [k, client_objects_to_h(v)] }]
when 'Array'
value.map { |v| client_objects_to_h(v) }
else
value
end
end | ruby | def client_objects_to_h(value)
case value.class.to_s
when /^MmJsonClient/
client_objects_to_h(value.to_h)
when 'Hash'
Hash[value.map { |k, v| [k, client_objects_to_h(v)] }]
when 'Array'
value.map { |v| client_objects_to_h(v) }
else
value
end
end | [
"def",
"client_objects_to_h",
"(",
"value",
")",
"case",
"value",
".",
"class",
".",
"to_s",
"when",
"/",
"/",
"client_objects_to_h",
"(",
"value",
".",
"to_h",
")",
"when",
"'Hash'",
"Hash",
"[",
"value",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"k",
",",
"client_objects_to_h",
"(",
"v",
")",
"]",
"}",
"]",
"when",
"'Array'",
"value",
".",
"map",
"{",
"|",
"v",
"|",
"client_objects_to_h",
"(",
"v",
")",
"}",
"else",
"value",
"end",
"end"
] | Recusively converts found MmJsonClient objects to hashes. | [
"Recusively",
"converts",
"found",
"MmJsonClient",
"objects",
"to",
"hashes",
"."
] | b6768b5ab52b097c2d6a7fb8000057f9537fef1c | https://github.com/ewannema/mm_json_client/blob/b6768b5ab52b097c2d6a7fb8000057f9537fef1c/lib/mm_json_client/client.rb#L50-L61 | train |
cucumber-ltd/relish-gem | lib/relish/options_file.rb | Relish.OptionsFile.store | def store(options)
@options = self.options.merge(options)
FileUtils.touch(@path)
File.open(@path, 'w') do |file|
YAML.dump(@options, file)
end
end | ruby | def store(options)
@options = self.options.merge(options)
FileUtils.touch(@path)
File.open(@path, 'w') do |file|
YAML.dump(@options, file)
end
end | [
"def",
"store",
"(",
"options",
")",
"@options",
"=",
"self",
".",
"options",
".",
"merge",
"(",
"options",
")",
"FileUtils",
".",
"touch",
"(",
"@path",
")",
"File",
".",
"open",
"(",
"@path",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"YAML",
".",
"dump",
"(",
"@options",
",",
"file",
")",
"end",
"end"
] | Store the given options into the file. Existing options with the same keys
will be overwritten. | [
"Store",
"the",
"given",
"options",
"into",
"the",
"file",
".",
"Existing",
"options",
"with",
"the",
"same",
"keys",
"will",
"be",
"overwritten",
"."
] | 3809c3e10aaefb84fedbcaa60e61cfc840b892a1 | https://github.com/cucumber-ltd/relish-gem/blob/3809c3e10aaefb84fedbcaa60e61cfc840b892a1/lib/relish/options_file.rb#L15-L21 | train |
johnl/web-page-parser | lib/web-page-parser/parsers/new_york_times_page_parser.rb | WebPageParser.NewYorkTimesPageParserV1.retrieve_page | def retrieve_page
return nil unless url
spurl = url
spurl << (spurl.include?("?") ? "&" : "?")
spurl << "pagewanted=all"
p = super(spurl)
# If it fails, reset the session and try one more time
unless retreive_successful?(p)
self.class.retrieve_session ||= WebPageParser::HTTP::Session.new
p = super(spurl)
end
if retreive_successful?(p)
p
else
raise RetrieveError, "Blocked by NYT paywall"
end
end | ruby | def retrieve_page
return nil unless url
spurl = url
spurl << (spurl.include?("?") ? "&" : "?")
spurl << "pagewanted=all"
p = super(spurl)
# If it fails, reset the session and try one more time
unless retreive_successful?(p)
self.class.retrieve_session ||= WebPageParser::HTTP::Session.new
p = super(spurl)
end
if retreive_successful?(p)
p
else
raise RetrieveError, "Blocked by NYT paywall"
end
end | [
"def",
"retrieve_page",
"return",
"nil",
"unless",
"url",
"spurl",
"=",
"url",
"spurl",
"<<",
"(",
"spurl",
".",
"include?",
"(",
"\"?\"",
")",
"?",
"\"&\"",
":",
"\"?\"",
")",
"spurl",
"<<",
"\"pagewanted=all\"",
"p",
"=",
"super",
"(",
"spurl",
")",
"unless",
"retreive_successful?",
"(",
"p",
")",
"self",
".",
"class",
".",
"retrieve_session",
"||=",
"WebPageParser",
"::",
"HTTP",
"::",
"Session",
".",
"new",
"p",
"=",
"super",
"(",
"spurl",
")",
"end",
"if",
"retreive_successful?",
"(",
"p",
")",
"p",
"else",
"raise",
"RetrieveError",
",",
"\"Blocked by NYT paywall\"",
"end",
"end"
] | We want to modify the url to request multi-page articles all in one request | [
"We",
"want",
"to",
"modify",
"the",
"url",
"to",
"request",
"multi",
"-",
"page",
"articles",
"all",
"in",
"one",
"request"
] | 105cbe6fda569c6c6667ed655ea6c6771c1d9037 | https://github.com/johnl/web-page-parser/blob/105cbe6fda569c6c6667ed655ea6c6771c1d9037/lib/web-page-parser/parsers/new_york_times_page_parser.rb#L25-L41 | train |
julik/tickly | lib/tickly/parser.rb | Tickly.Parser.wrap_io_or_string | def wrap_io_or_string(io_or_str)
return io_or_str if io_or_str.respond_to?(:read_one_char) # Bychar or R
return R.new(io_or_str) if io_or_str.respond_to?(:read)
R.new(StringIO.new(io_or_str))
end | ruby | def wrap_io_or_string(io_or_str)
return io_or_str if io_or_str.respond_to?(:read_one_char) # Bychar or R
return R.new(io_or_str) if io_or_str.respond_to?(:read)
R.new(StringIO.new(io_or_str))
end | [
"def",
"wrap_io_or_string",
"(",
"io_or_str",
")",
"return",
"io_or_str",
"if",
"io_or_str",
".",
"respond_to?",
"(",
":read_one_char",
")",
"return",
"R",
".",
"new",
"(",
"io_or_str",
")",
"if",
"io_or_str",
".",
"respond_to?",
"(",
":read",
")",
"R",
".",
"new",
"(",
"StringIO",
".",
"new",
"(",
"io_or_str",
")",
")",
"end"
] | Returns the given String or IO object wrapped in an object that has
one method, read_one_char - that gets used by all the subsequent
parsing steps | [
"Returns",
"the",
"given",
"String",
"or",
"IO",
"object",
"wrapped",
"in",
"an",
"object",
"that",
"has",
"one",
"method",
"read_one_char",
"-",
"that",
"gets",
"used",
"by",
"all",
"the",
"subsequent",
"parsing",
"steps"
] | 0b52d2bc46cd8fd63ba93e0884ae31a24598df9a | https://github.com/julik/tickly/blob/0b52d2bc46cd8fd63ba93e0884ae31a24598df9a/lib/tickly/parser.rb#L19-L23 | train |
julik/tickly | lib/tickly/parser.rb | Tickly.Parser.wrap_up | def wrap_up(expressions, stack, buf, stack_depth, multiple_expressions)
stack << buf if (buf.length > 0)
return stack unless multiple_expressions
expressions << stack if stack.any?
# Make sure that all of the expresisons get collapsed
expressions = expressions.map do | e |
compact_subexpr(e, stack_depth + 1)
end
return expressions
end | ruby | def wrap_up(expressions, stack, buf, stack_depth, multiple_expressions)
stack << buf if (buf.length > 0)
return stack unless multiple_expressions
expressions << stack if stack.any?
# Make sure that all of the expresisons get collapsed
expressions = expressions.map do | e |
compact_subexpr(e, stack_depth + 1)
end
return expressions
end | [
"def",
"wrap_up",
"(",
"expressions",
",",
"stack",
",",
"buf",
",",
"stack_depth",
",",
"multiple_expressions",
")",
"stack",
"<<",
"buf",
"if",
"(",
"buf",
".",
"length",
">",
"0",
")",
"return",
"stack",
"unless",
"multiple_expressions",
"expressions",
"<<",
"stack",
"if",
"stack",
".",
"any?",
"expressions",
"=",
"expressions",
".",
"map",
"do",
"|",
"e",
"|",
"compact_subexpr",
"(",
"e",
",",
"stack_depth",
"+",
"1",
")",
"end",
"return",
"expressions",
"end"
] | Package the expressions, stack and buffer.
We use a special flag to tell us whether we need multuple expressions.
If we do, the expressions will be returned. If not, just the stack.
Also, anything that remains on the stack will be put on the expressions
list if multiple_expressions is true. | [
"Package",
"the",
"expressions",
"stack",
"and",
"buffer",
".",
"We",
"use",
"a",
"special",
"flag",
"to",
"tell",
"us",
"whether",
"we",
"need",
"multuple",
"expressions",
".",
"If",
"we",
"do",
"the",
"expressions",
"will",
"be",
"returned",
".",
"If",
"not",
"just",
"the",
"stack",
".",
"Also",
"anything",
"that",
"remains",
"on",
"the",
"stack",
"will",
"be",
"put",
"on",
"the",
"expressions",
"list",
"if",
"multiple_expressions",
"is",
"true",
"."
] | 0b52d2bc46cd8fd63ba93e0884ae31a24598df9a | https://github.com/julik/tickly/blob/0b52d2bc46cd8fd63ba93e0884ae31a24598df9a/lib/tickly/parser.rb#L64-L76 | train |
julik/tickly | lib/tickly/parser.rb | Tickly.Parser.consume_remaining_buffer | def consume_remaining_buffer(stack, buf)
return if buf.length == 0
stack << buf.dup
buf.replace('')
end | ruby | def consume_remaining_buffer(stack, buf)
return if buf.length == 0
stack << buf.dup
buf.replace('')
end | [
"def",
"consume_remaining_buffer",
"(",
"stack",
",",
"buf",
")",
"return",
"if",
"buf",
".",
"length",
"==",
"0",
"stack",
"<<",
"buf",
".",
"dup",
"buf",
".",
"replace",
"(",
"''",
")",
"end"
] | If the passed buf contains any bytes, put them on the stack and
empty the buffer | [
"If",
"the",
"passed",
"buf",
"contains",
"any",
"bytes",
"put",
"them",
"on",
"the",
"stack",
"and",
"empty",
"the",
"buffer"
] | 0b52d2bc46cd8fd63ba93e0884ae31a24598df9a | https://github.com/julik/tickly/blob/0b52d2bc46cd8fd63ba93e0884ae31a24598df9a/lib/tickly/parser.rb#L80-L84 | train |
julik/tickly | lib/tickly/parser.rb | Tickly.Parser.parse_expr | def parse_expr(io, stop_char = nil, stack_depth = 0, multiple_expressions = false)
# A standard stack is an expression that does not evaluate to a string
expressions = []
stack = []
buf = ''
loop do
char = io.read_one_char
# Ignore carriage returns
next if char == "\r"
if stop_char && char.nil?
raise Error, "IO ran out when parsing a subexpression (expected to end on #{stop_char.inspect})"
elsif char == stop_char # Bail out of a subexpr or bail out on nil
# TODO: default stop_char is nil, and this is also what gets returned from a depleted
# IO on IO#read(). We should do that in Bychar.
# Handle any remaining subexpressions
return wrap_up(expressions, stack, buf, stack_depth, multiple_expressions)
elsif char == " " || char == "\n" # Space
if buf.length > 0
stack << buf
buf = ''
end
if TERMINATORS.include?(char) && stack.any? # Introduce a stack separator! This is a new line
# First get rid of the remaining buffer data
consume_remaining_buffer(stack, buf)
# Since we now finished an expression and it is on the stack,
# we can run this expression through the filter
filtered_expr = compact_subexpr(stack, stack_depth + 1)
# Only preserve the parsed expression if it's not nil
expressions << filtered_expr unless filtered_expr.nil?
# Reset the stack for the next expression
stack = []
# Note that we will return multiple expressions instead of one
multiple_expressions = true
end
elsif char == '[' # Opens a new string expression
consume_remaining_buffer(stack, buf)
stack << [:b] + parse_expr(io, ']', stack_depth + 1)
elsif char == '{' # Opens a new literal expression
consume_remaining_buffer(stack, buf)
stack << [:c] + parse_expr(io, '}', stack_depth + 1)
elsif QUOTES.include?(char) # String
consume_remaining_buffer(stack, buf)
stack << parse_str(io, char)
else
buf << char
end
end
raise Error, "Should never happen"
end | ruby | def parse_expr(io, stop_char = nil, stack_depth = 0, multiple_expressions = false)
# A standard stack is an expression that does not evaluate to a string
expressions = []
stack = []
buf = ''
loop do
char = io.read_one_char
# Ignore carriage returns
next if char == "\r"
if stop_char && char.nil?
raise Error, "IO ran out when parsing a subexpression (expected to end on #{stop_char.inspect})"
elsif char == stop_char # Bail out of a subexpr or bail out on nil
# TODO: default stop_char is nil, and this is also what gets returned from a depleted
# IO on IO#read(). We should do that in Bychar.
# Handle any remaining subexpressions
return wrap_up(expressions, stack, buf, stack_depth, multiple_expressions)
elsif char == " " || char == "\n" # Space
if buf.length > 0
stack << buf
buf = ''
end
if TERMINATORS.include?(char) && stack.any? # Introduce a stack separator! This is a new line
# First get rid of the remaining buffer data
consume_remaining_buffer(stack, buf)
# Since we now finished an expression and it is on the stack,
# we can run this expression through the filter
filtered_expr = compact_subexpr(stack, stack_depth + 1)
# Only preserve the parsed expression if it's not nil
expressions << filtered_expr unless filtered_expr.nil?
# Reset the stack for the next expression
stack = []
# Note that we will return multiple expressions instead of one
multiple_expressions = true
end
elsif char == '[' # Opens a new string expression
consume_remaining_buffer(stack, buf)
stack << [:b] + parse_expr(io, ']', stack_depth + 1)
elsif char == '{' # Opens a new literal expression
consume_remaining_buffer(stack, buf)
stack << [:c] + parse_expr(io, '}', stack_depth + 1)
elsif QUOTES.include?(char) # String
consume_remaining_buffer(stack, buf)
stack << parse_str(io, char)
else
buf << char
end
end
raise Error, "Should never happen"
end | [
"def",
"parse_expr",
"(",
"io",
",",
"stop_char",
"=",
"nil",
",",
"stack_depth",
"=",
"0",
",",
"multiple_expressions",
"=",
"false",
")",
"expressions",
"=",
"[",
"]",
"stack",
"=",
"[",
"]",
"buf",
"=",
"''",
"loop",
"do",
"char",
"=",
"io",
".",
"read_one_char",
"next",
"if",
"char",
"==",
"\"\\r\"",
"if",
"stop_char",
"&&",
"char",
".",
"nil?",
"raise",
"Error",
",",
"\"IO ran out when parsing a subexpression (expected to end on #{stop_char.inspect})\"",
"elsif",
"char",
"==",
"stop_char",
"return",
"wrap_up",
"(",
"expressions",
",",
"stack",
",",
"buf",
",",
"stack_depth",
",",
"multiple_expressions",
")",
"elsif",
"char",
"==",
"\" \"",
"||",
"char",
"==",
"\"\\n\"",
"if",
"buf",
".",
"length",
">",
"0",
"stack",
"<<",
"buf",
"buf",
"=",
"''",
"end",
"if",
"TERMINATORS",
".",
"include?",
"(",
"char",
")",
"&&",
"stack",
".",
"any?",
"consume_remaining_buffer",
"(",
"stack",
",",
"buf",
")",
"filtered_expr",
"=",
"compact_subexpr",
"(",
"stack",
",",
"stack_depth",
"+",
"1",
")",
"expressions",
"<<",
"filtered_expr",
"unless",
"filtered_expr",
".",
"nil?",
"stack",
"=",
"[",
"]",
"multiple_expressions",
"=",
"true",
"end",
"elsif",
"char",
"==",
"'['",
"consume_remaining_buffer",
"(",
"stack",
",",
"buf",
")",
"stack",
"<<",
"[",
":b",
"]",
"+",
"parse_expr",
"(",
"io",
",",
"']'",
",",
"stack_depth",
"+",
"1",
")",
"elsif",
"char",
"==",
"'{'",
"consume_remaining_buffer",
"(",
"stack",
",",
"buf",
")",
"stack",
"<<",
"[",
":c",
"]",
"+",
"parse_expr",
"(",
"io",
",",
"'}'",
",",
"stack_depth",
"+",
"1",
")",
"elsif",
"QUOTES",
".",
"include?",
"(",
"char",
")",
"consume_remaining_buffer",
"(",
"stack",
",",
"buf",
")",
"stack",
"<<",
"parse_str",
"(",
"io",
",",
"char",
")",
"else",
"buf",
"<<",
"char",
"end",
"end",
"raise",
"Error",
",",
"\"Should never happen\"",
"end"
] | Parse from a passed IO object either until an unescaped stop_char is reached
or until the IO is exhausted. The last argument is the class used to
compose the subexpression being parsed. The subparser is reentrant and not
destructive for the object containing it. | [
"Parse",
"from",
"a",
"passed",
"IO",
"object",
"either",
"until",
"an",
"unescaped",
"stop_char",
"is",
"reached",
"or",
"until",
"the",
"IO",
"is",
"exhausted",
".",
"The",
"last",
"argument",
"is",
"the",
"class",
"used",
"to",
"compose",
"the",
"subexpression",
"being",
"parsed",
".",
"The",
"subparser",
"is",
"reentrant",
"and",
"not",
"destructive",
"for",
"the",
"object",
"containing",
"it",
"."
] | 0b52d2bc46cd8fd63ba93e0884ae31a24598df9a | https://github.com/julik/tickly/blob/0b52d2bc46cd8fd63ba93e0884ae31a24598df9a/lib/tickly/parser.rb#L90-L147 | train |
julik/tickly | lib/tickly/parser.rb | Tickly.Parser.parse_str | def parse_str(io, stop_quote)
buf = ''
loop do
c = io.read_one_char
if c.nil?
raise Error, "The IO ran out before the end of a literal string"
elsif buf.length > 0 && buf[-1..-1] == ESC # If this char was escaped
# Trim the escape character at the end of the buffer
buf = buf[0..-2]
buf << c
elsif c == stop_quote
return buf
else
buf << c
end
end
end | ruby | def parse_str(io, stop_quote)
buf = ''
loop do
c = io.read_one_char
if c.nil?
raise Error, "The IO ran out before the end of a literal string"
elsif buf.length > 0 && buf[-1..-1] == ESC # If this char was escaped
# Trim the escape character at the end of the buffer
buf = buf[0..-2]
buf << c
elsif c == stop_quote
return buf
else
buf << c
end
end
end | [
"def",
"parse_str",
"(",
"io",
",",
"stop_quote",
")",
"buf",
"=",
"''",
"loop",
"do",
"c",
"=",
"io",
".",
"read_one_char",
"if",
"c",
".",
"nil?",
"raise",
"Error",
",",
"\"The IO ran out before the end of a literal string\"",
"elsif",
"buf",
".",
"length",
">",
"0",
"&&",
"buf",
"[",
"-",
"1",
"..",
"-",
"1",
"]",
"==",
"ESC",
"buf",
"=",
"buf",
"[",
"0",
"..",
"-",
"2",
"]",
"buf",
"<<",
"c",
"elsif",
"c",
"==",
"stop_quote",
"return",
"buf",
"else",
"buf",
"<<",
"c",
"end",
"end",
"end"
] | Parse a string literal, in single or double quotes. | [
"Parse",
"a",
"string",
"literal",
"in",
"single",
"or",
"double",
"quotes",
"."
] | 0b52d2bc46cd8fd63ba93e0884ae31a24598df9a | https://github.com/julik/tickly/blob/0b52d2bc46cd8fd63ba93e0884ae31a24598df9a/lib/tickly/parser.rb#L150-L166 | train |
Sage/class_kit | lib/class_kit/attribute_helper.rb | ClassKit.AttributeHelper.get_attributes | def get_attributes(klass)
return @attribute_store[klass] if @attribute_store.key?(klass)
attributes = []
klass.ancestors.map do |k|
hash = k.instance_variable_get(:@class_kit_attributes)
if hash != nil
hash.values.each do |a|
attributes.push(a)
end
end
end
attributes.compact!
@attribute_store[klass] = attributes
attributes
end | ruby | def get_attributes(klass)
return @attribute_store[klass] if @attribute_store.key?(klass)
attributes = []
klass.ancestors.map do |k|
hash = k.instance_variable_get(:@class_kit_attributes)
if hash != nil
hash.values.each do |a|
attributes.push(a)
end
end
end
attributes.compact!
@attribute_store[klass] = attributes
attributes
end | [
"def",
"get_attributes",
"(",
"klass",
")",
"return",
"@attribute_store",
"[",
"klass",
"]",
"if",
"@attribute_store",
".",
"key?",
"(",
"klass",
")",
"attributes",
"=",
"[",
"]",
"klass",
".",
"ancestors",
".",
"map",
"do",
"|",
"k",
"|",
"hash",
"=",
"k",
".",
"instance_variable_get",
"(",
":@class_kit_attributes",
")",
"if",
"hash",
"!=",
"nil",
"hash",
".",
"values",
".",
"each",
"do",
"|",
"a",
"|",
"attributes",
".",
"push",
"(",
"a",
")",
"end",
"end",
"end",
"attributes",
".",
"compact!",
"@attribute_store",
"[",
"klass",
"]",
"=",
"attributes",
"attributes",
"end"
] | Get attributes for a given class
@param klass [ClassKit] a class that has been extended with ClassKit
@return [Hash] | [
"Get",
"attributes",
"for",
"a",
"given",
"class"
] | addbb656e728adc353ee6eb6b1f9fd131effc8d1 | https://github.com/Sage/class_kit/blob/addbb656e728adc353ee6eb6b1f9fd131effc8d1/lib/class_kit/attribute_helper.rb#L17-L33 | train |
Sage/class_kit | lib/class_kit/attribute_helper.rb | ClassKit.AttributeHelper.get_attribute | def get_attribute(klass:, name:)
get_attributes(klass).detect { |a| a[:name] == name } ||
raise(ClassKit::Exceptions::AttributeNotFoundError, "Attribute: #{name}, could not be found.")
end | ruby | def get_attribute(klass:, name:)
get_attributes(klass).detect { |a| a[:name] == name } ||
raise(ClassKit::Exceptions::AttributeNotFoundError, "Attribute: #{name}, could not be found.")
end | [
"def",
"get_attribute",
"(",
"klass",
":",
",",
"name",
":",
")",
"get_attributes",
"(",
"klass",
")",
".",
"detect",
"{",
"|",
"a",
"|",
"a",
"[",
":name",
"]",
"==",
"name",
"}",
"||",
"raise",
"(",
"ClassKit",
"::",
"Exceptions",
"::",
"AttributeNotFoundError",
",",
"\"Attribute: #{name}, could not be found.\"",
")",
"end"
] | Get attribute for a given class and name
@param klass [ClassKit] a class that has been extended with ClassKit
@param name [Symbol] an attribute name
@raise [ClassKit::Exceptions::AttributeNotFoundError] if the given attribute could not be found
@return [Hash] that describes the attribute | [
"Get",
"attribute",
"for",
"a",
"given",
"class",
"and",
"name"
] | addbb656e728adc353ee6eb6b1f9fd131effc8d1 | https://github.com/Sage/class_kit/blob/addbb656e728adc353ee6eb6b1f9fd131effc8d1/lib/class_kit/attribute_helper.rb#L43-L46 | train |
cfanbase/cfan122 | lib/cfan122.rb | Cfan122.Reloader.cleanup | def cleanup(parent = Object, current = @top)
return unless all_project_objects_lookup[current]
current.constants.each {|const| cleanup current, current.const_get(const)}
parent.send(:remove_const, current.to_s.split('::').last.to_sym)
end | ruby | def cleanup(parent = Object, current = @top)
return unless all_project_objects_lookup[current]
current.constants.each {|const| cleanup current, current.const_get(const)}
parent.send(:remove_const, current.to_s.split('::').last.to_sym)
end | [
"def",
"cleanup",
"(",
"parent",
"=",
"Object",
",",
"current",
"=",
"@top",
")",
"return",
"unless",
"all_project_objects_lookup",
"[",
"current",
"]",
"current",
".",
"constants",
".",
"each",
"{",
"|",
"const",
"|",
"cleanup",
"current",
",",
"current",
".",
"const_get",
"(",
"const",
")",
"}",
"parent",
".",
"send",
"(",
":remove_const",
",",
"current",
".",
"to_s",
".",
"split",
"(",
"'::'",
")",
".",
"last",
".",
"to_sym",
")",
"end"
] | Recursively removes all constant entries of modules and classes under
the MyGemName namespace | [
"Recursively",
"removes",
"all",
"constant",
"entries",
"of",
"modules",
"and",
"classes",
"under",
"the",
"MyGemName",
"namespace"
] | ea0842d58cf36ffd1d555b26ed24db6a3e68ab26 | https://github.com/cfanbase/cfan122/blob/ea0842d58cf36ffd1d555b26ed24db6a3e68ab26/lib/cfan122.rb#L74-L78 | train |
Sage/class_kit | lib/class_kit/helper.rb | ClassKit.Helper.to_hash | def to_hash(object, use_alias = false)
return object.map { |i| to_hash(i, use_alias) } if object.is_a?(Array)
validate_class_kit(object.class)
hash = {}
attributes = @attribute_helper.get_attributes(object.class)
attributes.each do |attribute|
key = use_alias ? (attribute[:alias] || attribute[:name]) : attribute[:name]
type = attribute[:type]
value = object.public_send(attribute[:name])
if value != nil
hash[key] = if is_class_kit?(type)
to_hash(value, use_alias)
elsif type == Array
value.map do |i|
if is_class_kit?(i.class)
to_hash(i, use_alias)
else
i
end
end
else
value
end
end
end
@hash_helper.indifferent!(hash)
hash
end | ruby | def to_hash(object, use_alias = false)
return object.map { |i| to_hash(i, use_alias) } if object.is_a?(Array)
validate_class_kit(object.class)
hash = {}
attributes = @attribute_helper.get_attributes(object.class)
attributes.each do |attribute|
key = use_alias ? (attribute[:alias] || attribute[:name]) : attribute[:name]
type = attribute[:type]
value = object.public_send(attribute[:name])
if value != nil
hash[key] = if is_class_kit?(type)
to_hash(value, use_alias)
elsif type == Array
value.map do |i|
if is_class_kit?(i.class)
to_hash(i, use_alias)
else
i
end
end
else
value
end
end
end
@hash_helper.indifferent!(hash)
hash
end | [
"def",
"to_hash",
"(",
"object",
",",
"use_alias",
"=",
"false",
")",
"return",
"object",
".",
"map",
"{",
"|",
"i",
"|",
"to_hash",
"(",
"i",
",",
"use_alias",
")",
"}",
"if",
"object",
".",
"is_a?",
"(",
"Array",
")",
"validate_class_kit",
"(",
"object",
".",
"class",
")",
"hash",
"=",
"{",
"}",
"attributes",
"=",
"@attribute_helper",
".",
"get_attributes",
"(",
"object",
".",
"class",
")",
"attributes",
".",
"each",
"do",
"|",
"attribute",
"|",
"key",
"=",
"use_alias",
"?",
"(",
"attribute",
"[",
":alias",
"]",
"||",
"attribute",
"[",
":name",
"]",
")",
":",
"attribute",
"[",
":name",
"]",
"type",
"=",
"attribute",
"[",
":type",
"]",
"value",
"=",
"object",
".",
"public_send",
"(",
"attribute",
"[",
":name",
"]",
")",
"if",
"value",
"!=",
"nil",
"hash",
"[",
"key",
"]",
"=",
"if",
"is_class_kit?",
"(",
"type",
")",
"to_hash",
"(",
"value",
",",
"use_alias",
")",
"elsif",
"type",
"==",
"Array",
"value",
".",
"map",
"do",
"|",
"i",
"|",
"if",
"is_class_kit?",
"(",
"i",
".",
"class",
")",
"to_hash",
"(",
"i",
",",
"use_alias",
")",
"else",
"i",
"end",
"end",
"else",
"value",
"end",
"end",
"end",
"@hash_helper",
".",
"indifferent!",
"(",
"hash",
")",
"hash",
"end"
] | This method is called to convert a ClassKit object into a Hash. | [
"This",
"method",
"is",
"called",
"to",
"convert",
"a",
"ClassKit",
"object",
"into",
"a",
"Hash",
"."
] | addbb656e728adc353ee6eb6b1f9fd131effc8d1 | https://github.com/Sage/class_kit/blob/addbb656e728adc353ee6eb6b1f9fd131effc8d1/lib/class_kit/helper.rb#L20-L50 | train |
Sage/class_kit | lib/class_kit/helper.rb | ClassKit.Helper.to_json | def to_json(object, use_alias = false)
hash = to_hash(object, use_alias)
JSON.dump(hash)
end | ruby | def to_json(object, use_alias = false)
hash = to_hash(object, use_alias)
JSON.dump(hash)
end | [
"def",
"to_json",
"(",
"object",
",",
"use_alias",
"=",
"false",
")",
"hash",
"=",
"to_hash",
"(",
"object",
",",
"use_alias",
")",
"JSON",
".",
"dump",
"(",
"hash",
")",
"end"
] | This method is called to convert a ClassKit object into JSON. | [
"This",
"method",
"is",
"called",
"to",
"convert",
"a",
"ClassKit",
"object",
"into",
"JSON",
"."
] | addbb656e728adc353ee6eb6b1f9fd131effc8d1 | https://github.com/Sage/class_kit/blob/addbb656e728adc353ee6eb6b1f9fd131effc8d1/lib/class_kit/helper.rb#L93-L96 | train |
Sage/class_kit | lib/class_kit/helper.rb | ClassKit.Helper.from_json | def from_json(json:, klass:, use_alias: false)
hash = JSON.load(json)
from_hash(hash: hash, klass: klass, use_alias: use_alias)
end | ruby | def from_json(json:, klass:, use_alias: false)
hash = JSON.load(json)
from_hash(hash: hash, klass: klass, use_alias: use_alias)
end | [
"def",
"from_json",
"(",
"json",
":",
",",
"klass",
":",
",",
"use_alias",
":",
"false",
")",
"hash",
"=",
"JSON",
".",
"load",
"(",
"json",
")",
"from_hash",
"(",
"hash",
":",
"hash",
",",
"klass",
":",
"klass",
",",
"use_alias",
":",
"use_alias",
")",
"end"
] | This method is called to convert JSON into a ClassKit object. | [
"This",
"method",
"is",
"called",
"to",
"convert",
"JSON",
"into",
"a",
"ClassKit",
"object",
"."
] | addbb656e728adc353ee6eb6b1f9fd131effc8d1 | https://github.com/Sage/class_kit/blob/addbb656e728adc353ee6eb6b1f9fd131effc8d1/lib/class_kit/helper.rb#L99-L102 | train |
calonso/rails_friendly_urls | lib/rails_friendly_urls/friendly_url.rb | RailsFriendlyUrls.FriendlyUrl.set_destination_data! | def set_destination_data!
route_info = Rails.application.routes.recognize_path self.path
self.controller = route_info[:controller]
self.action = route_info[:action]
self.defaults = route_info.reject { |k, v| [:controller, :action].include? k }
end | ruby | def set_destination_data!
route_info = Rails.application.routes.recognize_path self.path
self.controller = route_info[:controller]
self.action = route_info[:action]
self.defaults = route_info.reject { |k, v| [:controller, :action].include? k }
end | [
"def",
"set_destination_data!",
"route_info",
"=",
"Rails",
".",
"application",
".",
"routes",
".",
"recognize_path",
"self",
".",
"path",
"self",
".",
"controller",
"=",
"route_info",
"[",
":controller",
"]",
"self",
".",
"action",
"=",
"route_info",
"[",
":action",
"]",
"self",
".",
"defaults",
"=",
"route_info",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"[",
":controller",
",",
":action",
"]",
".",
"include?",
"k",
"}",
"end"
] | This method tries to identify the route contained at self.path to extract
the destination's controller, action and other arguments and save them
into the corresponding controller, action and defaults fields of the
including objects. | [
"This",
"method",
"tries",
"to",
"identify",
"the",
"route",
"contained",
"at",
"self",
".",
"path",
"to",
"extract",
"the",
"destination",
"s",
"controller",
"action",
"and",
"other",
"arguments",
"and",
"save",
"them",
"into",
"the",
"corresponding",
"controller",
"action",
"and",
"defaults",
"fields",
"of",
"the",
"including",
"objects",
"."
] | 356fc101f106bda1ce890ae8f5ffc7cc44a56ec2 | https://github.com/calonso/rails_friendly_urls/blob/356fc101f106bda1ce890ae8f5ffc7cc44a56ec2/lib/rails_friendly_urls/friendly_url.rb#L14-L19 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.corpora | def corpora(project_id, opts = {})
data, _status_code, _headers = corpora_with_http_info(project_id, opts)
return data
end | ruby | def corpora(project_id, opts = {})
data, _status_code, _headers = corpora_with_http_info(project_id, opts)
return data
end | [
"def",
"corpora",
"(",
"project_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"corpora_with_http_info",
"(",
"project_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Corpora
Returns a collection of Corpora
@param project_id ID of the Project
@param [Hash] opts the optional parameters
@return [CorporaCollection] | [
"Returns",
"a",
"collection",
"of",
"Corpora",
"Returns",
"a",
"collection",
"of",
"Corpora"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L28-L31 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.corpus | def corpus(project_id, name, opts = {})
data, _status_code, _headers = corpus_with_http_info(project_id, name, opts)
return data
end | ruby | def corpus(project_id, name, opts = {})
data, _status_code, _headers = corpus_with_http_info(project_id, name, opts)
return data
end | [
"def",
"corpus",
"(",
"project_id",
",",
"name",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"corpus_with_http_info",
"(",
"project_id",
",",
"name",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns the Corpus
Returns the Corpus
@param project_id ID of the Project
@param name Corpus name
@param [Hash] opts the optional parameters
@return [Corpus] | [
"Returns",
"the",
"Corpus",
"Returns",
"the",
"Corpus"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L84-L87 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.create_corpus | def create_corpus(project_id, name, body, opts = {})
create_corpus_with_http_info(project_id, name, body, opts)
return nil
end | ruby | def create_corpus(project_id, name, body, opts = {})
create_corpus_with_http_info(project_id, name, body, opts)
return nil
end | [
"def",
"create_corpus",
"(",
"project_id",
",",
"name",
",",
"body",
",",
"opts",
"=",
"{",
"}",
")",
"create_corpus_with_http_info",
"(",
"project_id",
",",
"name",
",",
"body",
",",
"opts",
")",
"return",
"nil",
"end"
] | Creates a new Corpus
Creates a new Corpus
@param project_id ID of the Project
@param name Corpus name
@param body
@param [Hash] opts the optional parameters
@return [nil] | [
"Creates",
"a",
"new",
"Corpus",
"Creates",
"a",
"new",
"Corpus"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L146-L149 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.create_project | def create_project(project, opts = {})
data, _status_code, _headers = create_project_with_http_info(project, opts)
return data
end | ruby | def create_project(project, opts = {})
data, _status_code, _headers = create_project_with_http_info(project, opts)
return data
end | [
"def",
"create_project",
"(",
"project",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_project_with_http_info",
"(",
"project",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates a new Project
Creates a new Project
@param project
@param [Hash] opts the optional parameters
@return [Project] | [
"Creates",
"a",
"new",
"Project",
"Creates",
"a",
"new",
"Project"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L271-L274 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.job | def job(project_id, job_id, opts = {})
data, _status_code, _headers = job_with_http_info(project_id, job_id, opts)
return data
end | ruby | def job(project_id, job_id, opts = {})
data, _status_code, _headers = job_with_http_info(project_id, job_id, opts)
return data
end | [
"def",
"job",
"(",
"project_id",
",",
"job_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"job_with_http_info",
"(",
"project_id",
",",
"job_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns the Job
Returns the Job
@param project_id ID of the Project
@param job_id
@param [Hash] opts the optional parameters
@return [Job] | [
"Returns",
"the",
"Job",
"Returns",
"the",
"Job"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L495-L498 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.job_result | def job_result(project_id, job_id, opts = {})
data, _status_code, _headers = job_result_with_http_info(project_id, job_id, opts)
return data
end | ruby | def job_result(project_id, job_id, opts = {})
data, _status_code, _headers = job_result_with_http_info(project_id, job_id, opts)
return data
end | [
"def",
"job_result",
"(",
"project_id",
",",
"job_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"job_result_with_http_info",
"(",
"project_id",
",",
"job_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns the Job Result
Returns the Job Result
@param project_id ID of the Project
@param job_id
@param [Hash] opts the optional parameters
@return [JobResult] | [
"Returns",
"the",
"Job",
"Result",
"Returns",
"the",
"Job",
"Result"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L556-L559 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.jobs | def jobs(project_id, opts = {})
data, _status_code, _headers = jobs_with_http_info(project_id, opts)
return data
end | ruby | def jobs(project_id, opts = {})
data, _status_code, _headers = jobs_with_http_info(project_id, opts)
return data
end | [
"def",
"jobs",
"(",
"project_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"jobs_with_http_info",
"(",
"project_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Jobs
Returns a collection of Jobs
@param project_id ID of the Project
@param [Hash] opts the optional parameters
@option opts [Integer] :page page number
@option opts [Integer] :per_page number of records per page
@return [JobsCollection] | [
"Returns",
"a",
"collection",
"of",
"Jobs",
"Returns",
"a",
"collection",
"of",
"Jobs"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L618-L621 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.project | def project(project_id, opts = {})
data, _status_code, _headers = project_with_http_info(project_id, opts)
return data
end | ruby | def project(project_id, opts = {})
data, _status_code, _headers = project_with_http_info(project_id, opts)
return data
end | [
"def",
"project",
"(",
"project_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"project_with_http_info",
"(",
"project_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns the Project
Returns the Project
@param project_id ID of the Project
@param [Hash] opts the optional parameters
@return [Project] | [
"Returns",
"the",
"Project",
"Returns",
"the",
"Project"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L677-L680 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.update_project | def update_project(project, opts = {})
data, _status_code, _headers = update_project_with_http_info(project, opts)
return data
end | ruby | def update_project(project, opts = {})
data, _status_code, _headers = update_project_with_http_info(project, opts)
return data
end | [
"def",
"update_project",
"(",
"project",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"update_project_with_http_info",
"(",
"project",
",",
"opts",
")",
"return",
"data",
"end"
] | Updates an existing Project
Updates an existing Project
@param project
@param [Hash] opts the optional parameters
@return [Project] | [
"Updates",
"an",
"existing",
"Project",
"Updates",
"an",
"existing",
"Project"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L835-L838 | train |
Telestream/telestream-cloud-ruby-sdk | tts/lib/telestream_cloud_tts/api/tts_api.rb | TelestreamCloud::Tts.TtsApi.upload_video | def upload_video(project_id, video_upload_body, opts = {})
data, _status_code, _headers = upload_video_with_http_info(project_id, video_upload_body, opts)
return data
end | ruby | def upload_video(project_id, video_upload_body, opts = {})
data, _status_code, _headers = upload_video_with_http_info(project_id, video_upload_body, opts)
return data
end | [
"def",
"upload_video",
"(",
"project_id",
",",
"video_upload_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"upload_video_with_http_info",
"(",
"project_id",
",",
"video_upload_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates an upload session
@param project_id ID of the Project
@param video_upload_body
@param [Hash] opts the optional parameters
@return [UploadSession] | [
"Creates",
"an",
"upload",
"session"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/tts/lib/telestream_cloud_tts/api/tts_api.rb#L891-L894 | train |
christhekeele/rails-tables | lib/rails-tables/datatable/searching.rb | RailsTables::Searching.ClassMethods.search_on | def search_on(column_source, methods)
Array(methods).each do |method_name|
join column_source
self.searches += [{column_source: column_source.to_s, method_name: method_name.to_s}]
end
end | ruby | def search_on(column_source, methods)
Array(methods).each do |method_name|
join column_source
self.searches += [{column_source: column_source.to_s, method_name: method_name.to_s}]
end
end | [
"def",
"search_on",
"(",
"column_source",
",",
"methods",
")",
"Array",
"(",
"methods",
")",
".",
"each",
"do",
"|",
"method_name",
"|",
"join",
"column_source",
"self",
".",
"searches",
"+=",
"[",
"{",
"column_source",
":",
"column_source",
".",
"to_s",
",",
"method_name",
":",
"method_name",
".",
"to_s",
"}",
"]",
"end",
"end"
] | Allow user defined fields to sort on in addition to introspected fields | [
"Allow",
"user",
"defined",
"fields",
"to",
"sort",
"on",
"in",
"addition",
"to",
"introspected",
"fields"
] | 77adc0f9392f58819adce112b7964e4d353fab04 | https://github.com/christhekeele/rails-tables/blob/77adc0f9392f58819adce112b7964e4d353fab04/lib/rails-tables/datatable/searching.rb#L12-L17 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.read_image | def read_image
raw_image = []
@stream.index = @hdr['vox_offset']
type = NIFTI_DATATYPES[@hdr['datatype']]
format = @stream.format[type]
@image_rubyarray = @stream.decode(@stream.rest_length, type)
end | ruby | def read_image
raw_image = []
@stream.index = @hdr['vox_offset']
type = NIFTI_DATATYPES[@hdr['datatype']]
format = @stream.format[type]
@image_rubyarray = @stream.decode(@stream.rest_length, type)
end | [
"def",
"read_image",
"raw_image",
"=",
"[",
"]",
"@stream",
".",
"index",
"=",
"@hdr",
"[",
"'vox_offset'",
"]",
"type",
"=",
"NIFTI_DATATYPES",
"[",
"@hdr",
"[",
"'datatype'",
"]",
"]",
"format",
"=",
"@stream",
".",
"format",
"[",
"type",
"]",
"@image_rubyarray",
"=",
"@stream",
".",
"decode",
"(",
"@stream",
".",
"rest_length",
",",
"type",
")",
"end"
] | Create a NRead object to parse a nifti file or binary string and set header and image info instance variables.
The nifti header will be checked for validity (header size and magic number) and will raise an IOError if invalid.
NIFTI header extensions are not yet supported and are not included in the header.
The header and image are accessible via the hdr and image instance variables. An optional narray matrix may also be available in image_narray if desired by passing in :narray => true as an option.
=== Parameters
* <tt>source</tt> -- A string which specifies either the path of a NIFTI file to be loaded, or a binary NIFTI string to be parsed.
* <tt>options</tt> -- A hash of parameters.
=== Options
* <tt>:bin</tt> -- Boolean. If set to true, string parameter will be interpreted as a binary NIFTI string, and not a path string, which is the default behaviour.
* <tt>:image</tt> -- Boolean. If set to true, automatically load the image into @image, otherwise only a header is collected and you can get an image
* <tt>:narray</tt> -- Boolean. If set to true, a properly shaped narray matrix will be set in the instance variable @image_narray. Automatically sets :image => true
Unpack an image array from vox_offset to the end of a nifti file.
=== Parameters
There are no parameters - this reads from the binary string in the @string instance variable.
This sets @image_rubyarray to the image data vector and also returns it. | [
"Create",
"a",
"NRead",
"object",
"to",
"parse",
"a",
"nifti",
"file",
"or",
"binary",
"string",
"and",
"set",
"header",
"and",
"image",
"info",
"instance",
"variables",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L60-L66 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.get_image_narray | def get_image_narray(image_array, dim)
if Object.const_defined?('NArray')
@image_narray = pixel_data = NArray.to_na(image_array).reshape!(*dim[1..dim[0]])
else
add_msg "Can't find NArray, no image_narray created. Please `gem install narray`"
end
end | ruby | def get_image_narray(image_array, dim)
if Object.const_defined?('NArray')
@image_narray = pixel_data = NArray.to_na(image_array).reshape!(*dim[1..dim[0]])
else
add_msg "Can't find NArray, no image_narray created. Please `gem install narray`"
end
end | [
"def",
"get_image_narray",
"(",
"image_array",
",",
"dim",
")",
"if",
"Object",
".",
"const_defined?",
"(",
"'NArray'",
")",
"@image_narray",
"=",
"pixel_data",
"=",
"NArray",
".",
"to_na",
"(",
"image_array",
")",
".",
"reshape!",
"(",
"*",
"dim",
"[",
"1",
"..",
"dim",
"[",
"0",
"]",
"]",
")",
"else",
"add_msg",
"\"Can't find NArray, no image_narray created. Please `gem install narray`\"",
"end",
"end"
] | Create an narray if the NArray is available
Tests if a file is readable, and if so, opens it.
=== Parameters
* <tt>image_array</tt> -- Array. A vector of image data.
* <tt>dim</tt> -- Array. The dim array from the nifti header, specifing number of dimensions (dim[0]) and dimension length of other dimensions to reshape narray into. | [
"Create",
"an",
"narray",
"if",
"the",
"NArray",
"is",
"available",
"Tests",
"if",
"a",
"file",
"is",
"readable",
"and",
"if",
"so",
"opens",
"it",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L76-L82 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.parse_header | def parse_header(options = {})
check_header
@hdr = parse_basic_header
@extended_header = parse_extended_header
# Optional image gathering
read_image if options[:image]
get_image_narray(@image_rubyarray, @hdr['dim']) if options[:narray]
@success = true
end | ruby | def parse_header(options = {})
check_header
@hdr = parse_basic_header
@extended_header = parse_extended_header
# Optional image gathering
read_image if options[:image]
get_image_narray(@image_rubyarray, @hdr['dim']) if options[:narray]
@success = true
end | [
"def",
"parse_header",
"(",
"options",
"=",
"{",
"}",
")",
"check_header",
"@hdr",
"=",
"parse_basic_header",
"@extended_header",
"=",
"parse_extended_header",
"read_image",
"if",
"options",
"[",
":image",
"]",
"get_image_narray",
"(",
"@image_rubyarray",
",",
"@hdr",
"[",
"'dim'",
"]",
")",
"if",
"options",
"[",
":narray",
"]",
"@success",
"=",
"true",
"end"
] | Parse the NIFTI Header. | [
"Parse",
"the",
"NIFTI",
"Header",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L113-L123 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.parse_basic_header | def parse_basic_header
# The HEADER_SIGNATURE is defined in NIFTI::Constants and used for both reading and writing.
header = {}
HEADER_SIGNATURE.each do |header_item|
name, length, type = *header_item
header[name] = @stream.decode(length, type)
end
# Extract Freq, Phase & Slice Dimensions from diminfo
if header['dim_info']
header['freq_dim'] = dim_info_to_freq_dim(header['dim_info'])
header['phase_dim'] = dim_info_to_phase_dim(header['dim_info'])
header['slice_dim'] = dim_info_to_slice_dim(header['dim_info'])
end
header['sform_code_descr'] = XFORM_CODES[header['sform_code']]
header['qform_code_descr'] = XFORM_CODES[header['qform_code']]
return header
end | ruby | def parse_basic_header
# The HEADER_SIGNATURE is defined in NIFTI::Constants and used for both reading and writing.
header = {}
HEADER_SIGNATURE.each do |header_item|
name, length, type = *header_item
header[name] = @stream.decode(length, type)
end
# Extract Freq, Phase & Slice Dimensions from diminfo
if header['dim_info']
header['freq_dim'] = dim_info_to_freq_dim(header['dim_info'])
header['phase_dim'] = dim_info_to_phase_dim(header['dim_info'])
header['slice_dim'] = dim_info_to_slice_dim(header['dim_info'])
end
header['sform_code_descr'] = XFORM_CODES[header['sform_code']]
header['qform_code_descr'] = XFORM_CODES[header['qform_code']]
return header
end | [
"def",
"parse_basic_header",
"header",
"=",
"{",
"}",
"HEADER_SIGNATURE",
".",
"each",
"do",
"|",
"header_item",
"|",
"name",
",",
"length",
",",
"type",
"=",
"*",
"header_item",
"header",
"[",
"name",
"]",
"=",
"@stream",
".",
"decode",
"(",
"length",
",",
"type",
")",
"end",
"if",
"header",
"[",
"'dim_info'",
"]",
"header",
"[",
"'freq_dim'",
"]",
"=",
"dim_info_to_freq_dim",
"(",
"header",
"[",
"'dim_info'",
"]",
")",
"header",
"[",
"'phase_dim'",
"]",
"=",
"dim_info_to_phase_dim",
"(",
"header",
"[",
"'dim_info'",
"]",
")",
"header",
"[",
"'slice_dim'",
"]",
"=",
"dim_info_to_slice_dim",
"(",
"header",
"[",
"'dim_info'",
"]",
")",
"end",
"header",
"[",
"'sform_code_descr'",
"]",
"=",
"XFORM_CODES",
"[",
"header",
"[",
"'sform_code'",
"]",
"]",
"header",
"[",
"'qform_code_descr'",
"]",
"=",
"XFORM_CODES",
"[",
"header",
"[",
"'qform_code'",
"]",
"]",
"return",
"header",
"end"
] | Read the nifti header according to its byte signature.
The file stream will be left open and should be positioned at the end of the 348 byte header. | [
"Read",
"the",
"nifti",
"header",
"according",
"to",
"its",
"byte",
"signature",
".",
"The",
"file",
"stream",
"will",
"be",
"left",
"open",
"and",
"should",
"be",
"positioned",
"at",
"the",
"end",
"of",
"the",
"348",
"byte",
"header",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L157-L175 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.parse_extended_header | def parse_extended_header
extended = []
extension = @stream.decode(4, "BY")
# "After the end of the 348 byte header (e.g., after the magic field),
# the next 4 bytes are an byte array field named extension. By default,
# all 4 bytes of this array should be set to zero. In a .nii file, these 4
# bytes will always be present, since the earliest start point for the
# image data is byte #352. In a separate .hdr file, these bytes may or may
# not be present (i.e., a .hdr file may only be 348 bytes long). If not
# present, then a NIfTI-1.1 compliant program should use the default value
# of extension={0,0,0,0}. The first byte (extension[0]) is the only value
# of this array that is specified at present. The other 3 bytes are
# reserved for future use."
if extension[0] != 0
while @stream.index < @hdr['vox_offset']
esize, ecode = *@stream.decode(8, "UL")
data = @stream.decode(esize - 8, "STR")
extended << {:esize => esize, :ecode => ecode, :data => data}
end
# stream.decode(header['vox_offset'] - stream.index, "STR")
# stream.skip header['vox_offset'] - stream.index
end
return extended
end | ruby | def parse_extended_header
extended = []
extension = @stream.decode(4, "BY")
# "After the end of the 348 byte header (e.g., after the magic field),
# the next 4 bytes are an byte array field named extension. By default,
# all 4 bytes of this array should be set to zero. In a .nii file, these 4
# bytes will always be present, since the earliest start point for the
# image data is byte #352. In a separate .hdr file, these bytes may or may
# not be present (i.e., a .hdr file may only be 348 bytes long). If not
# present, then a NIfTI-1.1 compliant program should use the default value
# of extension={0,0,0,0}. The first byte (extension[0]) is the only value
# of this array that is specified at present. The other 3 bytes are
# reserved for future use."
if extension[0] != 0
while @stream.index < @hdr['vox_offset']
esize, ecode = *@stream.decode(8, "UL")
data = @stream.decode(esize - 8, "STR")
extended << {:esize => esize, :ecode => ecode, :data => data}
end
# stream.decode(header['vox_offset'] - stream.index, "STR")
# stream.skip header['vox_offset'] - stream.index
end
return extended
end | [
"def",
"parse_extended_header",
"extended",
"=",
"[",
"]",
"extension",
"=",
"@stream",
".",
"decode",
"(",
"4",
",",
"\"BY\"",
")",
"if",
"extension",
"[",
"0",
"]",
"!=",
"0",
"while",
"@stream",
".",
"index",
"<",
"@hdr",
"[",
"'vox_offset'",
"]",
"esize",
",",
"ecode",
"=",
"*",
"@stream",
".",
"decode",
"(",
"8",
",",
"\"UL\"",
")",
"data",
"=",
"@stream",
".",
"decode",
"(",
"esize",
"-",
"8",
",",
"\"STR\"",
")",
"extended",
"<<",
"{",
":esize",
"=>",
"esize",
",",
":ecode",
"=>",
"ecode",
",",
":data",
"=>",
"data",
"}",
"end",
"end",
"return",
"extended",
"end"
] | Read any extended header information.
The file stream will be left at imaging data itself, taking vox_offset into account for NIFTI Header Extended Attributes.
Pass in the voxel offset so the extended header knows when to stop reading. | [
"Read",
"any",
"extended",
"header",
"information",
".",
"The",
"file",
"stream",
"will",
"be",
"left",
"at",
"imaging",
"data",
"itself",
"taking",
"vox_offset",
"into",
"account",
"for",
"NIFTI",
"Header",
"Extended",
"Attributes",
".",
"Pass",
"in",
"the",
"voxel",
"offset",
"so",
"the",
"extended",
"header",
"knows",
"when",
"to",
"stop",
"reading",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L181-L205 | train |
brainmap/nifti | lib/nifti/n_read.rb | NIFTI.NRead.open_file | def open_file(file)
if File.exist?(file)
if File.readable?(file)
if not File.directory?(file)
if File.size(file) > 8
begin
@file = Zlib::GzipReader.new(File.new(file, "rb"))
rescue Zlib::GzipFile::Error
@file = File.new(file, "rb")
end
else
@msg << "Error! File is too small to contain DICOM information (#{file})."
end
else
@msg << "Error! File is a directory (#{file})."
end
else
@msg << "Error! File exists but I don't have permission to read it (#{file})."
end
else
@msg << "Error! The file you have supplied does not exist (#{file})."
end
end | ruby | def open_file(file)
if File.exist?(file)
if File.readable?(file)
if not File.directory?(file)
if File.size(file) > 8
begin
@file = Zlib::GzipReader.new(File.new(file, "rb"))
rescue Zlib::GzipFile::Error
@file = File.new(file, "rb")
end
else
@msg << "Error! File is too small to contain DICOM information (#{file})."
end
else
@msg << "Error! File is a directory (#{file})."
end
else
@msg << "Error! File exists but I don't have permission to read it (#{file})."
end
else
@msg << "Error! The file you have supplied does not exist (#{file})."
end
end | [
"def",
"open_file",
"(",
"file",
")",
"if",
"File",
".",
"exist?",
"(",
"file",
")",
"if",
"File",
".",
"readable?",
"(",
"file",
")",
"if",
"not",
"File",
".",
"directory?",
"(",
"file",
")",
"if",
"File",
".",
"size",
"(",
"file",
")",
">",
"8",
"begin",
"@file",
"=",
"Zlib",
"::",
"GzipReader",
".",
"new",
"(",
"File",
".",
"new",
"(",
"file",
",",
"\"rb\"",
")",
")",
"rescue",
"Zlib",
"::",
"GzipFile",
"::",
"Error",
"@file",
"=",
"File",
".",
"new",
"(",
"file",
",",
"\"rb\"",
")",
"end",
"else",
"@msg",
"<<",
"\"Error! File is too small to contain DICOM information (#{file}).\"",
"end",
"else",
"@msg",
"<<",
"\"Error! File is a directory (#{file}).\"",
"end",
"else",
"@msg",
"<<",
"\"Error! File exists but I don't have permission to read it (#{file}).\"",
"end",
"else",
"@msg",
"<<",
"\"Error! The file you have supplied does not exist (#{file}).\"",
"end",
"end"
] | Tests if a file is readable, and if so, opens it.
=== Parameters
* <tt>file</tt> -- A path/file string. | [
"Tests",
"if",
"a",
"file",
"is",
"readable",
"and",
"if",
"so",
"opens",
"it",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_read.rb#L213-L235 | train |
thelabtech/questionnaire | app/models/qe/text_field.rb | Qe.TextField.validation_class | def validation_class(answer_sheet)
validation = ''
validation += ' required' if self.required?(answer_sheet)
# validate-number, etc.
validate_style = ['number', 'currency-dollar', 'email', 'url', 'phone'].find {|v| v == self.style }
if validate_style
validation += ' validate-' + validate_style
end
validation
end | ruby | def validation_class(answer_sheet)
validation = ''
validation += ' required' if self.required?(answer_sheet)
# validate-number, etc.
validate_style = ['number', 'currency-dollar', 'email', 'url', 'phone'].find {|v| v == self.style }
if validate_style
validation += ' validate-' + validate_style
end
validation
end | [
"def",
"validation_class",
"(",
"answer_sheet",
")",
"validation",
"=",
"''",
"validation",
"+=",
"' required'",
"if",
"self",
".",
"required?",
"(",
"answer_sheet",
")",
"validate_style",
"=",
"[",
"'number'",
",",
"'currency-dollar'",
",",
"'email'",
",",
"'url'",
",",
"'phone'",
"]",
".",
"find",
"{",
"|",
"v",
"|",
"v",
"==",
"self",
".",
"style",
"}",
"if",
"validate_style",
"validation",
"+=",
"' validate-'",
"+",
"validate_style",
"end",
"validation",
"end"
] | css class names for javascript-based validation | [
"css",
"class",
"names",
"for",
"javascript",
"-",
"based",
"validation"
] | 02eb47cbcda8cca28a5db78e18623d0957aa2c9b | https://github.com/thelabtech/questionnaire/blob/02eb47cbcda8cca28a5db78e18623d0957aa2c9b/app/models/qe/text_field.rb#L17-L26 | train |
brainmap/nifti | lib/nifti/n_write.rb | NIFTI.NWrite.write | def write
# Check if we are able to create given file:
open_file(@file_name)
# Go ahead and write if the file was opened successfully:
if @file
# Initiate necessary variables:
init_variables
@file_endian = false
# Create a Stream instance to handle the encoding of content to a binary string:
@stream = Stream.new(nil, @file_endian)
# Tell the Stream instance which file to write to:
@stream.set_file(@file)
# Write Header and Image
write_basic_header
write_extended_header
write_image
# As file has been written successfully, it can be closed.
@file.close
# Mark this write session as successful:
@success = true
end
end | ruby | def write
# Check if we are able to create given file:
open_file(@file_name)
# Go ahead and write if the file was opened successfully:
if @file
# Initiate necessary variables:
init_variables
@file_endian = false
# Create a Stream instance to handle the encoding of content to a binary string:
@stream = Stream.new(nil, @file_endian)
# Tell the Stream instance which file to write to:
@stream.set_file(@file)
# Write Header and Image
write_basic_header
write_extended_header
write_image
# As file has been written successfully, it can be closed.
@file.close
# Mark this write session as successful:
@success = true
end
end | [
"def",
"write",
"open_file",
"(",
"@file_name",
")",
"if",
"@file",
"init_variables",
"@file_endian",
"=",
"false",
"@stream",
"=",
"Stream",
".",
"new",
"(",
"nil",
",",
"@file_endian",
")",
"@stream",
".",
"set_file",
"(",
"@file",
")",
"write_basic_header",
"write_extended_header",
"write_image",
"@file",
".",
"close",
"@success",
"=",
"true",
"end",
"end"
] | Creates an NWrite instance.
=== Parameters
* <tt>obj</tt> -- A NObject instance which will be used to encode a NIfTI string.
* <tt>file_name</tt> -- A string, either specifying the path of a DICOM file to be loaded, or a binary DICOM string to be parsed.
* <tt>options</tt> -- A hash of parameters.
=== Options
Handles the encoding of NIfTI information to string as well as writing it to file. | [
"Creates",
"an",
"NWrite",
"instance",
"."
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_write.rb#L33-L57 | train |
brainmap/nifti | lib/nifti/n_write.rb | NIFTI.NWrite.write_basic_header | def write_basic_header
HEADER_SIGNATURE.each do |header_item|
begin
name, length, type = *header_item
str = @stream.encode(@obj.header[name], type)
padded_str = @stream.encode_string_to_length(str, length)
# puts @stream.index, name, str.unpack(@stream.vr_to_str(type))
# pp padded_str.unpack(@stream.vr_to_str(type))
@stream.write padded_str
@stream.skip length
rescue StandardError => e
puts name, length, type, e
raise e
end
end
end | ruby | def write_basic_header
HEADER_SIGNATURE.each do |header_item|
begin
name, length, type = *header_item
str = @stream.encode(@obj.header[name], type)
padded_str = @stream.encode_string_to_length(str, length)
# puts @stream.index, name, str.unpack(@stream.vr_to_str(type))
# pp padded_str.unpack(@stream.vr_to_str(type))
@stream.write padded_str
@stream.skip length
rescue StandardError => e
puts name, length, type, e
raise e
end
end
end | [
"def",
"write_basic_header",
"HEADER_SIGNATURE",
".",
"each",
"do",
"|",
"header_item",
"|",
"begin",
"name",
",",
"length",
",",
"type",
"=",
"*",
"header_item",
"str",
"=",
"@stream",
".",
"encode",
"(",
"@obj",
".",
"header",
"[",
"name",
"]",
",",
"type",
")",
"padded_str",
"=",
"@stream",
".",
"encode_string_to_length",
"(",
"str",
",",
"length",
")",
"@stream",
".",
"write",
"padded_str",
"@stream",
".",
"skip",
"length",
"rescue",
"StandardError",
"=>",
"e",
"puts",
"name",
",",
"length",
",",
"type",
",",
"e",
"raise",
"e",
"end",
"end",
"end"
] | Write Basic Header | [
"Write",
"Basic",
"Header"
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_write.rb#L60-L76 | train |
brainmap/nifti | lib/nifti/n_write.rb | NIFTI.NWrite.write_extended_header | def write_extended_header
unless @obj.extended_header.empty?
@stream.write @stream.encode([1,0,0,0], "BY")
@obj.extended_header.each do |extension|
@stream.write @stream.encode extension[:esize], "UL"
@stream.write @stream.encode extension[:ecode], "UL"
@stream.write @stream.encode_string_to_length(@stream.encode(extension[:data], "STR"), extension[:esize] - 8)
end
else
@stream.write @stream.encode([0,0,0,0], "BY")
end
end | ruby | def write_extended_header
unless @obj.extended_header.empty?
@stream.write @stream.encode([1,0,0,0], "BY")
@obj.extended_header.each do |extension|
@stream.write @stream.encode extension[:esize], "UL"
@stream.write @stream.encode extension[:ecode], "UL"
@stream.write @stream.encode_string_to_length(@stream.encode(extension[:data], "STR"), extension[:esize] - 8)
end
else
@stream.write @stream.encode([0,0,0,0], "BY")
end
end | [
"def",
"write_extended_header",
"unless",
"@obj",
".",
"extended_header",
".",
"empty?",
"@stream",
".",
"write",
"@stream",
".",
"encode",
"(",
"[",
"1",
",",
"0",
",",
"0",
",",
"0",
"]",
",",
"\"BY\"",
")",
"@obj",
".",
"extended_header",
".",
"each",
"do",
"|",
"extension",
"|",
"@stream",
".",
"write",
"@stream",
".",
"encode",
"extension",
"[",
":esize",
"]",
",",
"\"UL\"",
"@stream",
".",
"write",
"@stream",
".",
"encode",
"extension",
"[",
":ecode",
"]",
",",
"\"UL\"",
"@stream",
".",
"write",
"@stream",
".",
"encode_string_to_length",
"(",
"@stream",
".",
"encode",
"(",
"extension",
"[",
":data",
"]",
",",
"\"STR\"",
")",
",",
"extension",
"[",
":esize",
"]",
"-",
"8",
")",
"end",
"else",
"@stream",
".",
"write",
"@stream",
".",
"encode",
"(",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
",",
"\"BY\"",
")",
"end",
"end"
] | Write Extended Header | [
"Write",
"Extended",
"Header"
] | a252ee91b4964116a72373aa5008f218fd695e57 | https://github.com/brainmap/nifti/blob/a252ee91b4964116a72373aa5008f218fd695e57/lib/nifti/n_write.rb#L79-L90 | train |
vchs/ruby_vcloud_sdk | lib/ruby_vcloud_sdk/powerable.rb | VCloudSdk.Powerable.power_on | def power_on
target = entity_xml
class_name = self.class.name.split("::").last
Config.logger.debug "#{class_name} status: #{target[:status]}"
if is_status?(target, :POWERED_ON)
Config.logger.info "#{class_name} #{target.name} is already powered-on."
return
end
power_on_link = target.power_on_link
unless power_on_link
fail CloudError,
"#{class_name} #{target.name} not in a state able to power on."
end
Config.logger.info "Powering on #{class_name} #{target.name}."
task = connection.post(power_on_link.href, nil)
task = monitor_task task, @session.time_limit[:power_on]
Config.logger.info "#{class_name} #{target.name} is powered on."
self
end | ruby | def power_on
target = entity_xml
class_name = self.class.name.split("::").last
Config.logger.debug "#{class_name} status: #{target[:status]}"
if is_status?(target, :POWERED_ON)
Config.logger.info "#{class_name} #{target.name} is already powered-on."
return
end
power_on_link = target.power_on_link
unless power_on_link
fail CloudError,
"#{class_name} #{target.name} not in a state able to power on."
end
Config.logger.info "Powering on #{class_name} #{target.name}."
task = connection.post(power_on_link.href, nil)
task = monitor_task task, @session.time_limit[:power_on]
Config.logger.info "#{class_name} #{target.name} is powered on."
self
end | [
"def",
"power_on",
"target",
"=",
"entity_xml",
"class_name",
"=",
"self",
".",
"class",
".",
"name",
".",
"split",
"(",
"\"::\"",
")",
".",
"last",
"Config",
".",
"logger",
".",
"debug",
"\"#{class_name} status: #{target[:status]}\"",
"if",
"is_status?",
"(",
"target",
",",
":POWERED_ON",
")",
"Config",
".",
"logger",
".",
"info",
"\"#{class_name} #{target.name} is already powered-on.\"",
"return",
"end",
"power_on_link",
"=",
"target",
".",
"power_on_link",
"unless",
"power_on_link",
"fail",
"CloudError",
",",
"\"#{class_name} #{target.name} not in a state able to power on.\"",
"end",
"Config",
".",
"logger",
".",
"info",
"\"Powering on #{class_name} #{target.name}.\"",
"task",
"=",
"connection",
".",
"post",
"(",
"power_on_link",
".",
"href",
",",
"nil",
")",
"task",
"=",
"monitor_task",
"task",
",",
"@session",
".",
"time_limit",
"[",
":power_on",
"]",
"Config",
".",
"logger",
".",
"info",
"\"#{class_name} #{target.name} is powered on.\"",
"self",
"end"
] | Power on VApp or VM | [
"Power",
"on",
"VApp",
"or",
"VM"
] | 92d56db4fea4321068ab300ca60bcc6cec3e459b | https://github.com/vchs/ruby_vcloud_sdk/blob/92d56db4fea4321068ab300ca60bcc6cec3e459b/lib/ruby_vcloud_sdk/powerable.rb#L15-L35 | train |
vchs/ruby_vcloud_sdk | lib/ruby_vcloud_sdk/powerable.rb | VCloudSdk.Powerable.power_off | def power_off
target = entity_xml
class_name = self.class.name.split("::").last
Config.logger.debug "#{class_name} status: #{target[:status]}"
if is_status?(target, :SUSPENDED)
error_msg = "#{class_name} #{target.name} suspended, discard state before powering off."
fail class_name == "VApp" ? VappSuspendedError : VmSuspendedError,
error_msg
end
if is_status?(target, :POWERED_OFF)
Config.logger.info "#{class_name} #{target.name} is already powered off."
return
end
power_off_link = target.power_off_link
unless power_off_link
fail CloudError, "#{class_name} #{target.name} is not in a state that could be powered off."
end
task = connection.post(power_off_link.href, nil)
monitor_task task, @session.time_limit[:power_off]
Config.logger.info "#{class_name} #{target.name} is powered off."
undeploy(target, class_name)
self
end | ruby | def power_off
target = entity_xml
class_name = self.class.name.split("::").last
Config.logger.debug "#{class_name} status: #{target[:status]}"
if is_status?(target, :SUSPENDED)
error_msg = "#{class_name} #{target.name} suspended, discard state before powering off."
fail class_name == "VApp" ? VappSuspendedError : VmSuspendedError,
error_msg
end
if is_status?(target, :POWERED_OFF)
Config.logger.info "#{class_name} #{target.name} is already powered off."
return
end
power_off_link = target.power_off_link
unless power_off_link
fail CloudError, "#{class_name} #{target.name} is not in a state that could be powered off."
end
task = connection.post(power_off_link.href, nil)
monitor_task task, @session.time_limit[:power_off]
Config.logger.info "#{class_name} #{target.name} is powered off."
undeploy(target, class_name)
self
end | [
"def",
"power_off",
"target",
"=",
"entity_xml",
"class_name",
"=",
"self",
".",
"class",
".",
"name",
".",
"split",
"(",
"\"::\"",
")",
".",
"last",
"Config",
".",
"logger",
".",
"debug",
"\"#{class_name} status: #{target[:status]}\"",
"if",
"is_status?",
"(",
"target",
",",
":SUSPENDED",
")",
"error_msg",
"=",
"\"#{class_name} #{target.name} suspended, discard state before powering off.\"",
"fail",
"class_name",
"==",
"\"VApp\"",
"?",
"VappSuspendedError",
":",
"VmSuspendedError",
",",
"error_msg",
"end",
"if",
"is_status?",
"(",
"target",
",",
":POWERED_OFF",
")",
"Config",
".",
"logger",
".",
"info",
"\"#{class_name} #{target.name} is already powered off.\"",
"return",
"end",
"power_off_link",
"=",
"target",
".",
"power_off_link",
"unless",
"power_off_link",
"fail",
"CloudError",
",",
"\"#{class_name} #{target.name} is not in a state that could be powered off.\"",
"end",
"task",
"=",
"connection",
".",
"post",
"(",
"power_off_link",
".",
"href",
",",
"nil",
")",
"monitor_task",
"task",
",",
"@session",
".",
"time_limit",
"[",
":power_off",
"]",
"Config",
".",
"logger",
".",
"info",
"\"#{class_name} #{target.name} is powered off.\"",
"undeploy",
"(",
"target",
",",
"class_name",
")",
"self",
"end"
] | Power off VApp or VM | [
"Power",
"off",
"VApp",
"or",
"VM"
] | 92d56db4fea4321068ab300ca60bcc6cec3e459b | https://github.com/vchs/ruby_vcloud_sdk/blob/92d56db4fea4321068ab300ca60bcc6cec3e459b/lib/ruby_vcloud_sdk/powerable.rb#L38-L63 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.cancel_encoding | def cancel_encoding(id, factory_id, opts = {})
data, _status_code, _headers = cancel_encoding_with_http_info(id, factory_id, opts)
return data
end | ruby | def cancel_encoding(id, factory_id, opts = {})
data, _status_code, _headers = cancel_encoding_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"cancel_encoding",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"cancel_encoding_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Cancels an Encoding.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [CanceledResponse] | [
"Cancels",
"an",
"Encoding",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L29-L32 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.copy_profile | def copy_profile(id, factory_id, copy_profile_body, opts = {})
data, _status_code, _headers = copy_profile_with_http_info(id, factory_id, copy_profile_body, opts)
return data
end | ruby | def copy_profile(id, factory_id, copy_profile_body, opts = {})
data, _status_code, _headers = copy_profile_with_http_info(id, factory_id, copy_profile_body, opts)
return data
end | [
"def",
"copy_profile",
"(",
"id",
",",
"factory_id",
",",
"copy_profile_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"copy_profile_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"copy_profile_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Copies a given Profile
@param id Id of a Profile.
@param factory_id Id of a Factory.
@param copy_profile_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :expand If expand option is set Profile objects will contain all command parameters, even if their value is default. By default this is not set.
@return [Profile] | [
"Copies",
"a",
"given",
"Profile"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L93-L96 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.create_encoding | def create_encoding(factory_id, create_encoding_body, opts = {})
data, _status_code, _headers = create_encoding_with_http_info(factory_id, create_encoding_body, opts)
return data
end | ruby | def create_encoding(factory_id, create_encoding_body, opts = {})
data, _status_code, _headers = create_encoding_with_http_info(factory_id, create_encoding_body, opts)
return data
end | [
"def",
"create_encoding",
"(",
"factory_id",
",",
"create_encoding_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_encoding_with_http_info",
"(",
"factory_id",
",",
"create_encoding_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates an Encoding
@param factory_id Id of a Factory.
@param create_encoding_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :screenshots Determines whether the response will include screenshots. By default this is not set.
@option opts [BOOLEAN] :precise_status Determines whether the response will include a precise status. By default this is not set.
@return [Encoding] | [
"Creates",
"an",
"Encoding"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L164-L167 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.create_factory | def create_factory(create_factory_body, opts = {})
data, _status_code, _headers = create_factory_with_http_info(create_factory_body, opts)
return data
end | ruby | def create_factory(create_factory_body, opts = {})
data, _status_code, _headers = create_factory_with_http_info(create_factory_body, opts)
return data
end | [
"def",
"create_factory",
"(",
"create_factory_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_factory_with_http_info",
"(",
"create_factory_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates a new factory
@param create_factory_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :with_storage_provider if set to `true`, results will include a storage provider's id
@return [Factory] | [
"Creates",
"a",
"new",
"factory"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L230-L233 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.create_profile | def create_profile(factory_id, create_profile_body, opts = {})
data, _status_code, _headers = create_profile_with_http_info(factory_id, create_profile_body, opts)
return data
end | ruby | def create_profile(factory_id, create_profile_body, opts = {})
data, _status_code, _headers = create_profile_with_http_info(factory_id, create_profile_body, opts)
return data
end | [
"def",
"create_profile",
"(",
"factory_id",
",",
"create_profile_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_profile_with_http_info",
"(",
"factory_id",
",",
"create_profile_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates a Profile
@param factory_id Id of a Factory.
@param create_profile_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :exclude_advanced_services
@option opts [BOOLEAN] :expand If expand option is set Profile objects will contain all command parameters, even if their value is default. By default it is not set.
@return [Profile] | [
"Creates",
"a",
"Profile"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L290-L293 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.create_video | def create_video(factory_id, create_video_body, opts = {})
data, _status_code, _headers = create_video_with_http_info(factory_id, create_video_body, opts)
return data
end | ruby | def create_video(factory_id, create_video_body, opts = {})
data, _status_code, _headers = create_video_with_http_info(factory_id, create_video_body, opts)
return data
end | [
"def",
"create_video",
"(",
"factory_id",
",",
"create_video_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"create_video_with_http_info",
"(",
"factory_id",
",",
"create_video_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Creates a Video from a provided source_url.
@param factory_id Id of a Factory.
@param create_video_body
@param [Hash] opts the optional parameters
@return [Video] | [
"Creates",
"a",
"Video",
"from",
"a",
"provided",
"source_url",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L356-L359 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.delete_encoding | def delete_encoding(id, factory_id, opts = {})
data, _status_code, _headers = delete_encoding_with_http_info(id, factory_id, opts)
return data
end | ruby | def delete_encoding(id, factory_id, opts = {})
data, _status_code, _headers = delete_encoding_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"delete_encoding",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"delete_encoding_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Deletes an Encoding from both Telestream Cloud and your storage. Returns an information whether the operation was successful.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [DeletedResponse] | [
"Deletes",
"an",
"Encoding",
"from",
"both",
"Telestream",
"Cloud",
"and",
"your",
"storage",
".",
"Returns",
"an",
"information",
"whether",
"the",
"operation",
"was",
"successful",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L482-L485 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.delete_profile | def delete_profile(id, factory_id, opts = {})
data, _status_code, _headers = delete_profile_with_http_info(id, factory_id, opts)
return data
end | ruby | def delete_profile(id, factory_id, opts = {})
data, _status_code, _headers = delete_profile_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"delete_profile",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"delete_profile_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Deletes a given Profile
@param id Id of a Profile
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [DeletedResponse] | [
"Deletes",
"a",
"given",
"Profile"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L544-L547 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.delete_video | def delete_video(id, factory_id, opts = {})
data, _status_code, _headers = delete_video_with_http_info(id, factory_id, opts)
return data
end | ruby | def delete_video(id, factory_id, opts = {})
data, _status_code, _headers = delete_video_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"delete_video",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"delete_video_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Deletes a Video object.
@param id Id of a Video.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [DeletedResponse] | [
"Deletes",
"a",
"Video",
"object",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L606-L609 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.delete_video_source | def delete_video_source(id, factory_id, opts = {})
data, _status_code, _headers = delete_video_source_with_http_info(id, factory_id, opts)
return data
end | ruby | def delete_video_source(id, factory_id, opts = {})
data, _status_code, _headers = delete_video_source_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"delete_video_source",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"delete_video_source_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Delete a video's source file.
@param id Id of a Video.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [DeletedResponse] | [
"Delete",
"a",
"video",
"s",
"source",
"file",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L668-L671 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.encoding | def encoding(id, factory_id, opts = {})
data, _status_code, _headers = encoding_with_http_info(id, factory_id, opts)
return data
end | ruby | def encoding(id, factory_id, opts = {})
data, _status_code, _headers = encoding_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"encoding",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"encoding_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns an Encoding object.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :screenshots Determines whether the response will include screenshots. By default this is not set.
@option opts [BOOLEAN] :precise_status Determines whether the response will include a precise status. By default this is not set.
@return [Encoding] | [
"Returns",
"an",
"Encoding",
"object",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L732-L735 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.encodings | def encodings(factory_id, opts = {})
data, _status_code, _headers = encodings_with_http_info(factory_id, opts)
return data
end | ruby | def encodings(factory_id, opts = {})
data, _status_code, _headers = encodings_with_http_info(factory_id, opts)
return data
end | [
"def",
"encodings",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"encodings_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a list of Encoding objects
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [String] :video_id Id of a Video. When specified, the resulting list will contain videos that belong to the Video.
@option opts [String] :status One of `success`, `fail`, `processing`. When specified, the resulting list will contain ecodings filtered by status.
@option opts [String] :profile_id Filter by profile_id.
@option opts [String] :profile_name Filter by profile_name.
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@option opts [BOOLEAN] :screenshots Determines whether the response will include screenshots. By default this is not set.
@option opts [BOOLEAN] :precise_status Determines whether the response will include a precise status. By default this is not set.
@return [PaginatedEncodingsCollection] | [
"Returns",
"a",
"list",
"of",
"Encoding",
"objects"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L805-L808 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.encodings_count | def encodings_count(factory_id, opts = {})
data, _status_code, _headers = encodings_count_with_http_info(factory_id, opts)
return data
end | ruby | def encodings_count(factory_id, opts = {})
data, _status_code, _headers = encodings_count_with_http_info(factory_id, opts)
return data
end | [
"def",
"encodings_count",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"encodings_count_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a number of Encoding objects created using a given factory.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [CountResponse] | [
"Returns",
"a",
"number",
"of",
"Encoding",
"objects",
"created",
"using",
"a",
"given",
"factory",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L877-L880 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.factory | def factory(id, opts = {})
data, _status_code, _headers = factory_with_http_info(id, opts)
return data
end | ruby | def factory(id, opts = {})
data, _status_code, _headers = factory_with_http_info(id, opts)
return data
end | [
"def",
"factory",
"(",
"id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"factory_with_http_info",
"(",
"id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a Factory object.
Returns a Factory object.
@param id id of a factory
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :with_storage_provider if set to `true`, results will include a storage provider's id
@return [Factory] | [
"Returns",
"a",
"Factory",
"object",
".",
"Returns",
"a",
"Factory",
"object",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L992-L995 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.notifications | def notifications(factory_id, opts = {})
data, _status_code, _headers = notifications_with_http_info(factory_id, opts)
return data
end | ruby | def notifications(factory_id, opts = {})
data, _status_code, _headers = notifications_with_http_info(factory_id, opts)
return data
end | [
"def",
"notifications",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"notifications_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a Factory's notification settings.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [CloudNotificationSettings] | [
"Returns",
"a",
"Factory",
"s",
"notification",
"settings",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1049-L1052 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.profile | def profile(id_or_name, factory_id, opts = {})
data, _status_code, _headers = profile_with_http_info(id_or_name, factory_id, opts)
return data
end | ruby | def profile(id_or_name, factory_id, opts = {})
data, _status_code, _headers = profile_with_http_info(id_or_name, factory_id, opts)
return data
end | [
"def",
"profile",
"(",
"id_or_name",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"profile_with_http_info",
"(",
"id_or_name",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a Profile object.
@param id_or_name A name or an id of a Profile.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :expand If expand option is set Profile objects will contain all command parameters, even if their value is default. By default this is not set.
@return [Profile] | [
"Returns",
"a",
"Profile",
"object",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1107-L1110 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.profile_encodings | def profile_encodings(id_or_name, factory_id, opts = {})
data, _status_code, _headers = profile_encodings_with_http_info(id_or_name, factory_id, opts)
return data
end | ruby | def profile_encodings(id_or_name, factory_id, opts = {})
data, _status_code, _headers = profile_encodings_with_http_info(id_or_name, factory_id, opts)
return data
end | [
"def",
"profile_encodings",
"(",
"id_or_name",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"profile_encodings_with_http_info",
"(",
"id_or_name",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a list of Encodings that belong to a Profile.
@param id_or_name Id or name of a Profile.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [PaginatedEncodingsCollection] | [
"Returns",
"a",
"list",
"of",
"Encodings",
"that",
"belong",
"to",
"a",
"Profile",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1171-L1174 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.profiles | def profiles(factory_id, opts = {})
data, _status_code, _headers = profiles_with_http_info(factory_id, opts)
return data
end | ruby | def profiles(factory_id, opts = {})
data, _status_code, _headers = profiles_with_http_info(factory_id, opts)
return data
end | [
"def",
"profiles",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"profiles_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Profile objects.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :exclude_advanced_services Determine whether exclude Advanced Services profiles from the results. By default this is not set.
@option opts [BOOLEAN] :expand If expand option is set Profile objects will contain all command parameters, even if their value is default. By default this is not set.
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@return [PaginatedProfilesCollection] | [
"Returns",
"a",
"collection",
"of",
"Profile",
"objects",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1236-L1239 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.queued_videos | def queued_videos(factory_id, opts = {})
data, _status_code, _headers = queued_videos_with_http_info(factory_id, opts)
return data
end | ruby | def queued_videos(factory_id, opts = {})
data, _status_code, _headers = queued_videos_with_http_info(factory_id, opts)
return data
end | [
"def",
"queued_videos",
"(",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"queued_videos_with_http_info",
"(",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a collection of Video objects queued for encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@option opts [Integer] :page A page to be fetched. Default is `1`.
@option opts [Integer] :per_page A number of results per page. Default is `100`.
@return [PaginatedVideoCollection] | [
"Returns",
"a",
"collection",
"of",
"Video",
"objects",
"queued",
"for",
"encoding",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1302-L1305 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.retry_encoding | def retry_encoding(id, factory_id, opts = {})
data, _status_code, _headers = retry_encoding_with_http_info(id, factory_id, opts)
return data
end | ruby | def retry_encoding(id, factory_id, opts = {})
data, _status_code, _headers = retry_encoding_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"retry_encoding",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"retry_encoding_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Retries a failed encoding.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [RetriedResponse] | [
"Retries",
"a",
"failed",
"encoding",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1424-L1427 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.signed_encoding_url | def signed_encoding_url(id, factory_id, opts = {})
data, _status_code, _headers = signed_encoding_url_with_http_info(id, factory_id, opts)
return data
end | ruby | def signed_encoding_url(id, factory_id, opts = {})
data, _status_code, _headers = signed_encoding_url_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"signed_encoding_url",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"signed_encoding_url_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a signed url pointing to an Encoding.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [EncodingSignedUrl] | [
"Returns",
"a",
"signed",
"url",
"pointing",
"to",
"an",
"Encoding",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1486-L1489 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.signed_encoding_urls | def signed_encoding_urls(id, factory_id, opts = {})
data, _status_code, _headers = signed_encoding_urls_with_http_info(id, factory_id, opts)
return data
end | ruby | def signed_encoding_urls(id, factory_id, opts = {})
data, _status_code, _headers = signed_encoding_urls_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"signed_encoding_urls",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"signed_encoding_urls_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a list of signed urls pointing to an Encoding's outputs.
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [EncodingSignedUrls] | [
"Returns",
"a",
"list",
"of",
"signed",
"urls",
"pointing",
"to",
"an",
"Encoding",
"s",
"outputs",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1548-L1551 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.signed_video_url | def signed_video_url(id, factory_id, opts = {})
data, _status_code, _headers = signed_video_url_with_http_info(id, factory_id, opts)
return data
end | ruby | def signed_video_url(id, factory_id, opts = {})
data, _status_code, _headers = signed_video_url_with_http_info(id, factory_id, opts)
return data
end | [
"def",
"signed_video_url",
"(",
"id",
",",
"factory_id",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"signed_video_url_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"opts",
")",
"return",
"data",
"end"
] | Returns a signed url pointing to a Video.
@param id Id of a Video.
@param factory_id Id of a Factory.
@param [Hash] opts the optional parameters
@return [SignedVideoUrl] | [
"Returns",
"a",
"signed",
"url",
"pointing",
"to",
"a",
"Video",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1610-L1613 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.toggle_factory_sync | def toggle_factory_sync(id, factory_sync_body, opts = {})
data, _status_code, _headers = toggle_factory_sync_with_http_info(id, factory_sync_body, opts)
return data
end | ruby | def toggle_factory_sync(id, factory_sync_body, opts = {})
data, _status_code, _headers = toggle_factory_sync_with_http_info(id, factory_sync_body, opts)
return data
end | [
"def",
"toggle_factory_sync",
"(",
"id",
",",
"factory_sync_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"toggle_factory_sync_with_http_info",
"(",
"id",
",",
"factory_sync_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Toggles synchronisation settings.
@param id id of the factory
@param factory_sync_body
@param [Hash] opts the optional parameters
@return [FactorySync] | [
"Toggles",
"synchronisation",
"settings",
"."
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1672-L1675 | train |
Telestream/telestream-cloud-ruby-sdk | flip/lib/telestream_cloud_flip/api/flip_api.rb | TelestreamCloud::Flip.FlipApi.update_encoding | def update_encoding(id, factory_id, update_encoding_body, opts = {})
data, _status_code, _headers = update_encoding_with_http_info(id, factory_id, update_encoding_body, opts)
return data
end | ruby | def update_encoding(id, factory_id, update_encoding_body, opts = {})
data, _status_code, _headers = update_encoding_with_http_info(id, factory_id, update_encoding_body, opts)
return data
end | [
"def",
"update_encoding",
"(",
"id",
",",
"factory_id",
",",
"update_encoding_body",
",",
"opts",
"=",
"{",
"}",
")",
"data",
",",
"_status_code",
",",
"_headers",
"=",
"update_encoding_with_http_info",
"(",
"id",
",",
"factory_id",
",",
"update_encoding_body",
",",
"opts",
")",
"return",
"data",
"end"
] | Updates an Encoding
@param id Id of an Encoding.
@param factory_id Id of a Factory.
@param update_encoding_body
@param [Hash] opts the optional parameters
@option opts [BOOLEAN] :screenshots Determines whether the response will include screenshots. By default this is not set.
@option opts [BOOLEAN] :precise_status Determines whether the response will include a precise status. By default this is not set.
@return [Encoding] | [
"Updates",
"an",
"Encoding"
] | c232427aa3e84688ba41ec28e5bef1cc72832bf4 | https://github.com/Telestream/telestream-cloud-ruby-sdk/blob/c232427aa3e84688ba41ec28e5bef1cc72832bf4/flip/lib/telestream_cloud_flip/api/flip_api.rb#L1736-L1739 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.