_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3 values | text stringlengths 66 10.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q18600 | Origin.Selectable.not | train | def not(*criterion)
if criterion.empty?
tap { |query| query.negating = true }
else
__override__(criterion.first, "$not")
end
end | ruby | {
"resource": ""
} |
q18601 | Origin.Selectable.text_search | train | def text_search(terms, opts = nil)
clone.tap do |query|
if terms
criterion = { :$text => { :$search => terms } }
criterion[:$text].merge!(opts) if opts
query.selector = criterion
end
end
end | ruby | {
"resource": ""
} |
q18602 | Origin.Selectable.typed_override | train | def typed_override(criterion, operator)
if criterion
criterion.update_values do |value|
yield(value)
end
end
__override__(criterion, operator)
end | ruby | {
"resource": ""
} |
q18603 | Origin.Selectable.selection | train | def selection(criterion = nil)
clone.tap do |query|
if criterion
criterion.each_pair do |field, value|
yield(query.selector, field.is_a?(Key) ? field : field.to_s, value)
end
end
query.reset_strategies!
end
end | ruby | {
"resource": ""
} |
q18604 | Origin.Queryable.initialize_copy | train | def initialize_copy(other)
@options = other.options.__deep_copy__
@selector = other.selector.__deep_copy__
@pipeline = other.pipeline.__deep_copy__
end | ruby | {
"resource": ""
} |
q18605 | Origin.Pipeline.evolve | train | def evolve(entry)
aggregate = Selector.new(aliases)
entry.each_pair do |field, value|
aggregate.merge!(field.to_s => value)
end
aggregate
end | ruby | {
"resource": ""
} |
q18606 | Origin.Forwardable.select_with | train | def select_with(receiver)
(Selectable.forwardables + Optional.forwardables).each do |name|
__forward__(name, receiver)
end
end | ruby | {
"resource": ""
} |
q18607 | Origin.Aggregable.aggregation | train | def aggregation(operation)
return self unless operation
clone.tap do |query|
unless aggregating?
query.pipeline.concat(query.selector.to_pipeline)
query.pipeline.concat(query.options.to_pipeline)
query.aggregating = true
end
yield(query.pipeline)
end
end | ruby | {
"resource": ""
} |
q18608 | Origin.Smash.storage_pair | train | def storage_pair(key)
field = key.to_s
name = aliases[field] || field
[ name, serializers[name] ]
end | ruby | {
"resource": ""
} |
q18609 | Origin.Mergeable.with_strategy | train | def with_strategy(strategy, criterion, operator)
selection(criterion) do |selector, field, value|
selector.store(
field,
selector[field].send(strategy, prepare(field, operator, value))
)
end
end | ruby | {
"resource": ""
} |
q18610 | Origin.Mergeable.prepare | train | def prepare(field, operator, value)
unless operator =~ /exists|type|size/
value = value.__expand_complex__
serializer = serializers[field]
value = serializer ? serializer.evolve(value) : value
end
selection = { operator => value }
negating? ? { "$not" => selection } : selection
end | ruby | {
"resource": ""
} |
q18611 | Origin.Selector.merge! | train | def merge!(other)
other.each_pair do |key, value|
if value.is_a?(Hash) && self[key.to_s].is_a?(Hash)
value = self[key.to_s].merge(value) do |_key, old_val, new_val|
if in?(_key)
new_val & old_val
elsif nin?(_key)
(old_val + new_val).uniq
else
new_val
end
end
end
if multi_selection?(key)
value = (self[key.to_s] || []).concat(value)
end
store(key, value)
end
end | ruby | {
"resource": ""
} |
q18612 | Origin.Selector.store | train | def store(key, value)
name, serializer = storage_pair(key)
if multi_selection?(name)
super(name, evolve_multi(value))
else
super(normalized_key(name, serializer), evolve(serializer, value))
end
end | ruby | {
"resource": ""
} |
q18613 | Origin.Selector.evolve | train | def evolve(serializer, value)
case value
when Hash
evolve_hash(serializer, value)
when Array
evolve_array(serializer, value)
else
(serializer || value.class).evolve(value)
end
end | ruby | {
"resource": ""
} |
q18614 | Origin.Options.to_pipeline | train | def to_pipeline
pipeline = []
pipeline.push({ "$skip" => skip }) if skip
pipeline.push({ "$limit" => limit }) if limit
pipeline.push({ "$sort" => sort }) if sort
pipeline
end | ruby | {
"resource": ""
} |
q18615 | Origin.Macroable.key | train | def key(name, strategy, operator, additional = nil, &block)
::Symbol.add_key(name, strategy, operator, additional, &block)
end | ruby | {
"resource": ""
} |
q18616 | Origin.Optional.order_by | train | def order_by(*spec)
option(spec) do |options, query|
spec.compact.each do |criterion|
criterion.__sort_option__.each_pair do |field, direction|
add_sort_option(options, field, direction)
end
query.pipeline.push("$sort" => options[:sort]) if aggregating?
end
end
end | ruby | {
"resource": ""
} |
q18617 | Origin.Optional.skip | train | def skip(value = nil)
option(value) do |options, query|
val = value.to_i
options.store(:skip, val)
query.pipeline.push("$skip" => val) if aggregating?
end
end | ruby | {
"resource": ""
} |
q18618 | Origin.Optional.slice | train | def slice(criterion = nil)
option(criterion) do |options|
options.__union__(
fields: criterion.inject({}) do |option, (field, val)|
option.tap { |opt| opt.store(field, { "$slice" => val }) }
end
)
end
end | ruby | {
"resource": ""
} |
q18619 | Origin.Optional.without | train | def without(*args)
args = args.flatten
option(*args) do |options|
options.store(
:fields, args.inject(options[:fields] || {}){ |sub, field| sub.tap { sub[field] = 0 }}
)
end
end | ruby | {
"resource": ""
} |
q18620 | Origin.Optional.add_sort_option | train | def add_sort_option(options, field, direction)
if driver == :mongo1x
sorting = (options[:sort] || []).dup
sorting.push([ field, direction ])
options.store(:sort, sorting)
else
sorting = (options[:sort] || {}).dup
sorting[field] = direction
options.store(:sort, sorting)
end
end | ruby | {
"resource": ""
} |
q18621 | Origin.Optional.option | train | def option(*args)
clone.tap do |query|
unless args.compact.empty?
yield(query.options, query)
end
end
end | ruby | {
"resource": ""
} |
q18622 | Origin.Optional.sort_with_list | train | def sort_with_list(*fields, direction)
option(fields) do |options, query|
fields.flatten.compact.each do |field|
add_sort_option(options, field, direction)
end
query.pipeline.push("$sort" => options[:sort]) if aggregating?
end
end | ruby | {
"resource": ""
} |
q18623 | Guillotine.Adapter.parse_url | train | def parse_url(url, options)
url.gsub!(/\s/, '')
url.gsub!(/\?.*/, '') if options.strip_query?
url.gsub!(/\#.*/, '') if options.strip_anchor?
Addressable::URI.parse(url)
end | ruby | {
"resource": ""
} |
q18624 | Guillotine.RiakAdapter.add | train | def add(url, code = nil, options = nil)
sha = url_key url
url_obj = @url_bucket.get_or_new sha, :r => 1
if url_obj.raw_data
fix_url_object(url_obj)
code = url_obj.data
end
code = get_code(url, code, options)
code_obj = @code_bucket.get_or_new code
code_obj.content_type = url_obj.content_type = PLAIN
if existing_url = code_obj.data # key exists
raise DuplicateCodeError.new(existing_url, url, code) if url_key(existing_url) != sha
end
if !url_obj.data # unsaved
url_obj.data = code
url_obj.store
end
code_obj.data = url
code_obj.store
code
end | ruby | {
"resource": ""
} |
q18625 | Guillotine.RiakAdapter.url_object | train | def url_object(code)
@code_bucket.get(code, :r => 1)
rescue Riak::FailedRequest => err
raise unless err.not_found?
end | ruby | {
"resource": ""
} |
q18626 | Guillotine.RiakAdapter.code_object | train | def code_object(url)
sha = url_key url
if o = @url_bucket.get(sha, :r => 1)
fix_url_object(o)
end
rescue Riak::FailedRequest => err
raise unless err.not_found?
end | ruby | {
"resource": ""
} |
q18627 | Xcode.ConfigurationList.create_config | train | def create_config(name)
name = ConfigurationList.symbol_config_name_to_config_name[name] if ConfigurationList.symbol_config_name_to_config_name[name]
# @todo a configuration has additional fields that are ususally set with
# some target information for the title.
new_config = @registry.add_object(Configuration.default_properties(name))
@properties['buildConfigurations'] << new_config.identifier
yield new_config if block_given?
new_config.save!
end | ruby | {
"resource": ""
} |
q18628 | Xcode.Resource.define_property | train | def define_property name, value
# Save the properties within the resource within a custom hash. This
# provides access to them without the indirection that we are about to
# set up.
@properties[name] = value
# Generate a getter method for this property based on the given name.
self.class.send :define_method, name.underscore do
# Retrieve the value that is current stored for this name.
raw_value = @properties[name]
# If the value is an array then we want to examine each element within
# the array to see if any of them are identifiers that we should replace
# finally returning all of the items as their resource representations
# or as their raw values.
#
# If the value is not an array then we want to examine that item and
# return the resource representation or the raw value.
if raw_value.is_a?(Array)
Array(raw_value).map do |sub_value|
if Registry.is_identifier? sub_value
Resource.new sub_value, @registry
else
sub_value
end
end
else
if Registry.is_identifier? raw_value
Resource.new raw_value, @registry
else
raw_value
end
end
end
# Generate a setter method for this property based on the given name.
self.class.send :define_method, "#{name.underscore}=" do |new_value|
@properties[name] = new_value
end
end | ruby | {
"resource": ""
} |
q18629 | Xcode.Project.file | train | def file(name_with_path)
path, name = File.split(name_with_path)
group(path).file(name).first
end | ruby | {
"resource": ""
} |
q18630 | Xcode.Project.products_group | train | def products_group
current_group = groups.group('Products').first
current_group.instance_eval(&block) if block_given? and current_group
current_group
end | ruby | {
"resource": ""
} |
q18631 | Xcode.Project.frameworks_group | train | def frameworks_group
current_group = groups.group('Frameworks').first
current_group.instance_eval(&block) if block_given? and current_group
current_group
end | ruby | {
"resource": ""
} |
q18632 | Xcode.Project.save | train | def save(path)
Dir.mkdir(path) unless File.exists?(path)
project_filepath = "#{path}/project.pbxproj"
# @toodo Save the workspace when the project is saved
# FileUtils.cp_r "#{path}/project.xcworkspace", "#{path}/project.xcworkspace"
Xcode::PLUTILProjectParser.save "#{path}/project.pbxproj", to_xcplist
end | ruby | {
"resource": ""
} |
q18633 | Xcode.Project.scheme | train | def scheme(name)
scheme = schemes.select {|t| t.name == name.to_s}.first
raise "No such scheme #{name}, available schemes are #{schemes.map {|t| t.name}.join(', ')}" if scheme.nil?
yield scheme if block_given?
scheme
end | ruby | {
"resource": ""
} |
q18634 | Xcode.Project.target | train | def target(name)
target = targets.select {|t| t.name == name.to_s}.first
raise "No such target #{name}, available targets are #{targets.map {|t| t.name}.join(', ')}" if target.nil?
yield target if block_given?
target
end | ruby | {
"resource": ""
} |
q18635 | Xcode.Project.create_target | train | def create_target(name,type=:native)
target = @registry.add_object Target.send(type)
@project.properties['targets'] << target.identifier
target.name = name
build_configuration_list = @registry.add_object(ConfigurationList.configuration_list)
target.build_configuration_list = build_configuration_list.identifier
target.project = self
yield target if block_given?
target.save!
end | ruby | {
"resource": ""
} |
q18636 | Xcode.Project.remove_target | train | def remove_target(name)
found_target = targets.find {|target| target.name == name }
if found_target
@project.properties['targets'].delete found_target.identifier
@registry.remove_object found_target.identifier
end
found_target
end | ruby | {
"resource": ""
} |
q18637 | Xcode.Project.describe | train | def describe
puts "Project #{name} contains"
targets.each do |t|
puts " + target:#{t.name}"
t.configs.each do |c|
puts " + config:#{c.name}"
end
end
schemes.each do |s|
puts " + scheme #{s.name}"
puts " + targets: #{s.build_targets.map{|t| t.name}}"
puts " + config: #{s.build_config}"
end
end | ruby | {
"resource": ""
} |
q18638 | Xcode.Project.parse_pbxproj | train | def parse_pbxproj
registry = Xcode::PLUTILProjectParser.parse "#{@path}/project.pbxproj"
class << registry
include Xcode::Registry
end
registry
end | ruby | {
"resource": ""
} |
q18639 | Xcode.PLUTILProjectParser.parse | train | def parse(path)
registry = Plist.parse_xml open_project_file(path)
raise "Failed to correctly parse the project file #{path}" unless registry
registry
end | ruby | {
"resource": ""
} |
q18640 | Xcode.TerminalOutput.print_input | train | def print_input message, level=:debug
return if LEVELS.index(level) > LEVELS.index(@@log_level)
puts format_lhs("", "", "<") + message, :default
end | ruby | {
"resource": ""
} |
q18641 | Xcode.TerminalOutput.print_output | train | def print_output message, level=:debug
return if LEVELS.index(level) > LEVELS.index(@@log_level)
puts format_lhs("", "", ">") + message, :default
end | ruby | {
"resource": ""
} |
q18642 | Xcode.Target.create_build_phases | train | def create_build_phases *base_phase_names
base_phase_names.compact.flatten.map do |phase_name|
build_phase = create_build_phase phase_name do |build_phase|
yield build_phase if block_given?
end
build_phase.save!
end
end | ruby | {
"resource": ""
} |
q18643 | Xcode.Target.create_product_reference | train | def create_product_reference(name)
product = project.products_group.create_product_reference(name)
product_reference = product.identifier
product
end | ruby | {
"resource": ""
} |
q18644 | Xcode.Keychain.in_search_path | train | def in_search_path(&block)
keychains = Keychains.search_path
begin
Keychains.search_path = [self] + keychains
yield
ensure
Keychains.search_path = keychains
# print_task 'keychain', "Restored search path"
end
end | ruby | {
"resource": ""
} |
q18645 | Xcode.Keychain.import | train | def import(cert, password)
cmd = Xcode::Shell::Command.new "security"
cmd << "import '#{cert}'"
cmd << "-k \"#{@path}\""
cmd << "-P #{password}"
cmd << "-T /usr/bin/codesign"
cmd.execute
end | ruby | {
"resource": ""
} |
q18646 | Xcode.Keychain.identities | train | def identities
names = []
cmd = Xcode::Shell::Command.new "security"
cmd << "find-certificate"
cmd << "-a"
cmd << "\"#{@path}\""
cmd.show_output = false
cmd.execute.join("").scan /\s+"labl"<blob>="([^"]+)"/ do |m|
names << m[0]
end
names
end | ruby | {
"resource": ""
} |
q18647 | Xcode.Keychain.lock | train | def lock
cmd = Xcode::Shell::Command.new "security"
cmd << "lock-keychain"
cmd << "\"#{@path}\""
cmd.execute
end | ruby | {
"resource": ""
} |
q18648 | Xcode.Keychain.unlock | train | def unlock(password)
cmd = Xcode::Shell::Command.new "security"
cmd << "unlock-keychain"
cmd << "-p #{password}"
cmd << "\"#{@path}\""
cmd.execute
end | ruby | {
"resource": ""
} |
q18649 | Xcode.ConfigurationOwner.config | train | def config(name)
config = configs.select {|config| config.name == name.to_s }.first
raise "No such config #{name}, available configs are #{configs.map {|c| c.name}.join(', ')}" if config.nil?
yield config if block_given?
config
end | ruby | {
"resource": ""
} |
q18650 | Xcode.ConfigurationOwner.create_configuration | train | def create_configuration(name)
# To create a configuration, we need to create or retrieve the configuration list
created_config = build_configuration_list.create_config(name) do |config|
yield config if block_given?
end
created_config
end | ruby | {
"resource": ""
} |
q18651 | Xcode.ConfigurationOwner.create_configurations | train | def create_configurations(*configuration_names)
configuration_names.compact.flatten.map do |config_name|
created_config = create_configuration config_name do |config|
yield config if block_given?
end
created_config.save!
end
end | ruby | {
"resource": ""
} |
q18652 | Xcode.BuildPhase.file | train | def file(name)
files.find {|file| file.file_ref.name == name or file.file_ref.path == name }
end | ruby | {
"resource": ""
} |
q18653 | Xcode.BuildPhase.build_file | train | def build_file(name)
build_files.find {|file| file.name == name or file.path == name }
end | ruby | {
"resource": ""
} |
q18654 | Xcode.BuildPhase.add_build_file | train | def add_build_file(file,settings = {})
find_file_by = file.path || file.name
unless build_file(find_file_by)
new_build_file = @registry.add_object BuildFile.buildfile(file.identifier,settings)
@properties['files'] << new_build_file.identifier
end
end | ruby | {
"resource": ""
} |
q18655 | Xcode.Registry.add_object | train | def add_object(object_properties)
new_identifier = SimpleIdentifierGenerator.generate :existing_keys => objects.keys
objects[new_identifier] = object_properties
Resource.new new_identifier, self
end | ruby | {
"resource": ""
} |
q18656 | Xcode.Workspace.project | train | def project(name)
project = @projects.select {|c| c.name == name.to_s}.first
raise "No such project #{name} in #{self}, available projects are #{@projects.map {|c| c.name}.join(', ')}" if project.nil?
yield project if block_given?
project
end | ruby | {
"resource": ""
} |
q18657 | Xcode.TargetDependency.create_dependency_on | train | def create_dependency_on(target)
@properties['target'] = target.identifier
container_item_proxy = ContainerItemProxy.default target.project.project.identifier, target.identifier, target.name
container_item_proxy = @registry.add_object(container_item_proxy)
@properties['targetProxy'] = container_item_proxy.identifier
save!
end | ruby | {
"resource": ""
} |
q18658 | Xcode.Configuration.info_plist | train | def info_plist
info = Xcode::InfoPlist.new(self, info_plist_location)
yield info if block_given?
info.save
info
end | ruby | {
"resource": ""
} |
q18659 | Xcode.Configuration.get | train | def get(name)
if respond_to?(name)
send(name)
elsif Configuration.setting_name_to_property(name)
send Configuration.setting_name_to_property(name)
else
build_settings[name]
end
end | ruby | {
"resource": ""
} |
q18660 | Xcode.Configuration.set | train | def set(name, value)
if respond_to?(name)
send("#{name}=",value)
elsif Configuration.setting_name_to_property(name)
send("#{Configuration.setting_name_to_property(name)}=",value)
else
build_settings[name] = value
end
end | ruby | {
"resource": ""
} |
q18661 | Xcode.Configuration.append | train | def append(name, value)
if respond_to?(name)
send("append_to_#{name}",value)
elsif Configuration.setting_name_to_property(name)
send("append_to_#{Configuration.setting_name_to_property(name)}",value)
else
# @note this will likely raise some errors if trying to append a booleans
# to fixnums, strings to booleans, symbols + arrays, etc. but that likely
# means a new property should be defined so that the appending logic
# wil behave correctly.
if build_settings[name].is_a?(Array)
# Ensure that we are appending an array to the array; Array() does not
# work in this case in the event we were to pass in a Hash.
value = value.is_a?(Array) ? value : [ value ]
build_settings[name] = build_settings[name] + value.compact
else
# Ensure we handle the cases where a nil value is present that we append
# correctly to the value. We also need to try and leave intact boolean
# values which may be stored
value = "" unless value
build_settings[name] = "" unless build_settings[name]
build_settings[name] = build_settings[name] + value
end
end
end | ruby | {
"resource": ""
} |
q18662 | Xcode.Group.group | train | def group(name)
groups.find_all {|group| group.name == name or group.path == name }
end | ruby | {
"resource": ""
} |
q18663 | Xcode.Group.file | train | def file(name)
files.find_all {|file| file.name == name or file.path == name }
end | ruby | {
"resource": ""
} |
q18664 | Xcode.Group.exists? | train | def exists?(name)
children.find_all do |child|
child.name ? (child.name == name) : (File.basename(child.path) == name)
end
end | ruby | {
"resource": ""
} |
q18665 | Xcode.Group.create_group | train | def create_group(name)
new_group = create_child_object Group.logical_group(name)
new_group.supergroup = self
new_group
end | ruby | {
"resource": ""
} |
q18666 | Xcode.Group.create_file | train | def create_file(file_properties)
# This allows both support for the string value or the hash as the parameter
file_properties = { 'path' => file_properties } if file_properties.is_a? String
# IF the file already exists then we will not create the file with the
# parameters that are being supplied, instead we will return what we
# found.
find_file_by = file_properties['name'] || file_properties['path']
found_or_created_file = exists?(find_file_by).first
unless found_or_created_file
found_or_created_file = create_child_object FileReference.file(file_properties)
end
found_or_created_file.supergroup = self
found_or_created_file
end | ruby | {
"resource": ""
} |
q18667 | Xcode.Group.remove! | train | def remove!(&block)
# @note #groups and #files is used because it adds the very precious
# supergroup to each of the child items.
groups.each {|group| group.remove!(&block) }
files.each {|file| file.remove!(&block) }
yield self if block_given?
child_identifier = identifier
supergroup.instance_eval { remove_child_object(child_identifier) }
@registry.remove_object identifier
end | ruby | {
"resource": ""
} |
q18668 | Xcode.Group.find_or_create_child_object | train | def find_or_create_child_object(child_properties)
found_child = children.find {|child| child.name == child_properties['name'] or child.path == child_properties['path'] }
found_child = create_child_object(child_properties) unless found_child
found_child
end | ruby | {
"resource": ""
} |
q18669 | Xcode.Group.remove_child_object | train | def remove_child_object(identifier)
found_child = children.find {|child| child.identifier == identifier }
@properties['children'].delete identifier
save!
found_child
end | ruby | {
"resource": ""
} |
q18670 | Xcode.RakeTask.define_per_project_scheme_builder_tasks | train | def define_per_project_scheme_builder_tasks
projects.each do |project|
project.schemes.each do |scheme|
builder_actions.each do |action|
description = "#{action.capitalize} #{project.name} #{scheme.name}"
task_name = friendlyname("#{name}:#{project.name}:scheme:#{scheme.name}:#{action}")
define_task_with description, task_name do
scheme.builder.send(action)
end
end
end
end
end | ruby | {
"resource": ""
} |
q18671 | Xcode.RakeTask.define_per_project_config_builder_tasks | train | def define_per_project_config_builder_tasks
projects.each do |project|
project.targets.each do |target|
target.configs.each do |config|
builder_actions.each do |action|
description = "#{action.capitalize} #{project.name} #{target.name} #{config.name}"
task_name = friendlyname("#{name}:#{project.name}:#{target.name}:#{config.name}:#{action}")
define_task_with description, task_name do
config.builder.send(action)
end
end
end
end
end
end | ruby | {
"resource": ""
} |
q18672 | Xcode.ProjectReference.group | train | def group(name,options = {},&block)
# By default create missing groups along the way
options = { :create => true }.merge(options)
current_group = main_group
# @todo consider this traversing and find/create as a normal procedure when
# traversing the project.
name.split("/").each do |path_component|
found_group = current_group.group(path_component).first
if options[:create] and found_group.nil?
found_group = current_group.create_group(path_component)
end
current_group = found_group
break unless current_group
end
current_group.instance_eval(&block) if block_given? and current_group
current_group
end | ruby | {
"resource": ""
} |
q18673 | CIDE.Runner.run! | train | def run!(interactive: false)
start_links!
run_options = ['--detach']
@env.each_pair do |key, value|
run_options.push '--env', [key, value].join('=')
end
@links.each do |link|
run_options.push '--link', [link.id, link.name].join(':')
end
run_options.push '--name', @id
run_options.push '--user', @user if @user
run_options.push('--interactive', '--tty') if interactive
run_options.push @tag
run_options.push(*@command)
id = docker(:run, *run_options, capture: true).strip
@containers << id
docker(:attach, id)
end | ruby | {
"resource": ""
} |
q18674 | H3.Regions.max_polyfill_size | train | def max_polyfill_size(geo_polygon, resolution)
geo_polygon = geo_json_to_coordinates(geo_polygon) if geo_polygon.is_a?(String)
Bindings::Private.max_polyfill_size(build_polygon(geo_polygon), resolution)
end | ruby | {
"resource": ""
} |
q18675 | H3.Regions.polyfill | train | def polyfill(geo_polygon, resolution)
geo_polygon = geo_json_to_coordinates(geo_polygon) if geo_polygon.is_a?(String)
max_size = max_polyfill_size(geo_polygon, resolution)
out = H3Indexes.of_size(max_size)
Bindings::Private.polyfill(build_polygon(geo_polygon), resolution, out)
out.read
end | ruby | {
"resource": ""
} |
q18676 | H3.Regions.h3_set_to_linked_geo | train | def h3_set_to_linked_geo(h3_indexes)
h3_set = H3Indexes.with_contents(h3_indexes)
linked_geo_polygon = LinkedGeoPolygon.new
Bindings::Private.h3_set_to_linked_geo(h3_set, h3_indexes.size, linked_geo_polygon)
extract_linked_geo_polygon(linked_geo_polygon).first
ensure
Bindings::Private.destroy_linked_polygon(linked_geo_polygon)
end | ruby | {
"resource": ""
} |
q18677 | H3.Indexing.geo_to_h3 | train | def geo_to_h3(coords, resolution)
raise ArgumentError unless coords.is_a?(Array) && coords.count == 2
lat, lon = coords
if lat > 90 || lat < -90 || lon > 180 || lon < -180
raise(ArgumentError, "Invalid coordinates")
end
coords = GeoCoord.new
coords[:lat] = degs_to_rads(lat)
coords[:lon] = degs_to_rads(lon)
Bindings::Private.geo_to_h3(coords, resolution)
end | ruby | {
"resource": ""
} |
q18678 | H3.Indexing.h3_to_geo | train | def h3_to_geo(h3_index)
coords = GeoCoord.new
Bindings::Private.h3_to_geo(h3_index, coords)
[rads_to_degs(coords[:lat]), rads_to_degs(coords[:lon])]
end | ruby | {
"resource": ""
} |
q18679 | H3.Indexing.h3_to_geo_boundary | train | def h3_to_geo_boundary(h3_index)
geo_boundary = GeoBoundary.new
Bindings::Private.h3_to_geo_boundary(h3_index, geo_boundary)
geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d|
[rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
end
end | ruby | {
"resource": ""
} |
q18680 | H3.UnidirectionalEdges.h3_indexes_from_unidirectional_edge | train | def h3_indexes_from_unidirectional_edge(edge)
max_hexagons = 2
out = H3Indexes.of_size(max_hexagons)
Bindings::Private.h3_indexes_from_unidirectional_edge(edge, out)
out.read
end | ruby | {
"resource": ""
} |
q18681 | H3.UnidirectionalEdges.h3_unidirectional_edges_from_hexagon | train | def h3_unidirectional_edges_from_hexagon(origin)
max_edges = 6
out = H3Indexes.of_size(max_edges)
Bindings::Private.h3_unidirectional_edges_from_hexagon(origin, out)
out.read
end | ruby | {
"resource": ""
} |
q18682 | H3.UnidirectionalEdges.h3_unidirectional_edge_boundary | train | def h3_unidirectional_edge_boundary(edge)
geo_boundary = GeoBoundary.new
Bindings::Private.h3_unidirectional_edge_boundary(edge, geo_boundary)
geo_boundary[:verts].take(geo_boundary[:num_verts]).map do |d|
[rads_to_degs(d[:lat]), rads_to_degs(d[:lon])]
end
end | ruby | {
"resource": ""
} |
q18683 | H3.Traversal.hex_ring | train | def hex_ring(origin, k)
max_hexagons = max_hex_ring_size(k)
out = H3Indexes.of_size(max_hexagons)
pentagonal_distortion = Bindings::Private.hex_ring(origin, k, out)
raise(ArgumentError, "The hex ring contains a pentagon") if pentagonal_distortion
out.read
end | ruby | {
"resource": ""
} |
q18684 | H3.Traversal.hex_ranges | train | def hex_ranges(h3_set, k, grouped: true)
h3_range_indexes = hex_ranges_ungrouped(h3_set, k)
return h3_range_indexes unless grouped
h3_range_indexes.each_slice(max_kring_size(k)).each_with_object({}) do |indexes, out|
h3_index = indexes.first
out[h3_index] = k_rings_for_hex_range(indexes, k)
end
end | ruby | {
"resource": ""
} |
q18685 | H3.Traversal.k_ring_distances | train | def k_ring_distances(origin, k)
max_out_size = max_kring_size(k)
out = H3Indexes.of_size(max_out_size)
distances = FFI::MemoryPointer.new(:int, max_out_size)
Bindings::Private.k_ring_distances(origin, k, out, distances)
hexagons = out.read
distances = distances.read_array_of_int(max_out_size)
Hash[
distances.zip(hexagons).group_by(&:first).map { |d, hs| [d, hs.map(&:last)] }
]
end | ruby | {
"resource": ""
} |
q18686 | H3.Inspection.h3_to_string | train | def h3_to_string(h3_index)
h3_str = FFI::MemoryPointer.new(:char, H3_TO_STR_BUF_SIZE)
Bindings::Private.h3_to_string(h3_index, h3_str, H3_TO_STR_BUF_SIZE)
h3_str.read_string
end | ruby | {
"resource": ""
} |
q18687 | H3.GeoJSON.geo_json_to_coordinates | train | def geo_json_to_coordinates(input)
geom = RGeo::GeoJSON.decode(input)
coordinates = fetch_coordinates(geom)
swap_lat_lon(coordinates) || failed_to_parse!
rescue JSON::ParserError
failed_to_parse!
end | ruby | {
"resource": ""
} |
q18688 | H3.GeoJSON.coordinates_to_geo_json | train | def coordinates_to_geo_json(coordinates)
coordinates = swap_lat_lon(coordinates)
outer_coords, *inner_coords = coordinates
factory = RGeo::Cartesian.simple_factory
exterior = factory.linear_ring(outer_coords.map { |lon, lat| factory.point(lon, lat) })
interior_rings = inner_coords.map do |polygon|
factory.linear_ring(polygon.map { |lon, lat| factory.point(lon, lat) })
end
polygon = factory.polygon(exterior, interior_rings)
RGeo::GeoJSON.encode(polygon).to_json
rescue RGeo::Error::InvalidGeometry, NoMethodError
invalid_coordinates!
end | ruby | {
"resource": ""
} |
q18689 | H3.Hierarchy.h3_to_children | train | def h3_to_children(h3_index, child_resolution)
max_children = max_h3_to_children_size(h3_index, child_resolution)
out = H3Indexes.of_size(max_children)
Bindings::Private.h3_to_children(h3_index, child_resolution, out)
out.read
end | ruby | {
"resource": ""
} |
q18690 | H3.Hierarchy.max_uncompact_size | train | def max_uncompact_size(compacted_set, resolution)
h3_set = H3Indexes.with_contents(compacted_set)
size = Bindings::Private.max_uncompact_size(h3_set, compacted_set.size, resolution)
raise(ArgumentError, "Couldn't estimate size. Invalid resolution?") if size.negative?
size
end | ruby | {
"resource": ""
} |
q18691 | H3.Hierarchy.compact | train | def compact(h3_set)
h3_set = H3Indexes.with_contents(h3_set)
out = H3Indexes.of_size(h3_set.size)
failure = Bindings::Private.compact(h3_set, out, out.size)
raise "Couldn't compact given indexes" if failure
out.read
end | ruby | {
"resource": ""
} |
q18692 | H3.Hierarchy.uncompact | train | def uncompact(compacted_set, resolution)
max_size = max_uncompact_size(compacted_set, resolution)
out = H3Indexes.of_size(max_size)
h3_set = H3Indexes.with_contents(compacted_set)
failure = Bindings::Private.uncompact(h3_set, compacted_set.size, out, max_size, resolution)
raise "Couldn't uncompact given indexes" if failure
out.read
end | ruby | {
"resource": ""
} |
q18693 | Necromancer.ConversionTarget.to | train | def to(target, options = {})
conversion = conversions[source || detect(object, false), detect(target)]
conversion.call(object, options)
end | ruby | {
"resource": ""
} |
q18694 | Necromancer.ConversionTarget.detect | train | def detect(object, symbol_as_object = true)
case object
when TrueClass, FalseClass then :boolean
when Integer then :integer
when Class then object.name.downcase
else
if object.is_a?(Symbol) && symbol_as_object
object
else
object.class.name.downcase
end
end
end | ruby | {
"resource": ""
} |
q18695 | Necromancer.Conversions.load | train | def load
ArrayConverters.load(self)
BooleanConverters.load(self)
DateTimeConverters.load(self)
NumericConverters.load(self)
RangeConverters.load(self)
end | ruby | {
"resource": ""
} |
q18696 | Necromancer.Conversions.register | train | def register(converter = nil, &block)
converter ||= Converter.create(&block)
key = generate_key(converter)
converter = add_config(converter, @configuration)
return false if converter_map.key?(key)
converter_map[key] = converter
true
end | ruby | {
"resource": ""
} |
q18697 | Necromancer.Conversions.add_config | train | def add_config(converter, config)
converter.instance_exec(:"@config") do |var|
instance_variable_set(var, config)
end
converter
end | ruby | {
"resource": ""
} |
q18698 | TLAW.DataTable.[] | train | def [](index_or_column)
case index_or_column
when Integer
super
when String, Symbol
map { |h| h[index_or_column.to_s] }
else
fail ArgumentError,
'Expected integer or string/symbol index' \
", got #{index_or_column.class}"
end
end | ruby | {
"resource": ""
} |
q18699 | TLAW.DataTable.columns | train | def columns(*names)
names.map!(&:to_s)
DataTable.new(map { |h| names.map { |n| [n, h[n]] }.to_h })
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.