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 list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
libvips/ruby-vips | lib/vips/object.rb | Vips.Object.get_typeof_error | def get_typeof_error name
pspec = get_pspec name
raise Vips::Error unless pspec
pspec[:value][:value_type]
end | ruby | def get_typeof_error name
pspec = get_pspec name
raise Vips::Error unless pspec
pspec[:value][:value_type]
end | [
"def",
"get_typeof_error",
"name",
"pspec",
"=",
"get_pspec",
"name",
"raise",
"Vips",
"::",
"Error",
"unless",
"pspec",
"pspec",
"[",
":value",
"]",
"[",
":value_type",
"]",
"end"
] | return a gtype, raise an error on not found | [
"return",
"a",
"gtype",
"raise",
"an",
"error",
"on",
"not",
"found"
] | 8f14b1afda91e1078d7a5e6afe94098fef2f2da1 | https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/object.rb#L133-L138 | train |
libvips/ruby-vips | lib/vips/gvalue.rb | GObject.GValue.set | def set value
# GLib::logger.debug("GObject::GValue.set") {
# "value = #{value.inspect[0..50]}"
# }
gtype = self[:gtype]
fundamental = ::GObject::g_type_fundamental gtype
case gtype
when GBOOL_TYPE
::GObject::g_value_set_boolean self, (value ? 1 : 0)
when G... | ruby | def set value
# GLib::logger.debug("GObject::GValue.set") {
# "value = #{value.inspect[0..50]}"
# }
gtype = self[:gtype]
fundamental = ::GObject::g_type_fundamental gtype
case gtype
when GBOOL_TYPE
::GObject::g_value_set_boolean self, (value ? 1 : 0)
when G... | [
"def",
"set",
"value",
"gtype",
"=",
"self",
"[",
":gtype",
"]",
"fundamental",
"=",
"::",
"GObject",
"::",
"g_type_fundamental",
"gtype",
"case",
"gtype",
"when",
"GBOOL_TYPE",
"::",
"GObject",
"::",
"g_value_set_boolean",
"self",
",",
"(",
"value",
"?",
"1... | Set the value of a GValue. The value is converted to the type of the
GValue, if possible.
@param value [Any] The value to set | [
"Set",
"the",
"value",
"of",
"a",
"GValue",
".",
"The",
"value",
"is",
"converted",
"to",
"the",
"type",
"of",
"the",
"GValue",
"if",
"possible",
"."
] | 8f14b1afda91e1078d7a5e6afe94098fef2f2da1 | https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/gvalue.rb#L84-L163 | train |
libvips/ruby-vips | lib/vips/gvalue.rb | GObject.GValue.get | def get
gtype = self[:gtype]
fundamental = ::GObject::g_type_fundamental gtype
result = nil
case gtype
when GBOOL_TYPE
result = ::GObject::g_value_get_boolean(self) != 0 ? true : false
when GINT_TYPE
result = ::GObject::g_value_get_int self
when GUINT64_TYPE
... | ruby | def get
gtype = self[:gtype]
fundamental = ::GObject::g_type_fundamental gtype
result = nil
case gtype
when GBOOL_TYPE
result = ::GObject::g_value_get_boolean(self) != 0 ? true : false
when GINT_TYPE
result = ::GObject::g_value_get_int self
when GUINT64_TYPE
... | [
"def",
"get",
"gtype",
"=",
"self",
"[",
":gtype",
"]",
"fundamental",
"=",
"::",
"GObject",
"::",
"g_type_fundamental",
"gtype",
"result",
"=",
"nil",
"case",
"gtype",
"when",
"GBOOL_TYPE",
"result",
"=",
"::",
"GObject",
"::",
"g_value_get_boolean",
"(",
"... | Get the value of a GValue. The value is converted to a Ruby type in
the obvious way.
@return [Any] the value held by the GValue | [
"Get",
"the",
"value",
"of",
"a",
"GValue",
".",
"The",
"value",
"is",
"converted",
"to",
"a",
"Ruby",
"type",
"in",
"the",
"obvious",
"way",
"."
] | 8f14b1afda91e1078d7a5e6afe94098fef2f2da1 | https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/gvalue.rb#L169-L247 | train |
pcreux/csv-importer | lib/csv_importer/runner.rb | CSVImporter.Runner.call | def call
if rows.empty?
report.done!
return report
end
report.in_progress!
persist_rows!
report.done!
report
rescue ImportAborted
report.aborted!
report
end | ruby | def call
if rows.empty?
report.done!
return report
end
report.in_progress!
persist_rows!
report.done!
report
rescue ImportAborted
report.aborted!
report
end | [
"def",
"call",
"if",
"rows",
".",
"empty?",
"report",
".",
"done!",
"return",
"report",
"end",
"report",
".",
"in_progress!",
"persist_rows!",
"report",
".",
"done!",
"report",
"rescue",
"ImportAborted",
"report",
".",
"aborted!",
"report",
"end"
] | Persist the rows' model and return a `Report` | [
"Persist",
"the",
"rows",
"model",
"and",
"return",
"a",
"Report"
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/runner.rb#L21-L36 | train |
pcreux/csv-importer | lib/csv_importer/csv_reader.rb | CSVImporter.CSVReader.sanitize_cells | def sanitize_cells(rows)
rows.map do |cells|
cells.map do |cell|
cell ? cell.strip : ""
end
end
end | ruby | def sanitize_cells(rows)
rows.map do |cells|
cells.map do |cell|
cell ? cell.strip : ""
end
end
end | [
"def",
"sanitize_cells",
"(",
"rows",
")",
"rows",
".",
"map",
"do",
"|",
"cells",
"|",
"cells",
".",
"map",
"do",
"|",
"cell",
"|",
"cell",
"?",
"cell",
".",
"strip",
":",
"\"\"",
"end",
"end",
"end"
] | Remove trailing white spaces and ensure we always return a string | [
"Remove",
"trailing",
"white",
"spaces",
"and",
"ensure",
"we",
"always",
"return",
"a",
"string"
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/csv_reader.rb#L60-L66 | train |
pcreux/csv-importer | lib/csv_importer/row.rb | CSVImporter.Row.model | def model
@model ||= begin
model = find_or_build_model
set_attributes(model)
after_build_blocks.each { |block| instance_exec(model, &block) }
model
end
end | ruby | def model
@model ||= begin
model = find_or_build_model
set_attributes(model)
after_build_blocks.each { |block| instance_exec(model, &block) }
model
end
end | [
"def",
"model",
"@model",
"||=",
"begin",
"model",
"=",
"find_or_build_model",
"set_attributes",
"(",
"model",
")",
"after_build_blocks",
".",
"each",
"{",
"|",
"block",
"|",
"instance_exec",
"(",
"model",
",",
"&",
"block",
")",
"}",
"model",
"end",
"end"
] | The model to be persisted | [
"The",
"model",
"to",
"be",
"persisted"
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/row.rb#L18-L27 | train |
pcreux/csv-importer | lib/csv_importer/row.rb | CSVImporter.Row.set_attribute | def set_attribute(model, column, csv_value)
column_definition = column.definition
if column_definition.to && column_definition.to.is_a?(Proc)
to_proc = column_definition.to
case to_proc.arity
when 1 # to: ->(email) { email.downcase }
model.public_send("#{column_definition.... | ruby | def set_attribute(model, column, csv_value)
column_definition = column.definition
if column_definition.to && column_definition.to.is_a?(Proc)
to_proc = column_definition.to
case to_proc.arity
when 1 # to: ->(email) { email.downcase }
model.public_send("#{column_definition.... | [
"def",
"set_attribute",
"(",
"model",
",",
"column",
",",
"csv_value",
")",
"column_definition",
"=",
"column",
".",
"definition",
"if",
"column_definition",
".",
"to",
"&&",
"column_definition",
".",
"to",
".",
"is_a?",
"(",
"Proc",
")",
"to_proc",
"=",
"co... | Set the attribute using the column_definition and the csv_value | [
"Set",
"the",
"attribute",
"using",
"the",
"column_definition",
"and",
"the",
"csv_value"
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/row.rb#L53-L74 | train |
pcreux/csv-importer | lib/csv_importer/row.rb | CSVImporter.Row.errors | def errors
Hash[
model.errors.map do |attribute, errors|
if column_name = header.column_name_for_model_attribute(attribute)
[column_name, errors]
else
[attribute, errors]
end
end
]
end | ruby | def errors
Hash[
model.errors.map do |attribute, errors|
if column_name = header.column_name_for_model_attribute(attribute)
[column_name, errors]
else
[attribute, errors]
end
end
]
end | [
"def",
"errors",
"Hash",
"[",
"model",
".",
"errors",
".",
"map",
"do",
"|",
"attribute",
",",
"errors",
"|",
"if",
"column_name",
"=",
"header",
".",
"column_name_for_model_attribute",
"(",
"attribute",
")",
"[",
"column_name",
",",
"errors",
"]",
"else",
... | Error from the model mapped back to the CSV header if we can | [
"Error",
"from",
"the",
"model",
"mapped",
"back",
"to",
"the",
"CSV",
"header",
"if",
"we",
"can"
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/row.rb#L77-L87 | train |
pcreux/csv-importer | lib/csv_importer/column_definition.rb | CSVImporter.ColumnDefinition.match? | def match?(column_name, search_query=(as || name))
return false if column_name.nil?
downcased_column_name = column_name.downcase
underscored_column_name = downcased_column_name.gsub(/\s+/, '_')
case search_query
when Symbol
underscored_column_name == search_query.to_s
when ... | ruby | def match?(column_name, search_query=(as || name))
return false if column_name.nil?
downcased_column_name = column_name.downcase
underscored_column_name = downcased_column_name.gsub(/\s+/, '_')
case search_query
when Symbol
underscored_column_name == search_query.to_s
when ... | [
"def",
"match?",
"(",
"column_name",
",",
"search_query",
"=",
"(",
"as",
"||",
"name",
")",
")",
"return",
"false",
"if",
"column_name",
".",
"nil?",
"downcased_column_name",
"=",
"column_name",
".",
"downcase",
"underscored_column_name",
"=",
"downcased_column_n... | Return true if column definition matches the column name passed in. | [
"Return",
"true",
"if",
"column",
"definition",
"matches",
"the",
"column",
"name",
"passed",
"in",
"."
] | 942070b4b22eed0b36989b98fe4ebe9104b9f665 | https://github.com/pcreux/csv-importer/blob/942070b4b22eed0b36989b98fe4ebe9104b9f665/lib/csv_importer/column_definition.rb#L44-L62 | train |
piotrmurach/tty | lib/tty/templater.rb | TTY.Templater.generate | def generate(template_options, color_option)
templates.each do |src, dst|
source = @source_path.join(src)
destination = @target_path.join(dst).to_s
next unless ::File.exist?(source)
within_root_path do
TTY::File.copy_file(source, destination,
{ co... | ruby | def generate(template_options, color_option)
templates.each do |src, dst|
source = @source_path.join(src)
destination = @target_path.join(dst).to_s
next unless ::File.exist?(source)
within_root_path do
TTY::File.copy_file(source, destination,
{ co... | [
"def",
"generate",
"(",
"template_options",
",",
"color_option",
")",
"templates",
".",
"each",
"do",
"|",
"src",
",",
"dst",
"|",
"source",
"=",
"@source_path",
".",
"join",
"(",
"src",
")",
"destination",
"=",
"@target_path",
".",
"join",
"(",
"dst",
"... | Process templates by injecting vars and moving to location
@api private | [
"Process",
"templates",
"by",
"injecting",
"vars",
"and",
"moving",
"to",
"location"
] | 872fa26d321d95b48807569f25cb1633f6fecd17 | https://github.com/piotrmurach/tty/blob/872fa26d321d95b48807569f25cb1633f6fecd17/lib/tty/templater.rb#L41-L51 | train |
piotrmurach/tty | lib/tty/plugins.rb | TTY.Plugins.load_from | def load_from(gemspec_path, pattern)
Gem.refresh
spec = Gem::Specification.load(gemspec_path)
dependencies = spec.runtime_dependencies.concat(spec.development_dependencies)
dependencies.each do |gem|
gem_name = gem.name[pattern]
next if gem_name.to_s.empty?
register(gem_n... | ruby | def load_from(gemspec_path, pattern)
Gem.refresh
spec = Gem::Specification.load(gemspec_path)
dependencies = spec.runtime_dependencies.concat(spec.development_dependencies)
dependencies.each do |gem|
gem_name = gem.name[pattern]
next if gem_name.to_s.empty?
register(gem_n... | [
"def",
"load_from",
"(",
"gemspec_path",
",",
"pattern",
")",
"Gem",
".",
"refresh",
"spec",
"=",
"Gem",
"::",
"Specification",
".",
"load",
"(",
"gemspec_path",
")",
"dependencies",
"=",
"spec",
".",
"runtime_dependencies",
".",
"concat",
"(",
"spec",
".",
... | Loads gemspec from a file and registers gems matching pattern.
@param [String|Pathname] gemspec_path
the path to gemspec
@param [Regex] pattern
the pattern to match gems by
@example
plugins.load_from('foo.gemspec', /tty-(.*)/)
@api public | [
"Loads",
"gemspec",
"from",
"a",
"file",
"and",
"registers",
"gems",
"matching",
"pattern",
"."
] | 872fa26d321d95b48807569f25cb1633f6fecd17 | https://github.com/piotrmurach/tty/blob/872fa26d321d95b48807569f25cb1633f6fecd17/lib/tty/plugins.rb#L55-L65 | train |
piotrmurach/tty | lib/tty/plugins.rb | TTY.Plugins.names | def names
plugins.reduce({}) do |hash, plugin|
hash[plugin.name] = plugin
hash
end
end | ruby | def names
plugins.reduce({}) do |hash, plugin|
hash[plugin.name] = plugin
hash
end
end | [
"def",
"names",
"plugins",
".",
"reduce",
"(",
"{",
"}",
")",
"do",
"|",
"hash",
",",
"plugin",
"|",
"hash",
"[",
"plugin",
".",
"name",
"]",
"=",
"plugin",
"hash",
"end",
"end"
] | Return a list of all plugin names as strings
@api public | [
"Return",
"a",
"list",
"of",
"all",
"plugin",
"names",
"as",
"strings"
] | 872fa26d321d95b48807569f25cb1633f6fecd17 | https://github.com/piotrmurach/tty/blob/872fa26d321d95b48807569f25cb1633f6fecd17/lib/tty/plugins.rb#L80-L85 | train |
piotrmurach/tty | lib/tty/path_helpers.rb | TTY.PathHelpers.relative_path_from | def relative_path_from(root_path, path)
project_path = Pathname.new(path)
return project_path if project_path.relative?
project_path.relative_path_from(root_path)
end | ruby | def relative_path_from(root_path, path)
project_path = Pathname.new(path)
return project_path if project_path.relative?
project_path.relative_path_from(root_path)
end | [
"def",
"relative_path_from",
"(",
"root_path",
",",
"path",
")",
"project_path",
"=",
"Pathname",
".",
"new",
"(",
"path",
")",
"return",
"project_path",
"if",
"project_path",
".",
"relative?",
"project_path",
".",
"relative_path_from",
"(",
"root_path",
")",
"e... | Extract a relative path for the app
@api private | [
"Extract",
"a",
"relative",
"path",
"for",
"the",
"app"
] | 872fa26d321d95b48807569f25cb1633f6fecd17 | https://github.com/piotrmurach/tty/blob/872fa26d321d95b48807569f25cb1633f6fecd17/lib/tty/path_helpers.rb#L31-L35 | train |
heroku/databasedotcom | lib/databasedotcom/client.rb | Databasedotcom.Client.authenticate | def authenticate(options = nil)
if user_and_pass?(options)
req = https_request(self.host)
user = self.username || options[:username]
pass = self.password || options[:password]
path = encode_path_with_params('/services/oauth2/token', :grant_type => 'password', :client_id => self.cli... | ruby | def authenticate(options = nil)
if user_and_pass?(options)
req = https_request(self.host)
user = self.username || options[:username]
pass = self.password || options[:password]
path = encode_path_with_params('/services/oauth2/token', :grant_type => 'password', :client_id => self.cli... | [
"def",
"authenticate",
"(",
"options",
"=",
"nil",
")",
"if",
"user_and_pass?",
"(",
"options",
")",
"req",
"=",
"https_request",
"(",
"self",
".",
"host",
")",
"user",
"=",
"self",
".",
"username",
"||",
"options",
"[",
":username",
"]",
"pass",
"=",
... | Returns a new client object. _options_ can be one of the following
* A String containing the name of a YAML file formatted like:
---
client_id: <your_salesforce_client_id>
client_secret: <your_salesforce_client_secret>
host: login.salesforce.com
debugging: true
version: 23.0
sobject_module... | [
"Returns",
"a",
"new",
"client",
"object",
".",
"_options_",
"can",
"be",
"one",
"of",
"the",
"following"
] | a9173ff9c47bf2321a6959c9616d00cb6d8e93be | https://github.com/heroku/databasedotcom/blob/a9173ff9c47bf2321a6959c9616d00cb6d8e93be/lib/databasedotcom/client.rb#L103-L133 | train |
heroku/databasedotcom | lib/databasedotcom/client.rb | Databasedotcom.Client.list_sobjects | def list_sobjects
result = http_get("/services/data/v#{self.version}/sobjects")
if result.is_a?(Net::HTTPOK)
JSON.parse(result.body)["sobjects"].collect { |sobject| sobject["name"] }
elsif result.is_a?(Net::HTTPBadRequest)
raise SalesForceError.new(result)
end
end | ruby | def list_sobjects
result = http_get("/services/data/v#{self.version}/sobjects")
if result.is_a?(Net::HTTPOK)
JSON.parse(result.body)["sobjects"].collect { |sobject| sobject["name"] }
elsif result.is_a?(Net::HTTPBadRequest)
raise SalesForceError.new(result)
end
end | [
"def",
"list_sobjects",
"result",
"=",
"http_get",
"(",
"\"/services/data/v#{self.version}/sobjects\"",
")",
"if",
"result",
".",
"is_a?",
"(",
"Net",
"::",
"HTTPOK",
")",
"JSON",
".",
"parse",
"(",
"result",
".",
"body",
")",
"[",
"\"sobjects\"",
"]",
".",
... | Returns an Array of Strings listing the class names for every type of _Sobject_ in the database. Raises SalesForceError if an error occurs. | [
"Returns",
"an",
"Array",
"of",
"Strings",
"listing",
"the",
"class",
"names",
"for",
"every",
"type",
"of",
"_Sobject_",
"in",
"the",
"database",
".",
"Raises",
"SalesForceError",
"if",
"an",
"error",
"occurs",
"."
] | a9173ff9c47bf2321a6959c9616d00cb6d8e93be | https://github.com/heroku/databasedotcom/blob/a9173ff9c47bf2321a6959c9616d00cb6d8e93be/lib/databasedotcom/client.rb#L141-L148 | train |
heroku/databasedotcom | lib/databasedotcom/client.rb | Databasedotcom.Client.trending_topics | def trending_topics
result = http_get("/services/data/v#{self.version}/chatter/topics/trending")
result = JSON.parse(result.body)
result["topics"].collect { |topic| topic["name"] }
end | ruby | def trending_topics
result = http_get("/services/data/v#{self.version}/chatter/topics/trending")
result = JSON.parse(result.body)
result["topics"].collect { |topic| topic["name"] }
end | [
"def",
"trending_topics",
"result",
"=",
"http_get",
"(",
"\"/services/data/v#{self.version}/chatter/topics/trending\"",
")",
"result",
"=",
"JSON",
".",
"parse",
"(",
"result",
".",
"body",
")",
"result",
"[",
"\"topics\"",
"]",
".",
"collect",
"{",
"|",
"topic",... | Returns an array of trending topic names. | [
"Returns",
"an",
"array",
"of",
"trending",
"topic",
"names",
"."
] | a9173ff9c47bf2321a6959c9616d00cb6d8e93be | https://github.com/heroku/databasedotcom/blob/a9173ff9c47bf2321a6959c9616d00cb6d8e93be/lib/databasedotcom/client.rb#L278-L282 | train |
heroku/databasedotcom | lib/databasedotcom/client.rb | Databasedotcom.Client.record_from_hash | def record_from_hash(data)
attributes = data.delete('attributes')
new_record = find_or_materialize(attributes["type"]).new
data.each do |name, value|
field = new_record.description['fields'].find do |field|
key_from_label(field["label"]) == name || field["name"] == name || field["rel... | ruby | def record_from_hash(data)
attributes = data.delete('attributes')
new_record = find_or_materialize(attributes["type"]).new
data.each do |name, value|
field = new_record.description['fields'].find do |field|
key_from_label(field["label"]) == name || field["name"] == name || field["rel... | [
"def",
"record_from_hash",
"(",
"data",
")",
"attributes",
"=",
"data",
".",
"delete",
"(",
"'attributes'",
")",
"new_record",
"=",
"find_or_materialize",
"(",
"attributes",
"[",
"\"type\"",
"]",
")",
".",
"new",
"data",
".",
"each",
"do",
"|",
"name",
","... | Converts a Hash of object data into a concrete SObject | [
"Converts",
"a",
"Hash",
"of",
"object",
"data",
"into",
"a",
"concrete",
"SObject"
] | a9173ff9c47bf2321a6959c9616d00cb6d8e93be | https://github.com/heroku/databasedotcom/blob/a9173ff9c47bf2321a6959c9616d00cb6d8e93be/lib/databasedotcom/client.rb#L437-L461 | train |
DamirSvrtan/fasterer | lib/fasterer/scanners/method_call_scanner.rb | Fasterer.MethodCallScanner.check_symbol_to_proc | def check_symbol_to_proc
return unless method_call.block_argument_names.count == 1
return if method_call.block_body.nil?
return unless method_call.block_body.sexp_type == :call
return if method_call.arguments.count > 0
body_method_call = MethodCall.new(method_call.block_body)
retur... | ruby | def check_symbol_to_proc
return unless method_call.block_argument_names.count == 1
return if method_call.block_body.nil?
return unless method_call.block_body.sexp_type == :call
return if method_call.arguments.count > 0
body_method_call = MethodCall.new(method_call.block_body)
retur... | [
"def",
"check_symbol_to_proc",
"return",
"unless",
"method_call",
".",
"block_argument_names",
".",
"count",
"==",
"1",
"return",
"if",
"method_call",
".",
"block_body",
".",
"nil?",
"return",
"unless",
"method_call",
".",
"block_body",
".",
"sexp_type",
"==",
":c... | Need to refactor, fukken complicated conditions. | [
"Need",
"to",
"refactor",
"fukken",
"complicated",
"conditions",
"."
] | f451a740879efa3c82c0604e3cc80b651f3461ab | https://github.com/DamirSvrtan/fasterer/blob/f451a740879efa3c82c0604e3cc80b651f3461ab/lib/fasterer/scanners/method_call_scanner.rb#L123-L136 | train |
jmettraux/rufus-scheduler | lib/rufus/scheduler.rb | Rufus.Scheduler.scheduled? | def scheduled?(job_or_job_id)
job, _ = fetch(job_or_job_id)
!! (job && job.unscheduled_at.nil? && job.next_time != nil)
end | ruby | def scheduled?(job_or_job_id)
job, _ = fetch(job_or_job_id)
!! (job && job.unscheduled_at.nil? && job.next_time != nil)
end | [
"def",
"scheduled?",
"(",
"job_or_job_id",
")",
"job",
",",
"_",
"=",
"fetch",
"(",
"job_or_job_id",
")",
"!",
"!",
"(",
"job",
"&&",
"job",
".",
"unscheduled_at",
".",
"nil?",
"&&",
"job",
".",
"next_time",
"!=",
"nil",
")",
"end"
] | Returns true if this job is currently scheduled.
Takes extra care to answer true if the job is a repeat job
currently firing. | [
"Returns",
"true",
"if",
"this",
"job",
"is",
"currently",
"scheduled",
"."
] | db3b559fbd988ef44126ea59508e0c62bfc45540 | https://github.com/jmettraux/rufus-scheduler/blob/db3b559fbd988ef44126ea59508e0c62bfc45540/lib/rufus/scheduler.rb#L374-L379 | train |
toptal/crystalball | lib/crystalball/extensions/git/lib.rb | Git.Lib.merge_base | def merge_base(*args)
opts = args.last.is_a?(Hash) ? args.pop : {}
arg_opts = opts.map { |k, v| "--#{k}" if v }.compact + args
command('merge-base', arg_opts)
end | ruby | def merge_base(*args)
opts = args.last.is_a?(Hash) ? args.pop : {}
arg_opts = opts.map { |k, v| "--#{k}" if v }.compact + args
command('merge-base', arg_opts)
end | [
"def",
"merge_base",
"(",
"*",
"args",
")",
"opts",
"=",
"args",
".",
"last",
".",
"is_a?",
"(",
"Hash",
")",
"?",
"args",
".",
"pop",
":",
"{",
"}",
"arg_opts",
"=",
"opts",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"--#{k}\"",
"if",
"v",
... | `git merge-base ...`. Returns common ancestor for all passed commits
@param [Array<Object>] args - list of commits to process. Last argument can be options for merge-base command
@return [String] | [
"git",
"merge",
"-",
"base",
"...",
".",
"Returns",
"common",
"ancestor",
"for",
"all",
"passed",
"commits"
] | 9cb62597425e0d0d3e8b428c7d08d3940a43fdea | https://github.com/toptal/crystalball/blob/9cb62597425e0d0d3e8b428c7d08d3940a43fdea/lib/crystalball/extensions/git/lib.rb#L10-L16 | train |
toptal/crystalball | lib/crystalball/map_generator.rb | Crystalball.MapGenerator.start! | def start!
self.map = nil
map_storage.clear!
map_storage.dump(map.metadata.to_h)
strategies.reverse.each(&:after_start)
self.started = true
end | ruby | def start!
self.map = nil
map_storage.clear!
map_storage.dump(map.metadata.to_h)
strategies.reverse.each(&:after_start)
self.started = true
end | [
"def",
"start!",
"self",
".",
"map",
"=",
"nil",
"map_storage",
".",
"clear!",
"map_storage",
".",
"dump",
"(",
"map",
".",
"metadata",
".",
"to_h",
")",
"strategies",
".",
"reverse",
".",
"each",
"(",
"&",
":after_start",
")",
"self",
".",
"started",
... | Registers strategies and prepares metadata for execution map | [
"Registers",
"strategies",
"and",
"prepares",
"metadata",
"for",
"execution",
"map"
] | 9cb62597425e0d0d3e8b428c7d08d3940a43fdea | https://github.com/toptal/crystalball/blob/9cb62597425e0d0d3e8b428c7d08d3940a43fdea/lib/crystalball/map_generator.rb#L35-L42 | train |
toptal/crystalball | lib/crystalball/map_generator.rb | Crystalball.MapGenerator.refresh_for_case | def refresh_for_case(example)
map << strategies.run(ExampleGroupMap.new(example), example) { example.run }
check_dump_threshold
end | ruby | def refresh_for_case(example)
map << strategies.run(ExampleGroupMap.new(example), example) { example.run }
check_dump_threshold
end | [
"def",
"refresh_for_case",
"(",
"example",
")",
"map",
"<<",
"strategies",
".",
"run",
"(",
"ExampleGroupMap",
".",
"new",
"(",
"example",
")",
",",
"example",
")",
"{",
"example",
".",
"run",
"}",
"check_dump_threshold",
"end"
] | Runs example and collects execution map for it | [
"Runs",
"example",
"and",
"collects",
"execution",
"map",
"for",
"it"
] | 9cb62597425e0d0d3e8b428c7d08d3940a43fdea | https://github.com/toptal/crystalball/blob/9cb62597425e0d0d3e8b428c7d08d3940a43fdea/lib/crystalball/map_generator.rb#L45-L48 | train |
toptal/crystalball | lib/crystalball/map_generator.rb | Crystalball.MapGenerator.finalize! | def finalize!
return unless started
strategies.each(&:before_finalize)
return unless map.size.positive?
example_groups = (configuration.compact_map? ? MapCompactor.compact_map!(map) : map).example_groups
map_storage.dump(example_groups)
end | ruby | def finalize!
return unless started
strategies.each(&:before_finalize)
return unless map.size.positive?
example_groups = (configuration.compact_map? ? MapCompactor.compact_map!(map) : map).example_groups
map_storage.dump(example_groups)
end | [
"def",
"finalize!",
"return",
"unless",
"started",
"strategies",
".",
"each",
"(",
"&",
":before_finalize",
")",
"return",
"unless",
"map",
".",
"size",
".",
"positive?",
"example_groups",
"=",
"(",
"configuration",
".",
"compact_map?",
"?",
"MapCompactor",
".",... | Finalizes strategies and saves map | [
"Finalizes",
"strategies",
"and",
"saves",
"map"
] | 9cb62597425e0d0d3e8b428c7d08d3940a43fdea | https://github.com/toptal/crystalball/blob/9cb62597425e0d0d3e8b428c7d08d3940a43fdea/lib/crystalball/map_generator.rb#L51-L60 | train |
gdelugre/origami | lib/origami/page.rb | Origami.ResourcesHolder.add_resource | def add_resource(type, rsrc, name = nil)
if name.nil?
rsrc_name = self.resources(type).key(rsrc)
return rsrc_name if rsrc_name
end
name ||= new_id(type)
target = self.is_a?(Resources) ? self : (self.Resources ||= Resources.new)
... | ruby | def add_resource(type, rsrc, name = nil)
if name.nil?
rsrc_name = self.resources(type).key(rsrc)
return rsrc_name if rsrc_name
end
name ||= new_id(type)
target = self.is_a?(Resources) ? self : (self.Resources ||= Resources.new)
... | [
"def",
"add_resource",
"(",
"type",
",",
"rsrc",
",",
"name",
"=",
"nil",
")",
"if",
"name",
".",
"nil?",
"rsrc_name",
"=",
"self",
".",
"resources",
"(",
"type",
")",
".",
"key",
"(",
"rsrc",
")",
"return",
"rsrc_name",
"if",
"rsrc_name",
"end",
"na... | Adds a resource of the specified _type_ in the current object.
If _name_ is not specified, a new name will be automatically generated. | [
"Adds",
"a",
"resource",
"of",
"the",
"specified",
"_type_",
"in",
"the",
"current",
"object",
".",
"If",
"_name_",
"is",
"not",
"specified",
"a",
"new",
"name",
"will",
"be",
"automatically",
"generated",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L148-L161 | train |
gdelugre/origami | lib/origami/page.rb | Origami.ResourcesHolder.each_resource | def each_resource(type)
target = self.is_a?(Resources) ? self : (self.Resources ||= Resources.new)
rsrc = (target[type] and target[type].solve)
return enum_for(__method__, type) { rsrc.is_a?(Dictionary) ? rsrc.length : 0 } unless block_given?
return unless rsrc.is_a?(Di... | ruby | def each_resource(type)
target = self.is_a?(Resources) ? self : (self.Resources ||= Resources.new)
rsrc = (target[type] and target[type].solve)
return enum_for(__method__, type) { rsrc.is_a?(Dictionary) ? rsrc.length : 0 } unless block_given?
return unless rsrc.is_a?(Di... | [
"def",
"each_resource",
"(",
"type",
")",
"target",
"=",
"self",
".",
"is_a?",
"(",
"Resources",
")",
"?",
"self",
":",
"(",
"self",
".",
"Resources",
"||=",
"Resources",
".",
"new",
")",
"rsrc",
"=",
"(",
"target",
"[",
"type",
"]",
"and",
"target",... | Iterates over the resources by _type_. | [
"Iterates",
"over",
"the",
"resources",
"by",
"_type_",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L166-L177 | train |
gdelugre/origami | lib/origami/page.rb | Origami.ResourcesHolder.resources | def resources(type = nil)
if type.nil?
self.extgstates
.merge self.colorspaces
.merge self.patterns
.merge self.shadings
.merge self.xobjects
.merge self.fonts
.merge self.... | ruby | def resources(type = nil)
if type.nil?
self.extgstates
.merge self.colorspaces
.merge self.patterns
.merge self.shadings
.merge self.xobjects
.merge self.fonts
.merge self.... | [
"def",
"resources",
"(",
"type",
"=",
"nil",
")",
"if",
"type",
".",
"nil?",
"self",
".",
"extgstates",
".",
"merge",
"self",
".",
"colorspaces",
".",
"merge",
"self",
".",
"patterns",
".",
"merge",
"self",
".",
"shadings",
".",
"merge",
"self",
".",
... | Returns a Hash of all resources in the object or only the specified _type_. | [
"Returns",
"a",
"Hash",
"of",
"all",
"resources",
"in",
"the",
"object",
"or",
"only",
"the",
"specified",
"_type_",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L198-L210 | train |
gdelugre/origami | lib/origami/page.rb | Origami.PageTreeNode.each_page | def each_page(browsed_nodes: [], &block)
return enum_for(__method__) { self.Count.to_i } unless block_given?
if browsed_nodes.any?{|node| node.equal?(self)}
raise InvalidPageTreeError, "Cyclic tree graph detected"
end
unless self.Kids.is_a?(Array)
... | ruby | def each_page(browsed_nodes: [], &block)
return enum_for(__method__) { self.Count.to_i } unless block_given?
if browsed_nodes.any?{|node| node.equal?(self)}
raise InvalidPageTreeError, "Cyclic tree graph detected"
end
unless self.Kids.is_a?(Array)
... | [
"def",
"each_page",
"(",
"browsed_nodes",
":",
"[",
"]",
",",
"&",
"block",
")",
"return",
"enum_for",
"(",
"__method__",
")",
"{",
"self",
".",
"Count",
".",
"to_i",
"}",
"unless",
"block_given?",
"if",
"browsed_nodes",
".",
"any?",
"{",
"|",
"node",
... | Iterate through each page of that node. | [
"Iterate",
"through",
"each",
"page",
"of",
"that",
"node",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L345-L372 | train |
gdelugre/origami | lib/origami/page.rb | Origami.PageTreeNode.get_page | def get_page(n)
raise IndexError, "Page numbers are referenced starting from 1" if n < 1
raise IndexError, "Page not found" if n > self.Count.to_i
self.each_page.lazy.drop(n - 1).first or raise IndexError, "Page not found"
end | ruby | def get_page(n)
raise IndexError, "Page numbers are referenced starting from 1" if n < 1
raise IndexError, "Page not found" if n > self.Count.to_i
self.each_page.lazy.drop(n - 1).first or raise IndexError, "Page not found"
end | [
"def",
"get_page",
"(",
"n",
")",
"raise",
"IndexError",
",",
"\"Page numbers are referenced starting from 1\"",
"if",
"n",
"<",
"1",
"raise",
"IndexError",
",",
"\"Page not found\"",
"if",
"n",
">",
"self",
".",
"Count",
".",
"to_i",
"self",
".",
"each_page",
... | Get the n-th Page object in this node, starting from 1. | [
"Get",
"the",
"n",
"-",
"th",
"Page",
"object",
"in",
"this",
"node",
"starting",
"from",
"1",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L377-L382 | train |
gdelugre/origami | lib/origami/page.rb | Origami.Page.each_content_stream | def each_content_stream
contents = self.Contents
return enum_for(__method__) do
case contents
when Array then contents.length
when Stream then 1
else
0
end
end unless block_given?
... | ruby | def each_content_stream
contents = self.Contents
return enum_for(__method__) do
case contents
when Array then contents.length
when Stream then 1
else
0
end
end unless block_given?
... | [
"def",
"each_content_stream",
"contents",
"=",
"self",
".",
"Contents",
"return",
"enum_for",
"(",
"__method__",
")",
"do",
"case",
"contents",
"when",
"Array",
"then",
"contents",
".",
"length",
"when",
"Stream",
"then",
"1",
"else",
"0",
"end",
"end",
"unl... | Iterates over all the ContentStreams of the Page. | [
"Iterates",
"over",
"all",
"the",
"ContentStreams",
"of",
"the",
"Page",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L560-L576 | train |
gdelugre/origami | lib/origami/page.rb | Origami.Page.add_annotation | def add_annotation(*annotations)
self.Annots ||= []
annotations.each do |annot|
annot.solve[:P] = self if self.indirect?
self.Annots << annot
end
end | ruby | def add_annotation(*annotations)
self.Annots ||= []
annotations.each do |annot|
annot.solve[:P] = self if self.indirect?
self.Annots << annot
end
end | [
"def",
"add_annotation",
"(",
"*",
"annotations",
")",
"self",
".",
"Annots",
"||=",
"[",
"]",
"annotations",
".",
"each",
"do",
"|",
"annot",
"|",
"annot",
".",
"solve",
"[",
":P",
"]",
"=",
"self",
"if",
"self",
".",
"indirect?",
"self",
".",
"Anno... | Add an Annotation to the Page. | [
"Add",
"an",
"Annotation",
"to",
"the",
"Page",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L588-L595 | train |
gdelugre/origami | lib/origami/page.rb | Origami.Page.each_annotation | def each_annotation
annots = self.Annots
return enum_for(__method__) { annots.is_a?(Array) ? annots.length : 0 } unless block_given?
return unless annots.is_a?(Array)
annots.each do |annot|
yield(annot.solve)
end
end | ruby | def each_annotation
annots = self.Annots
return enum_for(__method__) { annots.is_a?(Array) ? annots.length : 0 } unless block_given?
return unless annots.is_a?(Array)
annots.each do |annot|
yield(annot.solve)
end
end | [
"def",
"each_annotation",
"annots",
"=",
"self",
".",
"Annots",
"return",
"enum_for",
"(",
"__method__",
")",
"{",
"annots",
".",
"is_a?",
"(",
"Array",
")",
"?",
"annots",
".",
"length",
":",
"0",
"}",
"unless",
"block_given?",
"return",
"unless",
"annots... | Iterate through each Annotation of the Page. | [
"Iterate",
"through",
"each",
"Annotation",
"of",
"the",
"Page",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L600-L609 | train |
gdelugre/origami | lib/origami/page.rb | Origami.Page.add_flash_application | def add_flash_application(swfspec, params = {})
options =
{
windowed: false,
transparent: false,
navigation_pane: false,
toolbar: false,
pass_context_click: false,
activation: Annotation::RichMedia::A... | ruby | def add_flash_application(swfspec, params = {})
options =
{
windowed: false,
transparent: false,
navigation_pane: false,
toolbar: false,
pass_context_click: false,
activation: Annotation::RichMedia::A... | [
"def",
"add_flash_application",
"(",
"swfspec",
",",
"params",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"windowed",
":",
"false",
",",
"transparent",
":",
"false",
",",
"navigation_pane",
":",
"false",
",",
"toolbar",
":",
"false",
",",
"pass_context_click",... | Embed a SWF Flash application in the page. | [
"Embed",
"a",
"SWF",
"Flash",
"application",
"in",
"the",
"page",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/page.rb#L621-L639 | train |
gdelugre/origami | lib/origami/metadata.rb | Origami.PDF.metadata | def metadata
metadata_stm = self.Catalog.Metadata
if metadata_stm.is_a?(Stream)
doc = REXML::Document.new(metadata_stm.data)
info = {}
doc.elements.each('*/*/rdf:Description') do |description|
description.attributes.each_attr... | ruby | def metadata
metadata_stm = self.Catalog.Metadata
if metadata_stm.is_a?(Stream)
doc = REXML::Document.new(metadata_stm.data)
info = {}
doc.elements.each('*/*/rdf:Description') do |description|
description.attributes.each_attr... | [
"def",
"metadata",
"metadata_stm",
"=",
"self",
".",
"Catalog",
".",
"Metadata",
"if",
"metadata_stm",
".",
"is_a?",
"(",
"Stream",
")",
"doc",
"=",
"REXML",
"::",
"Document",
".",
"new",
"(",
"metadata_stm",
".",
"data",
")",
"info",
"=",
"{",
"}",
"d... | Returns a Hash of the information found in the metadata stream | [
"Returns",
"a",
"Hash",
"of",
"the",
"information",
"found",
"in",
"the",
"metadata",
"stream"
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/metadata.rb#L59-L83 | train |
gdelugre/origami | lib/origami/metadata.rb | Origami.PDF.create_metadata | def create_metadata(info = {})
skeleton = <<-XMP
<?packet begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmln... | ruby | def create_metadata(info = {})
skeleton = <<-XMP
<?packet begin="\xef\xbb\xbf" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmln... | [
"def",
"create_metadata",
"(",
"info",
"=",
"{",
"}",
")",
"skeleton",
"=",
"<<-XMP",
"\\xef",
"\\xbb",
"\\xbf",
"XMP",
"xml",
"=",
"if",
"self",
".",
"Catalog",
".",
"Metadata",
".",
"is_a?",
"(",
"Stream",
")",
"self",
".",
"Catalog",
".",
"Metadata"... | Modifies or creates a metadata stream. | [
"Modifies",
"or",
"creates",
"a",
"metadata",
"stream",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/metadata.rb#L88-L126 | train |
gdelugre/origami | lib/origami/trailer.rb | Origami.PDF.trailer | def trailer
#
# First look for a standard trailer dictionary
#
if @revisions.last.trailer.dictionary?
trl = @revisions.last.trailer
#
# Otherwise look for a xref stream.
#
else
trl = @revisio... | ruby | def trailer
#
# First look for a standard trailer dictionary
#
if @revisions.last.trailer.dictionary?
trl = @revisions.last.trailer
#
# Otherwise look for a xref stream.
#
else
trl = @revisio... | [
"def",
"trailer",
"if",
"@revisions",
".",
"last",
".",
"trailer",
".",
"dictionary?",
"trl",
"=",
"@revisions",
".",
"last",
".",
"trailer",
"else",
"trl",
"=",
"@revisions",
".",
"last",
".",
"xrefstm",
"end",
"raise",
"InvalidPDFError",
",",
"\"No trailer... | Returns the current trailer.
This might be either a Trailer or XRefStream. | [
"Returns",
"the",
"current",
"trailer",
".",
"This",
"might",
"be",
"either",
"a",
"Trailer",
"or",
"XRefStream",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/trailer.rb#L29-L46 | train |
gdelugre/origami | lib/origami/extensions/ppklite.rb | Origami.PPKLite.add_certificate | def add_certificate(certfile, attributes, viewable: false, editable: false)
if certfile.is_a?(OpenSSL::X509::Certificate)
x509 = certfile
else
x509 = OpenSSL::X509::Certificate.new(certfile)
end
address_book = get_address_book
... | ruby | def add_certificate(certfile, attributes, viewable: false, editable: false)
if certfile.is_a?(OpenSSL::X509::Certificate)
x509 = certfile
else
x509 = OpenSSL::X509::Certificate.new(certfile)
end
address_book = get_address_book
... | [
"def",
"add_certificate",
"(",
"certfile",
",",
"attributes",
",",
"viewable",
":",
"false",
",",
"editable",
":",
"false",
")",
"if",
"certfile",
".",
"is_a?",
"(",
"OpenSSL",
"::",
"X509",
"::",
"Certificate",
")",
"x509",
"=",
"certfile",
"else",
"x509"... | Add a certificate into the address book | [
"Add",
"a",
"certificate",
"into",
"the",
"address",
"book"
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/extensions/ppklite.rb#L346-L365 | train |
gdelugre/origami | lib/origami/stream.rb | Origami.Stream.each_filter | def each_filter
filters = self.Filter
return enum_for(__method__) do
case filters
when NilClass then 0
when Array then filters.length
else
1
end
end unless block_given?
r... | ruby | def each_filter
filters = self.Filter
return enum_for(__method__) do
case filters
when NilClass then 0
when Array then filters.length
else
1
end
end unless block_given?
r... | [
"def",
"each_filter",
"filters",
"=",
"self",
".",
"Filter",
"return",
"enum_for",
"(",
"__method__",
")",
"do",
"case",
"filters",
"when",
"NilClass",
"then",
"0",
"when",
"Array",
"then",
"filters",
".",
"length",
"else",
"1",
"end",
"end",
"unless",
"bl... | Iterates over each Filter in the Stream. | [
"Iterates",
"over",
"each",
"Filter",
"in",
"the",
"Stream",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/stream.rb#L166-L187 | train |
gdelugre/origami | lib/origami/stream.rb | Origami.Stream.set_predictor | def set_predictor(predictor, colors: 1, bitspercomponent: 8, columns: 1)
filters = self.filters
layer = filters.index(:FlateDecode) or filters.index(:LZWDecode)
if layer.nil?
raise InvalidStreamObjectError, 'Predictor functions can only be used with Flate or LZW filt... | ruby | def set_predictor(predictor, colors: 1, bitspercomponent: 8, columns: 1)
filters = self.filters
layer = filters.index(:FlateDecode) or filters.index(:LZWDecode)
if layer.nil?
raise InvalidStreamObjectError, 'Predictor functions can only be used with Flate or LZW filt... | [
"def",
"set_predictor",
"(",
"predictor",
",",
"colors",
":",
"1",
",",
"bitspercomponent",
":",
"8",
",",
"columns",
":",
"1",
")",
"filters",
"=",
"self",
".",
"filters",
"layer",
"=",
"filters",
".",
"index",
"(",
":FlateDecode",
")",
"or",
"filters",... | Set predictor type for the current Stream.
Applies only for LZW and FlateDecode filters. | [
"Set",
"predictor",
"type",
"for",
"the",
"current",
"Stream",
".",
"Applies",
"only",
"for",
"LZW",
"and",
"FlateDecode",
"filters",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/stream.rb#L200-L217 | train |
gdelugre/origami | lib/origami/stream.rb | Origami.Stream.decode! | def decode!
self.decrypt! if self.is_a?(Encryption::EncryptedStream)
return if decoded?
filters = self.filters
dparams = decode_params
@data = @encoded_data.dup
@data.freeze
filters.each_with_index do |filter, layer|
... | ruby | def decode!
self.decrypt! if self.is_a?(Encryption::EncryptedStream)
return if decoded?
filters = self.filters
dparams = decode_params
@data = @encoded_data.dup
@data.freeze
filters.each_with_index do |filter, layer|
... | [
"def",
"decode!",
"self",
".",
"decrypt!",
"if",
"self",
".",
"is_a?",
"(",
"Encryption",
"::",
"EncryptedStream",
")",
"return",
"if",
"decoded?",
"filters",
"=",
"self",
".",
"filters",
"dparams",
"=",
"decode_params",
"@data",
"=",
"@encoded_data",
".",
"... | Uncompress the stream data. | [
"Uncompress",
"the",
"stream",
"data",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/stream.rb#L274-L304 | train |
gdelugre/origami | lib/origami/stream.rb | Origami.Stream.encode! | def encode!
return if encoded?
filters = self.filters
dparams = decode_params
@encoded_data = @data.dup
(filters.length - 1).downto(0) do |layer|
params = dparams[layer].is_a?(Dictionary) ? dparams[layer] : {}
filter = filters... | ruby | def encode!
return if encoded?
filters = self.filters
dparams = decode_params
@encoded_data = @data.dup
(filters.length - 1).downto(0) do |layer|
params = dparams[layer].is_a?(Dictionary) ? dparams[layer] : {}
filter = filters... | [
"def",
"encode!",
"return",
"if",
"encoded?",
"filters",
"=",
"self",
".",
"filters",
"dparams",
"=",
"decode_params",
"@encoded_data",
"=",
"@data",
".",
"dup",
"(",
"filters",
".",
"length",
"-",
"1",
")",
".",
"downto",
"(",
"0",
")",
"do",
"|",
"la... | Compress the stream data. | [
"Compress",
"the",
"stream",
"data",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/stream.rb#L309-L334 | train |
gdelugre/origami | lib/origami/stream.rb | Origami.ObjectStream.import_object_from_document | def import_object_from_document(object)
obj_doc = object.document
# Remove the previous instance if the object is indirect to avoid duplicates.
if obj_doc.equal?(@document)
@document.delete_object(object.reference) if object.indirect?
# Otherwise, create... | ruby | def import_object_from_document(object)
obj_doc = object.document
# Remove the previous instance if the object is indirect to avoid duplicates.
if obj_doc.equal?(@document)
@document.delete_object(object.reference) if object.indirect?
# Otherwise, create... | [
"def",
"import_object_from_document",
"(",
"object",
")",
"obj_doc",
"=",
"object",
".",
"document",
"if",
"obj_doc",
".",
"equal?",
"(",
"@document",
")",
"@document",
".",
"delete_object",
"(",
"object",
".",
"reference",
")",
"if",
"object",
".",
"indirect?... | Preprocess the object in case it already belongs to a document.
If the document is the same as the current object stream, remove the duplicate object from our document.
If the object comes from another document, use the export method to create a version without references. | [
"Preprocess",
"the",
"object",
"in",
"case",
"it",
"already",
"belongs",
"to",
"a",
"document",
".",
"If",
"the",
"document",
"is",
"the",
"same",
"as",
"the",
"current",
"object",
"stream",
"remove",
"the",
"duplicate",
"object",
"from",
"our",
"document",
... | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/stream.rb#L638-L651 | train |
gdelugre/origami | lib/origami/string.rb | Origami.String.to_utf8 | def to_utf8
detect_encoding
utf16 = self.encoding.to_utf16be(self.value)
utf16.slice!(0, Encoding::UTF16BE::BOM.size)
utf16.encode("utf-8", "utf-16be")
end | ruby | def to_utf8
detect_encoding
utf16 = self.encoding.to_utf16be(self.value)
utf16.slice!(0, Encoding::UTF16BE::BOM.size)
utf16.encode("utf-8", "utf-16be")
end | [
"def",
"to_utf8",
"detect_encoding",
"utf16",
"=",
"self",
".",
"encoding",
".",
"to_utf16be",
"(",
"self",
".",
"value",
")",
"utf16",
".",
"slice!",
"(",
"0",
",",
"Encoding",
"::",
"UTF16BE",
"::",
"BOM",
".",
"size",
")",
"utf16",
".",
"encode",
"(... | Convert String object to an UTF8 encoded Ruby string. | [
"Convert",
"String",
"object",
"to",
"an",
"UTF8",
"encoded",
"Ruby",
"string",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/string.rb#L121-L128 | train |
gdelugre/origami | lib/origami/graphics/xobject.rb | Origami.ContentStream.draw_polygon | def draw_polygon(coords = [], attr = {})
load!
stroke_color = attr.fetch(:stroke_color, DEFAULT_STROKE_COLOR)
fill_color = attr.fetch(:fill_color, DEFAULT_FILL_COLOR)
line_cap = attr.fetch(:line_cap, DEFAULT_LINECAP)
line_join = attr.fetch(:line_... | ruby | def draw_polygon(coords = [], attr = {})
load!
stroke_color = attr.fetch(:stroke_color, DEFAULT_STROKE_COLOR)
fill_color = attr.fetch(:fill_color, DEFAULT_FILL_COLOR)
line_cap = attr.fetch(:line_cap, DEFAULT_LINECAP)
line_join = attr.fetch(:line_... | [
"def",
"draw_polygon",
"(",
"coords",
"=",
"[",
"]",
",",
"attr",
"=",
"{",
"}",
")",
"load!",
"stroke_color",
"=",
"attr",
".",
"fetch",
"(",
":stroke_color",
",",
"DEFAULT_STROKE_COLOR",
")",
"fill_color",
"=",
"attr",
".",
"fetch",
"(",
":fill_color",
... | Draw a polygon from a array of coordinates. | [
"Draw",
"a",
"polygon",
"from",
"a",
"array",
"of",
"coordinates",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/graphics/xobject.rb#L96-L144 | train |
gdelugre/origami | lib/origami/object.rb | Origami.StandardObject.version_required | def version_required #:nodoc:
max = [ "1.0", 0 ]
self.each_key do |field|
attributes = self.class.fields[field.value]
if attributes.nil?
STDERR.puts "Warning: object #{self.class} has undocumented field #{field.value}"
next... | ruby | def version_required #:nodoc:
max = [ "1.0", 0 ]
self.each_key do |field|
attributes = self.class.fields[field.value]
if attributes.nil?
STDERR.puts "Warning: object #{self.class} has undocumented field #{field.value}"
next... | [
"def",
"version_required",
"max",
"=",
"[",
"\"1.0\"",
",",
"0",
"]",
"self",
".",
"each_key",
"do",
"|",
"field",
"|",
"attributes",
"=",
"self",
".",
"class",
".",
"fields",
"[",
"field",
".",
"value",
"]",
"if",
"attributes",
".",
"nil?",
"STDERR",
... | Returns the version and level required by the current Object. | [
"Returns",
"the",
"version",
"and",
"level",
"required",
"by",
"the",
"current",
"Object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L263-L281 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.set_indirect | def set_indirect(bool)
unless bool == true or bool == false
raise TypeError, "The argument must be boolean"
end
if bool == false
@no = @generation = 0
@document = nil
@file_offset = nil
end
@ind... | ruby | def set_indirect(bool)
unless bool == true or bool == false
raise TypeError, "The argument must be boolean"
end
if bool == false
@no = @generation = 0
@document = nil
@file_offset = nil
end
@ind... | [
"def",
"set_indirect",
"(",
"bool",
")",
"unless",
"bool",
"==",
"true",
"or",
"bool",
"==",
"false",
"raise",
"TypeError",
",",
"\"The argument must be boolean\"",
"end",
"if",
"bool",
"==",
"false",
"@no",
"=",
"@generation",
"=",
"0",
"@document",
"=",
"n... | Creates a new PDF Object.
Sets whether the object is indirect or not.
Indirect objects are allocated numbers at build time. | [
"Creates",
"a",
"new",
"PDF",
"Object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L409-L422 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.copy | def copy
saved_doc = @document
saved_parent = @parent
@document = @parent = nil # do not process parent object and document in the copy
# Perform the recursive copy (quite dirty).
copyobj = Marshal.load(Marshal.dump(self))
# restore saved values... | ruby | def copy
saved_doc = @document
saved_parent = @parent
@document = @parent = nil # do not process parent object and document in the copy
# Perform the recursive copy (quite dirty).
copyobj = Marshal.load(Marshal.dump(self))
# restore saved values... | [
"def",
"copy",
"saved_doc",
"=",
"@document",
"saved_parent",
"=",
"@parent",
"@document",
"=",
"@parent",
"=",
"nil",
"copyobj",
"=",
"Marshal",
".",
"load",
"(",
"Marshal",
".",
"dump",
"(",
"self",
")",
")",
"@document",
"=",
"saved_doc",
"@parent",
"="... | Deep copy of an object. | [
"Deep",
"copy",
"of",
"an",
"object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L457-L474 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.cast_to | def cast_to(type, parser = nil)
assert_cast_type(type)
cast = type.new(self.copy, parser)
cast.file_offset = @file_offset
transfer_attributes(cast)
end | ruby | def cast_to(type, parser = nil)
assert_cast_type(type)
cast = type.new(self.copy, parser)
cast.file_offset = @file_offset
transfer_attributes(cast)
end | [
"def",
"cast_to",
"(",
"type",
",",
"parser",
"=",
"nil",
")",
"assert_cast_type",
"(",
"type",
")",
"cast",
"=",
"type",
".",
"new",
"(",
"self",
".",
"copy",
",",
"parser",
")",
"cast",
".",
"file_offset",
"=",
"@file_offset",
"transfer_attributes",
"(... | Casts an object to a new type. | [
"Casts",
"an",
"object",
"to",
"a",
"new",
"type",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L479-L486 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.reference | def reference
raise InvalidObjectError, "Cannot reference a direct object" unless self.indirect?
ref = Reference.new(@no, @generation)
ref.parent = self
ref
end | ruby | def reference
raise InvalidObjectError, "Cannot reference a direct object" unless self.indirect?
ref = Reference.new(@no, @generation)
ref.parent = self
ref
end | [
"def",
"reference",
"raise",
"InvalidObjectError",
",",
"\"Cannot reference a direct object\"",
"unless",
"self",
".",
"indirect?",
"ref",
"=",
"Reference",
".",
"new",
"(",
"@no",
",",
"@generation",
")",
"ref",
".",
"parent",
"=",
"self",
"ref",
"end"
] | Returns an indirect reference to this object. | [
"Returns",
"an",
"indirect",
"reference",
"to",
"this",
"object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L491-L498 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.xrefs | def xrefs
raise InvalidObjectError, "Cannot find xrefs to a direct object" unless self.indirect?
raise InvalidObjectError, "Not attached to any document" if self.document.nil?
@document.each_object(compressed: true)
.flat_map { |object|
c... | ruby | def xrefs
raise InvalidObjectError, "Cannot find xrefs to a direct object" unless self.indirect?
raise InvalidObjectError, "Not attached to any document" if self.document.nil?
@document.each_object(compressed: true)
.flat_map { |object|
c... | [
"def",
"xrefs",
"raise",
"InvalidObjectError",
",",
"\"Cannot find xrefs to a direct object\"",
"unless",
"self",
".",
"indirect?",
"raise",
"InvalidObjectError",
",",
"\"Not attached to any document\"",
"if",
"self",
".",
"document",
".",
"nil?",
"@document",
".",
"each_... | Returns an array of references pointing to the current object. | [
"Returns",
"an",
"array",
"of",
"references",
"pointing",
"to",
"the",
"current",
"object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L503-L517 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.export | def export
exported_obj = self.logicalize
exported_obj.no = exported_obj.generation = 0
exported_obj.set_document(nil) if exported_obj.indirect?
exported_obj.parent = nil
exported_obj.xref_cache.clear
exported_obj
end | ruby | def export
exported_obj = self.logicalize
exported_obj.no = exported_obj.generation = 0
exported_obj.set_document(nil) if exported_obj.indirect?
exported_obj.parent = nil
exported_obj.xref_cache.clear
exported_obj
end | [
"def",
"export",
"exported_obj",
"=",
"self",
".",
"logicalize",
"exported_obj",
".",
"no",
"=",
"exported_obj",
".",
"generation",
"=",
"0",
"exported_obj",
".",
"set_document",
"(",
"nil",
")",
"if",
"exported_obj",
".",
"indirect?",
"exported_obj",
".",
"pa... | Creates an exportable version of current object.
The exportable version is a copy of _self_ with solved references, no owning PDF and no parent.
References to Catalog or PageTreeNode objects have been destroyed.
When exported, an object can be moved into another document without hassle. | [
"Creates",
"an",
"exportable",
"version",
"of",
"current",
"object",
".",
"The",
"exportable",
"version",
"is",
"a",
"copy",
"of",
"_self_",
"with",
"solved",
"references",
"no",
"owning",
"PDF",
"and",
"no",
"parent",
".",
"References",
"to",
"Catalog",
"or... | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L526-L534 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.type | def type
name = (self.class.name or self.class.superclass.name or self.native_type.name)
name.split("::").last.to_sym
end | ruby | def type
name = (self.class.name or self.class.superclass.name or self.native_type.name)
name.split("::").last.to_sym
end | [
"def",
"type",
"name",
"=",
"(",
"self",
".",
"class",
".",
"name",
"or",
"self",
".",
"class",
".",
"superclass",
".",
"name",
"or",
"self",
".",
"native_type",
".",
"name",
")",
"name",
".",
"split",
"(",
"\"::\"",
")",
".",
"last",
".",
"to_sym"... | Returns the symbol type of this Object. | [
"Returns",
"the",
"symbol",
"type",
"of",
"this",
"Object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L681-L685 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.transfer_attributes | def transfer_attributes(target)
target.no, target.generation = @no, @generation
target.parent = @parent
if self.indirect?
target.set_indirect(true)
target.set_document(@document)
end
target
end | ruby | def transfer_attributes(target)
target.no, target.generation = @no, @generation
target.parent = @parent
if self.indirect?
target.set_indirect(true)
target.set_document(@document)
end
target
end | [
"def",
"transfer_attributes",
"(",
"target",
")",
"target",
".",
"no",
",",
"target",
".",
"generation",
"=",
"@no",
",",
"@generation",
"target",
".",
"parent",
"=",
"@parent",
"if",
"self",
".",
"indirect?",
"target",
".",
"set_indirect",
"(",
"true",
")... | Copy the attributes of the current object to another object.
Copied attributes do not include the file offset. | [
"Copy",
"the",
"attributes",
"of",
"the",
"current",
"object",
"to",
"another",
"object",
".",
"Copied",
"attributes",
"do",
"not",
"include",
"the",
"file",
"offset",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L716-L725 | train |
gdelugre/origami | lib/origami/object.rb | Origami.Object.resolve_all_references | def resolve_all_references(obj, browsed: [], cache: {})
return obj if browsed.include?(obj)
browsed.push(obj)
if obj.is_a?(ObjectStream)
obj.each do |subobj|
resolve_all_references(subobj, browsed: browsed, cache: cache)
end
... | ruby | def resolve_all_references(obj, browsed: [], cache: {})
return obj if browsed.include?(obj)
browsed.push(obj)
if obj.is_a?(ObjectStream)
obj.each do |subobj|
resolve_all_references(subobj, browsed: browsed, cache: cache)
end
... | [
"def",
"resolve_all_references",
"(",
"obj",
",",
"browsed",
":",
"[",
"]",
",",
"cache",
":",
"{",
"}",
")",
"return",
"obj",
"if",
"browsed",
".",
"include?",
"(",
"obj",
")",
"browsed",
".",
"push",
"(",
"obj",
")",
"if",
"obj",
".",
"is_a?",
"(... | Replace all references of an object by their actual object value. | [
"Replace",
"all",
"references",
"of",
"an",
"object",
"by",
"their",
"actual",
"object",
"value",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/object.rb#L730-L757 | train |
gdelugre/origami | lib/origami/parser.rb | Origami.Parser.try_object_promotion | def try_object_promotion(obj)
return obj unless Origami::OPTIONS[:enable_type_propagation] and @deferred_casts.key?(obj.reference)
types = @deferred_casts[obj.reference]
types = [ types ] unless types.is_a?(::Array)
# Promote object if a compatible type is found.
... | ruby | def try_object_promotion(obj)
return obj unless Origami::OPTIONS[:enable_type_propagation] and @deferred_casts.key?(obj.reference)
types = @deferred_casts[obj.reference]
types = [ types ] unless types.is_a?(::Array)
# Promote object if a compatible type is found.
... | [
"def",
"try_object_promotion",
"(",
"obj",
")",
"return",
"obj",
"unless",
"Origami",
"::",
"OPTIONS",
"[",
":enable_type_propagation",
"]",
"and",
"@deferred_casts",
".",
"key?",
"(",
"obj",
".",
"reference",
")",
"types",
"=",
"@deferred_casts",
"[",
"obj",
... | Attempt to promote an object using the deferred casts. | [
"Attempt",
"to",
"promote",
"an",
"object",
"using",
"the",
"deferred",
"casts",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/parser.rb#L226-L239 | train |
gdelugre/origami | lib/origami/signature.rb | Origami.PDF.signed? | def signed?
begin
self.Catalog.AcroForm.is_a?(Dictionary) and
self.Catalog.AcroForm.SigFlags.is_a?(Integer) and
(self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURES_EXIST != 0)
rescue InvalidReferenceError
false
... | ruby | def signed?
begin
self.Catalog.AcroForm.is_a?(Dictionary) and
self.Catalog.AcroForm.SigFlags.is_a?(Integer) and
(self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURES_EXIST != 0)
rescue InvalidReferenceError
false
... | [
"def",
"signed?",
"begin",
"self",
".",
"Catalog",
".",
"AcroForm",
".",
"is_a?",
"(",
"Dictionary",
")",
"and",
"self",
".",
"Catalog",
".",
"AcroForm",
".",
"SigFlags",
".",
"is_a?",
"(",
"Integer",
")",
"and",
"(",
"self",
".",
"Catalog",
".",
"Acro... | Returns whether the document contains a digital signature. | [
"Returns",
"whether",
"the",
"document",
"contains",
"a",
"digital",
"signature",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/signature.rb#L194-L202 | train |
gdelugre/origami | lib/origami/signature.rb | Origami.PDF.extract_signed_data | def extract_signed_data(digsig)
# Computes the boundaries of the Contents field.
start_sig = digsig[:Contents].file_offset
stream = StringScanner.new(self.original_data)
stream.pos = digsig[:Contents].file_offset
Object.typeof(stream).parse(stream)
... | ruby | def extract_signed_data(digsig)
# Computes the boundaries of the Contents field.
start_sig = digsig[:Contents].file_offset
stream = StringScanner.new(self.original_data)
stream.pos = digsig[:Contents].file_offset
Object.typeof(stream).parse(stream)
... | [
"def",
"extract_signed_data",
"(",
"digsig",
")",
"start_sig",
"=",
"digsig",
"[",
":Contents",
"]",
".",
"file_offset",
"stream",
"=",
"StringScanner",
".",
"new",
"(",
"self",
".",
"original_data",
")",
"stream",
".",
"pos",
"=",
"digsig",
"[",
":Contents"... | Verifies the ByteRange field of a digital signature and returned the signed data. | [
"Verifies",
"the",
"ByteRange",
"field",
"of",
"a",
"digital",
"signature",
"and",
"returned",
"the",
"signed",
"data",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/signature.rb#L314-L334 | train |
gdelugre/origami | lib/origami/compound.rb | Origami.CompoundObject.update_values | def update_values(&b)
return enum_for(__method__) unless block_given?
return self.class.new self.transform_values(&b) if self.respond_to?(:transform_values)
return self.class.new self.map(&b) if self.respond_to?(:map)
raise NotImplementedError, "This object does not impl... | ruby | def update_values(&b)
return enum_for(__method__) unless block_given?
return self.class.new self.transform_values(&b) if self.respond_to?(:transform_values)
return self.class.new self.map(&b) if self.respond_to?(:map)
raise NotImplementedError, "This object does not impl... | [
"def",
"update_values",
"(",
"&",
"b",
")",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"return",
"self",
".",
"class",
".",
"new",
"self",
".",
"transform_values",
"(",
"&",
"b",
")",
"if",
"self",
".",
"respond_to?",
"(",
":... | Returns a new compound object with updated values based on the provided block. | [
"Returns",
"a",
"new",
"compound",
"object",
"with",
"updated",
"values",
"based",
"on",
"the",
"provided",
"block",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/compound.rb#L127-L133 | train |
gdelugre/origami | lib/origami/compound.rb | Origami.CompoundObject.update_values! | def update_values!(&b)
return enum_for(__method__) unless block_given?
return self.transform_values!(&b) if self.respond_to?(:transform_values!)
return self.map!(&b) if self.respond_to?(:map!)
raise NotImplementedError, "This object does not implement this method"
... | ruby | def update_values!(&b)
return enum_for(__method__) unless block_given?
return self.transform_values!(&b) if self.respond_to?(:transform_values!)
return self.map!(&b) if self.respond_to?(:map!)
raise NotImplementedError, "This object does not implement this method"
... | [
"def",
"update_values!",
"(",
"&",
"b",
")",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"return",
"self",
".",
"transform_values!",
"(",
"&",
"b",
")",
"if",
"self",
".",
"respond_to?",
"(",
":transform_values!",
")",
"return",
"... | Modifies the compound object's values based on the provided block. | [
"Modifies",
"the",
"compound",
"object",
"s",
"values",
"based",
"on",
"the",
"provided",
"block",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/compound.rb#L138-L144 | train |
gdelugre/origami | lib/origami/linearization.rb | Origami.PDF.linearized? | def linearized?
begin
first_obj = @revisions.first.objects.min_by{|obj| obj.file_offset}
rescue
return false
end
@revisions.size > 1 and first_obj.is_a?(Dictionary) and first_obj.has_key? :Linearized
end | ruby | def linearized?
begin
first_obj = @revisions.first.objects.min_by{|obj| obj.file_offset}
rescue
return false
end
@revisions.size > 1 and first_obj.is_a?(Dictionary) and first_obj.has_key? :Linearized
end | [
"def",
"linearized?",
"begin",
"first_obj",
"=",
"@revisions",
".",
"first",
".",
"objects",
".",
"min_by",
"{",
"|",
"obj",
"|",
"obj",
".",
"file_offset",
"}",
"rescue",
"return",
"false",
"end",
"@revisions",
".",
"size",
">",
"1",
"and",
"first_obj",
... | Returns whether the current document is linearized. | [
"Returns",
"whether",
"the",
"current",
"document",
"is",
"linearized",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/linearization.rb#L31-L39 | train |
gdelugre/origami | lib/origami/linearization.rb | Origami.PDF.delinearize! | def delinearize!
raise LinearizationError, 'Not a linearized document' unless self.linearized?
#
# Saves the first trailer.
#
prev_trailer = @revisions.first.trailer
linear_dict = @revisions.first.objects.min_by{|obj| obj.file_offset}
... | ruby | def delinearize!
raise LinearizationError, 'Not a linearized document' unless self.linearized?
#
# Saves the first trailer.
#
prev_trailer = @revisions.first.trailer
linear_dict = @revisions.first.objects.min_by{|obj| obj.file_offset}
... | [
"def",
"delinearize!",
"raise",
"LinearizationError",
",",
"'Not a linearized document'",
"unless",
"self",
".",
"linearized?",
"prev_trailer",
"=",
"@revisions",
".",
"first",
".",
"trailer",
"linear_dict",
"=",
"@revisions",
".",
"first",
".",
"objects",
".",
"min... | Tries to delinearize the document if it has been linearized.
This operation is xrefs destructive, should be fixed in the future to merge tables. | [
"Tries",
"to",
"delinearize",
"the",
"document",
"if",
"it",
"has",
"been",
"linearized",
".",
"This",
"operation",
"is",
"xrefs",
"destructive",
"should",
"be",
"fixed",
"in",
"the",
"future",
"to",
"merge",
"tables",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/linearization.rb#L45-L95 | train |
gdelugre/origami | lib/origami/linearization.rb | Origami.PDF.delete_hint_streams | def delete_hint_streams(linearization_dict)
hints = linearization_dict[:H]
return unless hints.is_a?(Array)
hints.each_slice(2) do |offset, _length|
next unless offset.is_a?(Integer)
stream = get_object_by_offset(offset)
delete_object... | ruby | def delete_hint_streams(linearization_dict)
hints = linearization_dict[:H]
return unless hints.is_a?(Array)
hints.each_slice(2) do |offset, _length|
next unless offset.is_a?(Integer)
stream = get_object_by_offset(offset)
delete_object... | [
"def",
"delete_hint_streams",
"(",
"linearization_dict",
")",
"hints",
"=",
"linearization_dict",
"[",
":H",
"]",
"return",
"unless",
"hints",
".",
"is_a?",
"(",
"Array",
")",
"hints",
".",
"each_slice",
"(",
"2",
")",
"do",
"|",
"offset",
",",
"_length",
... | Strip the document from Hint streams given a linearization dictionary. | [
"Strip",
"the",
"document",
"from",
"Hint",
"streams",
"given",
"a",
"linearization",
"dictionary",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/linearization.rb#L102-L112 | train |
gdelugre/origami | lib/origami/reference.rb | Origami.Reference.follow | def follow
doc = self.document
if doc.nil?
raise InvalidReferenceError, "Not attached to any document"
end
target = doc.get_object(self)
if target.nil? and not Origami::OPTIONS[:ignore_bad_references]
raise InvalidReferenceEr... | ruby | def follow
doc = self.document
if doc.nil?
raise InvalidReferenceError, "Not attached to any document"
end
target = doc.get_object(self)
if target.nil? and not Origami::OPTIONS[:ignore_bad_references]
raise InvalidReferenceEr... | [
"def",
"follow",
"doc",
"=",
"self",
".",
"document",
"if",
"doc",
".",
"nil?",
"raise",
"InvalidReferenceError",
",",
"\"Not attached to any document\"",
"end",
"target",
"=",
"doc",
".",
"get_object",
"(",
"self",
")",
"if",
"target",
".",
"nil?",
"and",
"... | Returns the object pointed to by the reference.
The reference must be part of a document.
Raises an InvalidReferenceError if the object cannot be found. | [
"Returns",
"the",
"object",
"pointed",
"to",
"by",
"the",
"reference",
".",
"The",
"reference",
"must",
"be",
"part",
"of",
"a",
"document",
".",
"Raises",
"an",
"InvalidReferenceError",
"if",
"the",
"object",
"cannot",
"be",
"found",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/reference.rb#L68-L82 | train |
gdelugre/origami | lib/origami/acroform.rb | Origami.PDF.create_form | def create_form(*fields)
acroform = self.Catalog.AcroForm ||= InteractiveForm.new.set_indirect(true)
self.add_fields(*fields)
acroform
end | ruby | def create_form(*fields)
acroform = self.Catalog.AcroForm ||= InteractiveForm.new.set_indirect(true)
self.add_fields(*fields)
acroform
end | [
"def",
"create_form",
"(",
"*",
"fields",
")",
"acroform",
"=",
"self",
".",
"Catalog",
".",
"AcroForm",
"||=",
"InteractiveForm",
".",
"new",
".",
"set_indirect",
"(",
"true",
")",
"self",
".",
"add_fields",
"(",
"*",
"fields",
")",
"acroform",
"end"
] | Creates a new AcroForm with specified fields. | [
"Creates",
"a",
"new",
"AcroForm",
"with",
"specified",
"fields",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/acroform.rb#L35-L40 | train |
gdelugre/origami | lib/origami/acroform.rb | Origami.PDF.each_field | def each_field
return enum_for(__method__) do
if self.form? and self.Catalog.AcroForm.Fields.is_a?(Array)
self.Catalog.AcroForm.Fields.length
else
0
end
end unless block_given?
if self.form? and ... | ruby | def each_field
return enum_for(__method__) do
if self.form? and self.Catalog.AcroForm.Fields.is_a?(Array)
self.Catalog.AcroForm.Fields.length
else
0
end
end unless block_given?
if self.form? and ... | [
"def",
"each_field",
"return",
"enum_for",
"(",
"__method__",
")",
"do",
"if",
"self",
".",
"form?",
"and",
"self",
".",
"Catalog",
".",
"AcroForm",
".",
"Fields",
".",
"is_a?",
"(",
"Array",
")",
"self",
".",
"Catalog",
".",
"AcroForm",
".",
"Fields",
... | Iterates over each Acroform Field. | [
"Iterates",
"over",
"each",
"Acroform",
"Field",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/acroform.rb#L68-L82 | train |
gdelugre/origami | lib/origami/encryption.rb | Origami.PDF.create_security_handler | def create_security_handler(version, revision, params)
# Ensure the document has an ID.
doc_id = (trailer_key(:ID) || generate_id).first
# Create the standard encryption dictionary.
handler = Encryption::Standard::Dictionary.new
handler.Filter = :Standard
... | ruby | def create_security_handler(version, revision, params)
# Ensure the document has an ID.
doc_id = (trailer_key(:ID) || generate_id).first
# Create the standard encryption dictionary.
handler = Encryption::Standard::Dictionary.new
handler.Filter = :Standard
... | [
"def",
"create_security_handler",
"(",
"version",
",",
"revision",
",",
"params",
")",
"doc_id",
"=",
"(",
"trailer_key",
"(",
":ID",
")",
"||",
"generate_id",
")",
".",
"first",
"handler",
"=",
"Encryption",
"::",
"Standard",
"::",
"Dictionary",
".",
"new",... | Installs the standard security dictionary, marking the document as being encrypted.
Returns the handler and the encryption key used for protecting contents. | [
"Installs",
"the",
"standard",
"security",
"dictionary",
"marking",
"the",
"document",
"as",
"being",
"encrypted",
".",
"Returns",
"the",
"handler",
"and",
"the",
"encryption",
"key",
"used",
"for",
"protecting",
"contents",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/encryption.rb#L123-L165 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.<< | def <<(object)
owner = object.document
#
# Does object belongs to another PDF ?
#
if owner and not owner.equal?(self)
import object
else
add_to_revision(object, @revisions.last)
end
end | ruby | def <<(object)
owner = object.document
#
# Does object belongs to another PDF ?
#
if owner and not owner.equal?(self)
import object
else
add_to_revision(object, @revisions.last)
end
end | [
"def",
"<<",
"(",
"object",
")",
"owner",
"=",
"object",
".",
"document",
"if",
"owner",
"and",
"not",
"owner",
".",
"equal?",
"(",
"self",
")",
"import",
"object",
"else",
"add_to_revision",
"(",
"object",
",",
"@revisions",
".",
"last",
")",
"end",
"... | Adds a new object to the PDF file.
If this object has no version number, then a new one will be automatically
computed and assignated to him.
It returns a Reference to this Object.
_object_:: The object to add. | [
"Adds",
"a",
"new",
"object",
"to",
"the",
"PDF",
"file",
".",
"If",
"this",
"object",
"has",
"no",
"version",
"number",
"then",
"a",
"new",
"one",
"will",
"be",
"automatically",
"computed",
"and",
"assignated",
"to",
"him",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L317-L328 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.add_to_revision | def add_to_revision(object, revision)
object.set_indirect(true)
object.set_document(self)
object.no, object.generation = allocate_new_object_number if object.no == 0
revision.body[object.reference] = object
object.reference
end | ruby | def add_to_revision(object, revision)
object.set_indirect(true)
object.set_document(self)
object.no, object.generation = allocate_new_object_number if object.no == 0
revision.body[object.reference] = object
object.reference
end | [
"def",
"add_to_revision",
"(",
"object",
",",
"revision",
")",
"object",
".",
"set_indirect",
"(",
"true",
")",
"object",
".",
"set_document",
"(",
"self",
")",
"object",
".",
"no",
",",
"object",
".",
"generation",
"=",
"allocate_new_object_number",
"if",
"... | Adds a new object to a specific revision.
If this object has no version number, then a new one will be automatically
computed and assignated to him.
It returns a Reference to this Object.
_object_:: The object to add.
_revision_:: The revision to add the object to. | [
"Adds",
"a",
"new",
"object",
"to",
"a",
"specific",
"revision",
".",
"If",
"this",
"object",
"has",
"no",
"version",
"number",
"then",
"a",
"new",
"one",
"will",
"be",
"automatically",
"computed",
"and",
"assignated",
"to",
"him",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L350-L359 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.add_new_revision | def add_new_revision
root = @revisions.last.trailer[:Root] unless @revisions.empty?
@revisions << Revision.new(self)
@revisions.last.trailer = Trailer.new
@revisions.last.trailer.Root = root
self
end | ruby | def add_new_revision
root = @revisions.last.trailer[:Root] unless @revisions.empty?
@revisions << Revision.new(self)
@revisions.last.trailer = Trailer.new
@revisions.last.trailer.Root = root
self
end | [
"def",
"add_new_revision",
"root",
"=",
"@revisions",
".",
"last",
".",
"trailer",
"[",
":Root",
"]",
"unless",
"@revisions",
".",
"empty?",
"@revisions",
"<<",
"Revision",
".",
"new",
"(",
"self",
")",
"@revisions",
".",
"last",
".",
"trailer",
"=",
"Trai... | Ends the current Revision, and starts a new one. | [
"Ends",
"the",
"current",
"Revision",
"and",
"starts",
"a",
"new",
"one",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L364-L372 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.delete_object | def delete_object(no, generation = 0)
case no
when Reference
target = no
when ::Integer
target = Reference.new(no, generation)
else
raise TypeError, "Invalid parameter type : #{no.class}"
end
@revisi... | ruby | def delete_object(no, generation = 0)
case no
when Reference
target = no
when ::Integer
target = Reference.new(no, generation)
else
raise TypeError, "Invalid parameter type : #{no.class}"
end
@revisi... | [
"def",
"delete_object",
"(",
"no",
",",
"generation",
"=",
"0",
")",
"case",
"no",
"when",
"Reference",
"target",
"=",
"no",
"when",
"::",
"Integer",
"target",
"=",
"Reference",
".",
"new",
"(",
"no",
",",
"generation",
")",
"else",
"raise",
"TypeError",... | Remove an object. | [
"Remove",
"an",
"object",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L401-L414 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.cast_object | def cast_object(reference, type) #:nodoc:
@revisions.each do |rev|
if rev.body.include?(reference)
object = rev.body[reference]
return object if object.is_a?(type)
if type < rev.body[reference].class
rev.bod... | ruby | def cast_object(reference, type) #:nodoc:
@revisions.each do |rev|
if rev.body.include?(reference)
object = rev.body[reference]
return object if object.is_a?(type)
if type < rev.body[reference].class
rev.bod... | [
"def",
"cast_object",
"(",
"reference",
",",
"type",
")",
"@revisions",
".",
"each",
"do",
"|",
"rev",
"|",
"if",
"rev",
".",
"body",
".",
"include?",
"(",
"reference",
")",
"object",
"=",
"rev",
".",
"body",
"[",
"reference",
"]",
"return",
"object",
... | Casts a PDF object into another object type.
The target type must be a subtype of the original type. | [
"Casts",
"a",
"PDF",
"object",
"into",
"another",
"object",
"type",
".",
"The",
"target",
"type",
"must",
"be",
"a",
"subtype",
"of",
"the",
"original",
"type",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L499-L514 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.search_object | def search_object(object, pattern, streams: true, object_streams: true)
result = []
case object
when Stream
result.concat object.dictionary.strings_cache.select{|str| str.match(pattern) }
result.concat object.dictionary.names_cache.select{|name| name.... | ruby | def search_object(object, pattern, streams: true, object_streams: true)
result = []
case object
when Stream
result.concat object.dictionary.strings_cache.select{|str| str.match(pattern) }
result.concat object.dictionary.names_cache.select{|name| name.... | [
"def",
"search_object",
"(",
"object",
",",
"pattern",
",",
"streams",
":",
"true",
",",
"object_streams",
":",
"true",
")",
"result",
"=",
"[",
"]",
"case",
"object",
"when",
"Stream",
"result",
".",
"concat",
"object",
".",
"dictionary",
".",
"strings_ca... | Searches through an object, possibly going into object streams.
Returns an array of matching strings, names and streams. | [
"Searches",
"through",
"an",
"object",
"possibly",
"going",
"into",
"object",
"streams",
".",
"Returns",
"an",
"array",
"of",
"matching",
"strings",
"names",
"and",
"streams",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L576-L606 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.load_object_at_offset | def load_object_at_offset(revision, offset)
return nil if loaded? or @parser.nil?
pos = @parser.pos
begin
object = @parser.parse_object(offset)
return nil if object.nil?
if self.is_a?(Encryption::EncryptedDocument)
... | ruby | def load_object_at_offset(revision, offset)
return nil if loaded? or @parser.nil?
pos = @parser.pos
begin
object = @parser.parse_object(offset)
return nil if object.nil?
if self.is_a?(Encryption::EncryptedDocument)
... | [
"def",
"load_object_at_offset",
"(",
"revision",
",",
"offset",
")",
"return",
"nil",
"if",
"loaded?",
"or",
"@parser",
".",
"nil?",
"pos",
"=",
"@parser",
".",
"pos",
"begin",
"object",
"=",
"@parser",
".",
"parse_object",
"(",
"offset",
")",
"return",
"n... | Load an object from its given file offset.
The document must have an associated Parser. | [
"Load",
"an",
"object",
"from",
"its",
"given",
"file",
"offset",
".",
"The",
"document",
"must",
"have",
"an",
"associated",
"Parser",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L612-L630 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.make_encrypted_object | def make_encrypted_object(object)
case object
when String
object.extend(Encryption::EncryptedString)
when Stream
object.extend(Encryption::EncryptedStream)
when ObjectCache
object.strings_cache.each do |string|
... | ruby | def make_encrypted_object(object)
case object
when String
object.extend(Encryption::EncryptedString)
when Stream
object.extend(Encryption::EncryptedStream)
when ObjectCache
object.strings_cache.each do |string|
... | [
"def",
"make_encrypted_object",
"(",
"object",
")",
"case",
"object",
"when",
"String",
"object",
".",
"extend",
"(",
"Encryption",
"::",
"EncryptedString",
")",
"when",
"Stream",
"object",
".",
"extend",
"(",
"Encryption",
"::",
"EncryptedStream",
")",
"when",
... | Method called on encrypted objects loaded into the document. | [
"Method",
"called",
"on",
"encrypted",
"objects",
"loaded",
"into",
"the",
"document",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L635-L646 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.load_all_objects | def load_all_objects
return if loaded? or @parser.nil?
@revisions.each do |revision|
if revision.xreftable?
xrefs = revision.xreftable
elsif revision.xrefstm?
xrefs = revision.xrefstm
else
... | ruby | def load_all_objects
return if loaded? or @parser.nil?
@revisions.each do |revision|
if revision.xreftable?
xrefs = revision.xreftable
elsif revision.xrefstm?
xrefs = revision.xrefstm
else
... | [
"def",
"load_all_objects",
"return",
"if",
"loaded?",
"or",
"@parser",
".",
"nil?",
"@revisions",
".",
"each",
"do",
"|",
"revision",
"|",
"if",
"revision",
".",
"xreftable?",
"xrefs",
"=",
"revision",
".",
"xreftable",
"elsif",
"revision",
".",
"xrefstm?",
... | Force the loading of all objects in the document. | [
"Force",
"the",
"loading",
"of",
"all",
"objects",
"in",
"the",
"document",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L651-L669 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.physicalize | def physicalize(options = {})
@revisions.each do |revision|
# Do not use each_object here as build_object may modify the iterator.
revision.objects.each do |obj|
build_object(obj, revision, options)
end
end
self
... | ruby | def physicalize(options = {})
@revisions.each do |revision|
# Do not use each_object here as build_object may modify the iterator.
revision.objects.each do |obj|
build_object(obj, revision, options)
end
end
self
... | [
"def",
"physicalize",
"(",
"options",
"=",
"{",
"}",
")",
"@revisions",
".",
"each",
"do",
"|",
"revision",
"|",
"revision",
".",
"objects",
".",
"each",
"do",
"|",
"obj",
"|",
"build_object",
"(",
"obj",
",",
"revision",
",",
"options",
")",
"end",
... | Converts a logical PDF view into a physical view ready for writing. | [
"Converts",
"a",
"logical",
"PDF",
"view",
"into",
"a",
"physical",
"view",
"ready",
"for",
"writing",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L731-L741 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.init | def init
catalog = (self.Catalog = (trailer_key(:Root) || Catalog.new))
@revisions.last.trailer.Root = catalog.reference
loaded!
self
end | ruby | def init
catalog = (self.Catalog = (trailer_key(:Root) || Catalog.new))
@revisions.last.trailer.Root = catalog.reference
loaded!
self
end | [
"def",
"init",
"catalog",
"=",
"(",
"self",
".",
"Catalog",
"=",
"(",
"trailer_key",
"(",
":Root",
")",
"||",
"Catalog",
".",
"new",
")",
")",
"@revisions",
".",
"last",
".",
"trailer",
".",
"Root",
"=",
"catalog",
".",
"reference",
"loaded!",
"self",
... | Instanciates basic structures required for a valid PDF file. | [
"Instanciates",
"basic",
"structures",
"required",
"for",
"a",
"valid",
"PDF",
"file",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L988-L995 | train |
gdelugre/origami | lib/origami/pdf.rb | Origami.PDF.build_xrefs | def build_xrefs(objects) #:nodoc:
lastno = 0
brange = 0
xrefs = [ XRef.new(0, XRef::FIRSTFREE, XRef::FREE) ]
xrefsection = XRef::Section.new
objects.sort_by {|object| object.reference}
.each do |object|
if (object.no - la... | ruby | def build_xrefs(objects) #:nodoc:
lastno = 0
brange = 0
xrefs = [ XRef.new(0, XRef::FIRSTFREE, XRef::FREE) ]
xrefsection = XRef::Section.new
objects.sort_by {|object| object.reference}
.each do |object|
if (object.no - la... | [
"def",
"build_xrefs",
"(",
"objects",
")",
"lastno",
"=",
"0",
"brange",
"=",
"0",
"xrefs",
"=",
"[",
"XRef",
".",
"new",
"(",
"0",
",",
"XRef",
"::",
"FIRSTFREE",
",",
"XRef",
"::",
"FREE",
")",
"]",
"xrefsection",
"=",
"XRef",
"::",
"Section",
".... | Build a xref section from a set of objects. | [
"Build",
"a",
"xref",
"section",
"from",
"a",
"set",
"of",
"objects",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/pdf.rb#L1060-L1085 | train |
gdelugre/origami | lib/origami/dictionary.rb | Origami.Dictionary.transform_values | def transform_values(&b)
self.class.new self.map { |k, v|
[ k.to_sym, b.call(v) ]
}.to_h
end | ruby | def transform_values(&b)
self.class.new self.map { |k, v|
[ k.to_sym, b.call(v) ]
}.to_h
end | [
"def",
"transform_values",
"(",
"&",
"b",
")",
"self",
".",
"class",
".",
"new",
"self",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"[",
"k",
".",
"to_sym",
",",
"b",
".",
"call",
"(",
"v",
")",
"]",
"}",
".",
"to_h",
"end"
] | Returns a new Dictionary object with values modified by given block. | [
"Returns",
"a",
"new",
"Dictionary",
"object",
"with",
"values",
"modified",
"by",
"given",
"block",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/dictionary.rb#L131-L135 | train |
gdelugre/origami | lib/origami/dictionary.rb | Origami.Dictionary.transform_values! | def transform_values!(&b)
self.each_pair do |k, v|
self[k] = b.call(unlink_object(v))
end
end | ruby | def transform_values!(&b)
self.each_pair do |k, v|
self[k] = b.call(unlink_object(v))
end
end | [
"def",
"transform_values!",
"(",
"&",
"b",
")",
"self",
".",
"each_pair",
"do",
"|",
"k",
",",
"v",
"|",
"self",
"[",
"k",
"]",
"=",
"b",
".",
"call",
"(",
"unlink_object",
"(",
"v",
")",
")",
"end",
"end"
] | Modifies the values of the Dictionary, leaving keys unchanged. | [
"Modifies",
"the",
"values",
"of",
"the",
"Dictionary",
"leaving",
"keys",
"unchanged",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/dictionary.rb#L140-L144 | train |
gdelugre/origami | lib/origami/xreftable.rb | Origami.PDF.remove_xrefs | def remove_xrefs
@revisions.reverse_each do |rev|
if rev.xrefstm?
delete_object(rev.xrefstm.reference)
end
if rev.trailer.XRefStm.is_a?(Integer)
xrefstm = get_object_by_offset(rev.trailer.XRefStm)
d... | ruby | def remove_xrefs
@revisions.reverse_each do |rev|
if rev.xrefstm?
delete_object(rev.xrefstm.reference)
end
if rev.trailer.XRefStm.is_a?(Integer)
xrefstm = get_object_by_offset(rev.trailer.XRefStm)
d... | [
"def",
"remove_xrefs",
"@revisions",
".",
"reverse_each",
"do",
"|",
"rev",
"|",
"if",
"rev",
".",
"xrefstm?",
"delete_object",
"(",
"rev",
".",
"xrefstm",
".",
"reference",
")",
"end",
"if",
"rev",
".",
"trailer",
".",
"XRefStm",
".",
"is_a?",
"(",
"Int... | Tries to strip any xrefs information off the document. | [
"Tries",
"to",
"strip",
"any",
"xrefs",
"information",
"off",
"the",
"document",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/xreftable.rb#L27-L41 | train |
gdelugre/origami | lib/origami/xreftable.rb | Origami.XRefStream.each_with_number | def each_with_number
return enum_for(__method__) unless block_given?
load! if @xrefs.nil?
ranges = object_ranges
xrefs = @xrefs.to_enum
ranges.each do |range|
range.each do |no|
begin
yield(xrefs.n... | ruby | def each_with_number
return enum_for(__method__) unless block_given?
load! if @xrefs.nil?
ranges = object_ranges
xrefs = @xrefs.to_enum
ranges.each do |range|
range.each do |no|
begin
yield(xrefs.n... | [
"def",
"each_with_number",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"load!",
"if",
"@xrefs",
".",
"nil?",
"ranges",
"=",
"object_ranges",
"xrefs",
"=",
"@xrefs",
".",
"to_enum",
"ranges",
".",
"each",
"do",
"|",
"range",
"|",
"... | Iterates over each XRef present in the stream, passing the XRef and its object number. | [
"Iterates",
"over",
"each",
"XRef",
"present",
"in",
"the",
"stream",
"passing",
"the",
"XRef",
"and",
"its",
"object",
"number",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/xreftable.rb#L447-L464 | train |
gdelugre/origami | lib/origami/xreftable.rb | Origami.XRefStream.find | def find(no)
load! if @xrefs.nil?
ranges = object_ranges
index = 0
ranges.each do |range|
return @xrefs[index + no - range.begin] if range.cover?(no)
index += range.size
end
nil
end | ruby | def find(no)
load! if @xrefs.nil?
ranges = object_ranges
index = 0
ranges.each do |range|
return @xrefs[index + no - range.begin] if range.cover?(no)
index += range.size
end
nil
end | [
"def",
"find",
"(",
"no",
")",
"load!",
"if",
"@xrefs",
".",
"nil?",
"ranges",
"=",
"object_ranges",
"index",
"=",
"0",
"ranges",
".",
"each",
"do",
"|",
"range",
"|",
"return",
"@xrefs",
"[",
"index",
"+",
"no",
"-",
"range",
".",
"begin",
"]",
"i... | Returns an XRef matching this object number. | [
"Returns",
"an",
"XRef",
"matching",
"this",
"object",
"number",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/xreftable.rb#L469-L482 | train |
gdelugre/origami | lib/origami/xreftable.rb | Origami.XRefStream.field_widths | def field_widths
widths = self.W
unless widths.is_a?(Array) and widths.length == 3 and widths.all? {|w| w.is_a?(Integer) and w >= 0 }
raise InvalidXRefStreamObjectError, "Invalid W field: #{widths}"
end
widths
end | ruby | def field_widths
widths = self.W
unless widths.is_a?(Array) and widths.length == 3 and widths.all? {|w| w.is_a?(Integer) and w >= 0 }
raise InvalidXRefStreamObjectError, "Invalid W field: #{widths}"
end
widths
end | [
"def",
"field_widths",
"widths",
"=",
"self",
".",
"W",
"unless",
"widths",
".",
"is_a?",
"(",
"Array",
")",
"and",
"widths",
".",
"length",
"==",
"3",
"and",
"widths",
".",
"all?",
"{",
"|",
"w",
"|",
"w",
".",
"is_a?",
"(",
"Integer",
")",
"and",... | Check and return the internal field widths. | [
"Check",
"and",
"return",
"the",
"internal",
"field",
"widths",
"."
] | ac1df803517601d486556fd40af5d422a6f4378e | https://github.com/gdelugre/origami/blob/ac1df803517601d486556fd40af5d422a6f4378e/lib/origami/xreftable.rb#L546-L554 | train |
igorkasyanchuk/rails_db | app/helpers/rails_db/application_helper.rb | RailsDb.ApplicationHelper.guess_name | def guess_name(sections)
if sections.size > 1
sections[-1] = 'rails_db'
variable = sections.join("_")
result = eval(variable)
end
rescue NameError
sections.delete_at(-2)
guess_name(sections)
end | ruby | def guess_name(sections)
if sections.size > 1
sections[-1] = 'rails_db'
variable = sections.join("_")
result = eval(variable)
end
rescue NameError
sections.delete_at(-2)
guess_name(sections)
end | [
"def",
"guess_name",
"(",
"sections",
")",
"if",
"sections",
".",
"size",
">",
"1",
"sections",
"[",
"-",
"1",
"]",
"=",
"'rails_db'",
"variable",
"=",
"sections",
".",
"join",
"(",
"\"_\"",
")",
"result",
"=",
"eval",
"(",
"variable",
")",
"end",
"r... | in case engine was added in namespace | [
"in",
"case",
"engine",
"was",
"added",
"in",
"namespace"
] | ecc664670242f032ca4387d9c1ba80c02591b923 | https://github.com/igorkasyanchuk/rails_db/blob/ecc664670242f032ca4387d9c1ba80c02591b923/app/helpers/rails_db/application_helper.rb#L11-L20 | train |
orta/cocoapods-keys | lib/preinstaller.rb | CocoaPodsKeys.PreInstaller.setup | def setup
require 'key_master'
require 'keyring_liberator'
require 'pod/command/keys/set'
require 'cocoapods/user_interface'
require 'dotenv'
ui = Pod::UserInterface
options = @user_options || {}
current_dir = Pathname.pwd
Dotenv.load
project = options.fetch... | ruby | def setup
require 'key_master'
require 'keyring_liberator'
require 'pod/command/keys/set'
require 'cocoapods/user_interface'
require 'dotenv'
ui = Pod::UserInterface
options = @user_options || {}
current_dir = Pathname.pwd
Dotenv.load
project = options.fetch... | [
"def",
"setup",
"require",
"'key_master'",
"require",
"'keyring_liberator'",
"require",
"'pod/command/keys/set'",
"require",
"'cocoapods/user_interface'",
"require",
"'dotenv'",
"ui",
"=",
"Pod",
"::",
"UserInterface",
"options",
"=",
"@user_options",
"||",
"{",
"}",
"c... | Returns `true` if all keys specified by the user are satisfied by either an existing keyring or environment
variables. | [
"Returns",
"true",
"if",
"all",
"keys",
"specified",
"by",
"the",
"user",
"are",
"satisfied",
"by",
"either",
"an",
"existing",
"keyring",
"or",
"environment",
"variables",
"."
] | bfdaa7be34457539a4cbcd74f907befd179fd4e7 | https://github.com/orta/cocoapods-keys/blob/bfdaa7be34457539a4cbcd74f907befd179fd4e7/lib/preinstaller.rb#L9-L70 | train |
justinfrench/formtastic | lib/formtastic/namespaced_class_finder.rb | Formtastic.NamespacedClassFinder.find_with_const_defined | def find_with_const_defined(class_name)
@namespaces.find do |namespace|
if namespace.const_defined?(class_name)
break namespace.const_get(class_name)
end
end
end | ruby | def find_with_const_defined(class_name)
@namespaces.find do |namespace|
if namespace.const_defined?(class_name)
break namespace.const_get(class_name)
end
end
end | [
"def",
"find_with_const_defined",
"(",
"class_name",
")",
"@namespaces",
".",
"find",
"do",
"|",
"namespace",
"|",
"if",
"namespace",
".",
"const_defined?",
"(",
"class_name",
")",
"break",
"namespace",
".",
"const_get",
"(",
"class_name",
")",
"end",
"end",
"... | Looks up the given class name in the configured namespaces in order,
returning the first one that has the class name constant defined. | [
"Looks",
"up",
"the",
"given",
"class",
"name",
"in",
"the",
"configured",
"namespaces",
"in",
"order",
"returning",
"the",
"first",
"one",
"that",
"has",
"the",
"class",
"name",
"constant",
"defined",
"."
] | f1ddec6efbcf49b88e212249829344c450784195 | https://github.com/justinfrench/formtastic/blob/f1ddec6efbcf49b88e212249829344c450784195/lib/formtastic/namespaced_class_finder.rb#L81-L87 | train |
ruby-grape/grape-swagger | lib/grape-swagger/endpoint.rb | Grape.Endpoint.swagger_object | def swagger_object(target_class, request, options)
object = {
info: info_object(options[:info].merge(version: options[:doc_version])),
swagger: '2.0',
produces: content_types_for(target_class),
authorizations: options[:authorizations],
securityDefinitions: options[:security... | ruby | def swagger_object(target_class, request, options)
object = {
info: info_object(options[:info].merge(version: options[:doc_version])),
swagger: '2.0',
produces: content_types_for(target_class),
authorizations: options[:authorizations],
securityDefinitions: options[:security... | [
"def",
"swagger_object",
"(",
"target_class",
",",
"request",
",",
"options",
")",
"object",
"=",
"{",
"info",
":",
"info_object",
"(",
"options",
"[",
":info",
"]",
".",
"merge",
"(",
"version",
":",
"options",
"[",
":doc_version",
"]",
")",
")",
",",
... | swagger spec2.0 related parts
required keys for SwaggerObject | [
"swagger",
"spec2",
".",
"0",
"related",
"parts"
] | 542511d9ef08f25b587914a4976009fbc95f7dc0 | https://github.com/ruby-grape/grape-swagger/blob/542511d9ef08f25b587914a4976009fbc95f7dc0/lib/grape-swagger/endpoint.rb#L26-L41 | train |
ruby-grape/grape-swagger | lib/grape-swagger/endpoint.rb | Grape.Endpoint.info_object | def info_object(infos)
result = {
title: infos[:title] || 'API title',
description: infos[:description],
termsOfService: infos[:terms_of_service_url],
contact: contact_object(infos),
license: license_object(infos),
version: infos[:version]
}
GrapeSwagge... | ruby | def info_object(infos)
result = {
title: infos[:title] || 'API title',
description: infos[:description],
termsOfService: infos[:terms_of_service_url],
contact: contact_object(infos),
license: license_object(infos),
version: infos[:version]
}
GrapeSwagge... | [
"def",
"info_object",
"(",
"infos",
")",
"result",
"=",
"{",
"title",
":",
"infos",
"[",
":title",
"]",
"||",
"'API title'",
",",
"description",
":",
"infos",
"[",
":description",
"]",
",",
"termsOfService",
":",
"infos",
"[",
":terms_of_service_url",
"]",
... | building info object | [
"building",
"info",
"object"
] | 542511d9ef08f25b587914a4976009fbc95f7dc0 | https://github.com/ruby-grape/grape-swagger/blob/542511d9ef08f25b587914a4976009fbc95f7dc0/lib/grape-swagger/endpoint.rb#L44-L57 | train |
ruby-grape/grape-swagger | lib/grape-swagger/endpoint.rb | Grape.Endpoint.license_object | def license_object(infos)
{
name: infos.delete(:license),
url: infos.delete(:license_url)
}.delete_if { |_, value| value.blank? }
end | ruby | def license_object(infos)
{
name: infos.delete(:license),
url: infos.delete(:license_url)
}.delete_if { |_, value| value.blank? }
end | [
"def",
"license_object",
"(",
"infos",
")",
"{",
"name",
":",
"infos",
".",
"delete",
"(",
":license",
")",
",",
"url",
":",
"infos",
".",
"delete",
"(",
":license_url",
")",
"}",
".",
"delete_if",
"{",
"|",
"_",
",",
"value",
"|",
"value",
".",
"b... | sub-objects of info object
license | [
"sub",
"-",
"objects",
"of",
"info",
"object",
"license"
] | 542511d9ef08f25b587914a4976009fbc95f7dc0 | https://github.com/ruby-grape/grape-swagger/blob/542511d9ef08f25b587914a4976009fbc95f7dc0/lib/grape-swagger/endpoint.rb#L61-L66 | train |
ruby-grape/grape-swagger | lib/grape-swagger/endpoint.rb | Grape.Endpoint.path_and_definition_objects | def path_and_definition_objects(namespace_routes, options)
@paths = {}
@definitions = {}
namespace_routes.each_key do |key|
routes = namespace_routes[key]
path_item(routes, options)
end
add_definitions_from options[:models]
[@paths, @definitions]
end | ruby | def path_and_definition_objects(namespace_routes, options)
@paths = {}
@definitions = {}
namespace_routes.each_key do |key|
routes = namespace_routes[key]
path_item(routes, options)
end
add_definitions_from options[:models]
[@paths, @definitions]
end | [
"def",
"path_and_definition_objects",
"(",
"namespace_routes",
",",
"options",
")",
"@paths",
"=",
"{",
"}",
"@definitions",
"=",
"{",
"}",
"namespace_routes",
".",
"each_key",
"do",
"|",
"key",
"|",
"routes",
"=",
"namespace_routes",
"[",
"key",
"]",
"path_it... | building path and definitions objects | [
"building",
"path",
"and",
"definitions",
"objects"
] | 542511d9ef08f25b587914a4976009fbc95f7dc0 | https://github.com/ruby-grape/grape-swagger/blob/542511d9ef08f25b587914a4976009fbc95f7dc0/lib/grape-swagger/endpoint.rb#L78-L88 | train |
piotrmurach/tty-tree | lib/tty/tree.rb | TTY.Tree.node | def node(name, type = Node, &block)
parent = @nodes_stack.empty? ? Node::ROOT : @nodes_stack.last
level = [0, @nodes_stack.size - 1].max
prefix = ':pipe' * level
if parent.class == LeafNode
prefix = ':space' * level
end
node = type.new(name, parent.full_path, prefix, @nodes_s... | ruby | def node(name, type = Node, &block)
parent = @nodes_stack.empty? ? Node::ROOT : @nodes_stack.last
level = [0, @nodes_stack.size - 1].max
prefix = ':pipe' * level
if parent.class == LeafNode
prefix = ':space' * level
end
node = type.new(name, parent.full_path, prefix, @nodes_s... | [
"def",
"node",
"(",
"name",
",",
"type",
"=",
"Node",
",",
"&",
"block",
")",
"parent",
"=",
"@nodes_stack",
".",
"empty?",
"?",
"Node",
"::",
"ROOT",
":",
"@nodes_stack",
".",
"last",
"level",
"=",
"[",
"0",
",",
"@nodes_stack",
".",
"size",
"-",
... | Create a Tree
@param [String,Dir,Hash] data
@api public
Add node to this tree.
@param [Symbol,String] name
the name for the node
@param [Node, LeafNode] type
the type of node to add
@example
TTY::Tree.new do
node '...' do
node '...'
end
end
@api public | [
"Create",
"a",
"Tree"
] | 8e7e3bfc84a3bf3a2d325eae2fb5bfca2f7a5a8c | https://github.com/piotrmurach/tty-tree/blob/8e7e3bfc84a3bf3a2d325eae2fb5bfca2f7a5a8c/lib/tty/tree.rb#L58-L77 | train |
yosiat/panko_serializer | lib/panko/serialization_descriptor.rb | Panko.SerializationDescriptor.apply_filters | def apply_filters(options)
return unless options.key?(:only) || options.key?(:except)
attributes_only_filters, associations_only_filters = resolve_filters(options, :only)
attributes_except_filters, associations_except_filters = resolve_filters(options, :except)
self.attributes = apply_attribut... | ruby | def apply_filters(options)
return unless options.key?(:only) || options.key?(:except)
attributes_only_filters, associations_only_filters = resolve_filters(options, :only)
attributes_except_filters, associations_except_filters = resolve_filters(options, :except)
self.attributes = apply_attribut... | [
"def",
"apply_filters",
"(",
"options",
")",
"return",
"unless",
"options",
".",
"key?",
"(",
":only",
")",
"||",
"options",
".",
"key?",
"(",
":except",
")",
"attributes_only_filters",
",",
"associations_only_filters",
"=",
"resolve_filters",
"(",
"options",
",... | Applies attributes and association filters | [
"Applies",
"attributes",
"and",
"association",
"filters"
] | bbd23293b33cd8c25efc7609382139716b1b9ec7 | https://github.com/yosiat/panko_serializer/blob/bbd23293b33cd8c25efc7609382139716b1b9ec7/lib/panko/serialization_descriptor.rb#L56-L89 | train |
FooBarWidget/default_value_for | lib/default_value_for.rb | DefaultValueFor.ClassMethods.default_value_for | def default_value_for(attribute, options = {}, &block)
value = options
allows_nil = true
if options.is_a?(Hash)
opts = options.stringify_keys
value = opts.fetch('value', options)
allows_nil = opts.fetch('allows_nil', true)
end
if !method_defined?(:... | ruby | def default_value_for(attribute, options = {}, &block)
value = options
allows_nil = true
if options.is_a?(Hash)
opts = options.stringify_keys
value = opts.fetch('value', options)
allows_nil = opts.fetch('allows_nil', true)
end
if !method_defined?(:... | [
"def",
"default_value_for",
"(",
"attribute",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"value",
"=",
"options",
"allows_nil",
"=",
"true",
"if",
"options",
".",
"is_a?",
"(",
"Hash",
")",
"opts",
"=",
"options",
".",
"stringify_keys",
"valu... | Declares a default value for the given attribute.
Sets the default value to the given options parameter unless the given options equal { :value => ... }
The <tt>options</tt> can be used to specify the following things:
* <tt>value</tt> - Sets the default value.
* <tt>allows_nil (default: true)</tt> - Sets explici... | [
"Declares",
"a",
"default",
"value",
"for",
"the",
"given",
"attribute",
"."
] | d5fe8f13aed6e63df5e5128c7625ccf46f66eea8 | https://github.com/FooBarWidget/default_value_for/blob/d5fe8f13aed6e63df5e5128c7625ccf46f66eea8/lib/default_value_for.rb#L58-L94 | train |
zendesk/zendesk_apps_support | lib/zendesk_apps_support/package.rb | ZendeskAppsSupport.Package.compile | def compile(options)
begin
app_id = options.fetch(:app_id)
asset_url_prefix = options.fetch(:assets_dir)
name = options.fetch(:app_name)
rescue KeyError => e
raise ArgumentError, e.message
end
locale = options.fetch(:locale, 'en')
source = manifest.iframe_... | ruby | def compile(options)
begin
app_id = options.fetch(:app_id)
asset_url_prefix = options.fetch(:assets_dir)
name = options.fetch(:app_name)
rescue KeyError => e
raise ArgumentError, e.message
end
locale = options.fetch(:locale, 'en')
source = manifest.iframe_... | [
"def",
"compile",
"(",
"options",
")",
"begin",
"app_id",
"=",
"options",
".",
"fetch",
"(",
":app_id",
")",
"asset_url_prefix",
"=",
"options",
".",
"fetch",
"(",
":assets_dir",
")",
"name",
"=",
"options",
".",
"fetch",
"(",
":app_name",
")",
"rescue",
... | this is not really compile_js, it compiles the whole app including scss for v1 apps | [
"this",
"is",
"not",
"really",
"compile_js",
"it",
"compiles",
"the",
"whole",
"app",
"including",
"scss",
"for",
"v1",
"apps"
] | d744af677c8d05706a63a25c2aee0203d2a3f102 | https://github.com/zendesk/zendesk_apps_support/blob/d744af677c8d05706a63a25c2aee0203d2a3f102/lib/zendesk_apps_support/package.rb#L108-L140 | train |
cldwalker/hirb | lib/hirb/helpers/table.rb | Hirb.Helpers::Table.default_field_lengths | def default_field_lengths
field_lengths = @headers ? @headers.inject({}) {|h,(k,v)| h[k] = String.size(v); h} :
@fields.inject({}) {|h,e| h[e] = 1; h }
@rows.each do |row|
@fields.each do |field|
len = String.size(row[field])
field_lengths[field] = len if len > field_lengths[field].t... | ruby | def default_field_lengths
field_lengths = @headers ? @headers.inject({}) {|h,(k,v)| h[k] = String.size(v); h} :
@fields.inject({}) {|h,e| h[e] = 1; h }
@rows.each do |row|
@fields.each do |field|
len = String.size(row[field])
field_lengths[field] = len if len > field_lengths[field].t... | [
"def",
"default_field_lengths",
"field_lengths",
"=",
"@headers",
"?",
"@headers",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"h",
",",
"(",
"k",
",",
"v",
")",
"|",
"h",
"[",
"k",
"]",
"=",
"String",
".",
"size",
"(",
"v",
")",
";",
"h",
"}"... | find max length for each field; start with the headers | [
"find",
"max",
"length",
"for",
"each",
"field",
";",
"start",
"with",
"the",
"headers"
] | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/helpers/table.rb#L322-L332 | train |
cldwalker/hirb | lib/hirb/helpers/table.rb | Hirb.Helpers::Table.array_to_indices_hash | def array_to_indices_hash(array)
array.inject({}) {|hash,e| hash[hash.size] = e; hash }
end | ruby | def array_to_indices_hash(array)
array.inject({}) {|hash,e| hash[hash.size] = e; hash }
end | [
"def",
"array_to_indices_hash",
"(",
"array",
")",
"array",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"hash",
",",
"e",
"|",
"hash",
"[",
"hash",
".",
"size",
"]",
"=",
"e",
";",
"hash",
"}",
"end"
] | Converts an array to a hash mapping a numerical index to its array value. | [
"Converts",
"an",
"array",
"to",
"a",
"hash",
"mapping",
"a",
"numerical",
"index",
"to",
"its",
"array",
"value",
"."
] | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/helpers/table.rb#L371-L373 | train |
cldwalker/hirb | lib/hirb/formatter.rb | Hirb.Formatter.format_output | def format_output(output, options={}, &block)
output_class = determine_output_class(output)
options = parse_console_options(options) if options.delete(:console)
options = Util.recursive_hash_merge(klass_config(output_class), options)
_format_output(output, options, &block)
end | ruby | def format_output(output, options={}, &block)
output_class = determine_output_class(output)
options = parse_console_options(options) if options.delete(:console)
options = Util.recursive_hash_merge(klass_config(output_class), options)
_format_output(output, options, &block)
end | [
"def",
"format_output",
"(",
"output",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"output_class",
"=",
"determine_output_class",
"(",
"output",
")",
"options",
"=",
"parse_console_options",
"(",
"options",
")",
"if",
"options",
".",
"delete",
"("... | This method looks for an output object's view in Formatter.config and then Formatter.dynamic_config.
If a view is found, a stringified view is returned based on the object. If no view is found, nil is returned. The options this
class takes are a view hash as described in Formatter.config. These options will be merged... | [
"This",
"method",
"looks",
"for",
"an",
"output",
"object",
"s",
"view",
"in",
"Formatter",
".",
"config",
"and",
"then",
"Formatter",
".",
"dynamic_config",
".",
"If",
"a",
"view",
"is",
"found",
"a",
"stringified",
"view",
"is",
"returned",
"based",
"on"... | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/formatter.rb#L52-L57 | train |
cldwalker/hirb | lib/hirb/dynamic_view.rb | Hirb.DynamicView.dynamic_options | def dynamic_options(obj)
view_methods.each do |meth|
if obj.class.ancestors.map {|e| e.to_s }.include?(method_to_class(meth))
begin
return send(meth, obj)
rescue
raise "View failed to generate for '#{method_to_class(meth)}' "+
"while in '#{meth}' w... | ruby | def dynamic_options(obj)
view_methods.each do |meth|
if obj.class.ancestors.map {|e| e.to_s }.include?(method_to_class(meth))
begin
return send(meth, obj)
rescue
raise "View failed to generate for '#{method_to_class(meth)}' "+
"while in '#{meth}' w... | [
"def",
"dynamic_options",
"(",
"obj",
")",
"view_methods",
".",
"each",
"do",
"|",
"meth",
"|",
"if",
"obj",
".",
"class",
".",
"ancestors",
".",
"map",
"{",
"|",
"e",
"|",
"e",
".",
"to_s",
"}",
".",
"include?",
"(",
"method_to_class",
"(",
"meth",
... | Returns a hash of options based on dynamic views defined for the object's ancestry. If no config is found returns nil. | [
"Returns",
"a",
"hash",
"of",
"options",
"based",
"on",
"dynamic",
"views",
"defined",
"for",
"the",
"object",
"s",
"ancestry",
".",
"If",
"no",
"config",
"is",
"found",
"returns",
"nil",
"."
] | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/dynamic_view.rb#L69-L81 | train |
cldwalker/hirb | lib/hirb/pager.rb | Hirb.Pager.activated_by? | def activated_by?(string_to_page, inspect_mode=false)
inspect_mode ? (String.size(string_to_page) > @height * @width) : (string_to_page.count("\n") > @height)
end | ruby | def activated_by?(string_to_page, inspect_mode=false)
inspect_mode ? (String.size(string_to_page) > @height * @width) : (string_to_page.count("\n") > @height)
end | [
"def",
"activated_by?",
"(",
"string_to_page",
",",
"inspect_mode",
"=",
"false",
")",
"inspect_mode",
"?",
"(",
"String",
".",
"size",
"(",
"string_to_page",
")",
">",
"@height",
"*",
"@width",
")",
":",
"(",
"string_to_page",
".",
"count",
"(",
"\"\\n\"",
... | Determines if string should be paged based on configured width and height. | [
"Determines",
"if",
"string",
"should",
"be",
"paged",
"based",
"on",
"configured",
"width",
"and",
"height",
"."
] | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/pager.rb#L88-L90 | train |
cldwalker/hirb | lib/hirb/util.rb | Hirb.Util.recursive_hash_merge | def recursive_hash_merge(hash1, hash2)
hash1.merge(hash2) {|k,o,n| (o.is_a?(Hash)) ? recursive_hash_merge(o,n) : n}
end | ruby | def recursive_hash_merge(hash1, hash2)
hash1.merge(hash2) {|k,o,n| (o.is_a?(Hash)) ? recursive_hash_merge(o,n) : n}
end | [
"def",
"recursive_hash_merge",
"(",
"hash1",
",",
"hash2",
")",
"hash1",
".",
"merge",
"(",
"hash2",
")",
"{",
"|",
"k",
",",
"o",
",",
"n",
"|",
"(",
"o",
".",
"is_a?",
"(",
"Hash",
")",
")",
"?",
"recursive_hash_merge",
"(",
"o",
",",
"n",
")",... | Recursively merge hash1 with hash2. | [
"Recursively",
"merge",
"hash1",
"with",
"hash2",
"."
] | 264f72c7c0f0966001e802414a5b0641036c7860 | https://github.com/cldwalker/hirb/blob/264f72c7c0f0966001e802414a5b0641036c7860/lib/hirb/util.rb#L21-L23 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.