id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
18,600
mongoid/origin
lib/origin/selectable.rb
Origin.Selectable.not
def not(*criterion) if criterion.empty? tap { |query| query.negating = true } else __override__(criterion.first, "$not") end end
ruby
def not(*criterion) if criterion.empty? tap { |query| query.negating = true } else __override__(criterion.first, "$not") end end
[ "def", "not", "(", "*", "criterion", ")", "if", "criterion", ".", "empty?", "tap", "{", "|", "query", "|", "query", ".", "negating", "=", "true", "}", "else", "__override__", "(", "criterion", ".", "first", ",", "\"$not\"", ")", "end", "end" ]
Negate the next selection. @example Negate the selection. selectable.not.in(field: [ 1, 2 ]) @example Add the $not criterion. selectable.not(name: /Bob/) @example Execute a $not in a where query. selectable.where(:field.not => /Bob/) @param [ Hash ] criterion The field/value pairs to negate. @return [ Selectable ] The negated selectable. @since 1.0.0
[ "Negate", "the", "next", "selection", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selectable.rb#L421-L427
18,601
mongoid/origin
lib/origin/selectable.rb
Origin.Selectable.text_search
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
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
[ "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" ]
Construct a text search selector. @example Construct a text search selector. selectable.text_search("testing") @example Construct a text search selector with options. selectable.text_search("testing", :$language => "fr") @param [ String, Symbol ] terms A string of terms that MongoDB parses and uses to query the text index. @param [ Hash ] opts Text search options. See MongoDB documentation for options. @return [ Selectable ] The cloned selectable. @since 2.2.0
[ "Construct", "a", "text", "search", "selector", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selectable.rb#L510-L518
18,602
mongoid/origin
lib/origin/selectable.rb
Origin.Selectable.typed_override
def typed_override(criterion, operator) if criterion criterion.update_values do |value| yield(value) end end __override__(criterion, operator) end
ruby
def typed_override(criterion, operator) if criterion criterion.update_values do |value| yield(value) end end __override__(criterion, operator) end
[ "def", "typed_override", "(", "criterion", ",", "operator", ")", "if", "criterion", "criterion", ".", "update_values", "do", "|", "value", "|", "yield", "(", "value", ")", "end", "end", "__override__", "(", "criterion", ",", "operator", ")", "end" ]
Force the values of the criterion to be evolved. @api private @example Force values to booleans. selectable.force_typing(criterion) do |val| Boolean.evolve(val) end @param [ Hash ] criterion The criterion. @since 1.0.0
[ "Force", "the", "values", "of", "the", "criterion", "to", "be", "evolved", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selectable.rb#L571-L578
18,603
mongoid/origin
lib/origin/selectable.rb
Origin.Selectable.selection
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
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
[ "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" ]
Take the provided criterion and store it as a selection in the query selector. @api private @example Store the selection. selectable.selection({ field: "value" }) @param [ Hash ] criterion The selection to store. @return [ Selectable ] The cloned selectable. @since 1.0.0
[ "Take", "the", "provided", "criterion", "and", "store", "it", "as", "a", "selection", "in", "the", "query", "selector", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selectable.rb#L611-L620
18,604
mongoid/origin
lib/origin/queryable.rb
Origin.Queryable.initialize_copy
def initialize_copy(other) @options = other.options.__deep_copy__ @selector = other.selector.__deep_copy__ @pipeline = other.pipeline.__deep_copy__ end
ruby
def initialize_copy(other) @options = other.options.__deep_copy__ @selector = other.selector.__deep_copy__ @pipeline = other.pipeline.__deep_copy__ end
[ "def", "initialize_copy", "(", "other", ")", "@options", "=", "other", ".", "options", ".", "__deep_copy__", "@selector", "=", "other", ".", "selector", ".", "__deep_copy__", "@pipeline", "=", "other", ".", "pipeline", ".", "__deep_copy__", "end" ]
Is this queryable equal to another object? Is true if the selector and options are equal. @example Are the objects equal? queryable == criteria @param [ Object ] other The object to compare against. @return [ true, false ] If the objects are equal. @since 1.0.0 Initialize the new queryable. Will yield itself to the block if a block is provided for objects that need additional behaviour. @example Initialize the queryable. Origin::Queryable.new @param [ Hash ] aliases The optional field aliases. @param [ Hash ] serializers The optional field serializers. @param [ Symbol ] driver The driver being used. @since 1.0.0 Handle the creation of a copy via #clone or #dup. @example Handle copy initialization. queryable.initialize_copy(criteria) @param [ Queryable ] other The original copy. @since 1.0.0
[ "Is", "this", "queryable", "equal", "to", "another", "object?", "Is", "true", "if", "the", "selector", "and", "options", "are", "equal", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/queryable.rb#L77-L81
18,605
mongoid/origin
lib/origin/pipeline.rb
Origin.Pipeline.evolve
def evolve(entry) aggregate = Selector.new(aliases) entry.each_pair do |field, value| aggregate.merge!(field.to_s => value) end aggregate end
ruby
def evolve(entry) aggregate = Selector.new(aliases) entry.each_pair do |field, value| aggregate.merge!(field.to_s => value) end aggregate end
[ "def", "evolve", "(", "entry", ")", "aggregate", "=", "Selector", ".", "new", "(", "aliases", ")", "entry", ".", "each_pair", "do", "|", "field", ",", "value", "|", "aggregate", ".", "merge!", "(", "field", ".", "to_s", "=>", "value", ")", "end", "aggregate", "end" ]
Evolve the entry using the aliases. @api private @example Evolve the entry. pipeline.evolve(name: 1) @param [ Hash ] entry The entry to evolve. @return [ Hash ] The evolved entry. @since 2.0.0
[ "Evolve", "the", "entry", "using", "the", "aliases", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/pipeline.rb#L99-L105
18,606
mongoid/origin
lib/origin/forwardable.rb
Origin.Forwardable.select_with
def select_with(receiver) (Selectable.forwardables + Optional.forwardables).each do |name| __forward__(name, receiver) end end
ruby
def select_with(receiver) (Selectable.forwardables + Optional.forwardables).each do |name| __forward__(name, receiver) end end
[ "def", "select_with", "(", "receiver", ")", "(", "Selectable", ".", "forwardables", "+", "Optional", ".", "forwardables", ")", ".", "each", "do", "|", "name", "|", "__forward__", "(", "name", ",", "receiver", ")", "end", "end" ]
Tells origin with method on the class to delegate to when calling an original selectable or optional method on the class. @example Tell origin where to select from. class Band extend Origin::Forwardable select_with :criteria def self.criteria Query.new end end @param [ Symbol ] receiver The name of the receiver method. @return [ Array<Symbol> ] The names of the forwarded methods. @since 1.0.0
[ "Tells", "origin", "with", "method", "on", "the", "class", "to", "delegate", "to", "when", "calling", "an", "original", "selectable", "or", "optional", "method", "on", "the", "class", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/forwardable.rb#L26-L30
18,607
mongoid/origin
lib/origin/aggregable.rb
Origin.Aggregable.aggregation
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
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
[ "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" ]
Add the aggregation operation. @api private @example Aggregate on the operation. aggregation(operation) do |pipeline| pipeline.push("$project" => operation) end @param [ Hash ] operation The operation for the pipeline. @return [ Aggregable ] The cloned aggregable. @since 2.0.0
[ "Add", "the", "aggregation", "operation", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/aggregable.rb#L104-L114
18,608
mongoid/origin
lib/origin/smash.rb
Origin.Smash.storage_pair
def storage_pair(key) field = key.to_s name = aliases[field] || field [ name, serializers[name] ] end
ruby
def storage_pair(key) field = key.to_s name = aliases[field] || field [ name, serializers[name] ] end
[ "def", "storage_pair", "(", "key", ")", "field", "=", "key", ".", "to_s", "name", "=", "aliases", "[", "field", "]", "||", "field", "[", "name", ",", "serializers", "[", "name", "]", "]", "end" ]
Get the pair of objects needed to store the value in a hash by the provided key. This is the database field name and the serializer. @api private @example Get the name and serializer. smash.storage_pair("id") @param [ Symbol, String ] key The key provided to the selection. @return [ Array<String, Object> ] The name of the db field and serializer. @since 1.0.0
[ "Get", "the", "pair", "of", "objects", "needed", "to", "store", "the", "value", "in", "a", "hash", "by", "the", "provided", "key", ".", "This", "is", "the", "database", "field", "name", "and", "the", "serializer", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/smash.rb#L93-L97
18,609
mongoid/origin
lib/origin/mergeable.rb
Origin.Mergeable.with_strategy
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
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
[ "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" ]
Add criterion to the selection with the named strategy. @api private @example Add criterion with a strategy. mergeable.with_strategy(:__union__, [ 1, 2, 3 ], "$in") @param [ Symbol ] strategy The name of the strategy method. @param [ Object ] criterion The criterion to add. @param [ String ] operator The MongoDB operator. @return [ Mergeable ] The cloned query. @since 1.0.0
[ "Add", "criterion", "to", "the", "selection", "with", "the", "named", "strategy", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/mergeable.rb#L235-L242
18,610
mongoid/origin
lib/origin/mergeable.rb
Origin.Mergeable.prepare
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
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
[ "def", "prepare", "(", "field", ",", "operator", ",", "value", ")", "unless", "operator", "=~", "/", "/", "value", "=", "value", ".", "__expand_complex__", "serializer", "=", "serializers", "[", "field", "]", "value", "=", "serializer", "?", "serializer", ".", "evolve", "(", "value", ")", ":", "value", "end", "selection", "=", "{", "operator", "=>", "value", "}", "negating?", "?", "{", "\"$not\"", "=>", "selection", "}", ":", "selection", "end" ]
Prepare the value for merging. @api private @example Prepare the value. mergeable.prepare("field", "$gt", 10) @param [ String ] field The name of the field. @param [ Object ] value The value. @return [ Object ] The serialized value. @since 1.0.0
[ "Prepare", "the", "value", "for", "merging", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/mergeable.rb#L257-L265
18,611
mongoid/origin
lib/origin/selector.rb
Origin.Selector.merge!
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
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
[ "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" ]
Merges another selector into this one. @example Merge in another selector. selector.merge!(name: "test") @param [ Hash, Selector ] other The object to merge in. @return [ Selector ] The selector. @since 1.0.0
[ "Merges", "another", "selector", "into", "this", "one", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selector.rb#L18-L36
18,612
mongoid/origin
lib/origin/selector.rb
Origin.Selector.store
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
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
[ "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" ]
Store the value in the selector for the provided key. The selector will handle all necessary serialization and localization in this step. @example Store a value in the selector. selector.store(:key, "testing") @param [ String, Symbol ] key The name of the attribute. @param [ Object ] value The value to add. @return [ Object ] The stored object. @since 1.0.0
[ "Store", "the", "value", "in", "the", "selector", "for", "the", "provided", "key", ".", "The", "selector", "will", "handle", "all", "necessary", "serialization", "and", "localization", "in", "this", "step", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selector.rb#L50-L57
18,613
mongoid/origin
lib/origin/selector.rb
Origin.Selector.evolve
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
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
[ "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" ]
Evolve a single key selection with various types of values. @api private @example Evolve a simple selection. selector.evolve(field, 5) @param [ Object ] serializer The optional serializer for the field. @param [ Object ] value The value to serialize. @return [ Object ] The serialized object. @since 1.0.0
[ "Evolve", "a", "single", "key", "selection", "with", "various", "types", "of", "values", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/selector.rb#L112-L121
18,614
mongoid/origin
lib/origin/options.rb
Origin.Options.to_pipeline
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
def to_pipeline pipeline = [] pipeline.push({ "$skip" => skip }) if skip pipeline.push({ "$limit" => limit }) if limit pipeline.push({ "$sort" => sort }) if sort pipeline end
[ "def", "to_pipeline", "pipeline", "=", "[", "]", "pipeline", ".", "push", "(", "{", "\"$skip\"", "=>", "skip", "}", ")", "if", "skip", "pipeline", ".", "push", "(", "{", "\"$limit\"", "=>", "limit", "}", ")", "if", "limit", "pipeline", ".", "push", "(", "{", "\"$sort\"", "=>", "sort", "}", ")", "if", "sort", "pipeline", "end" ]
Convert the options to aggregation pipeline friendly options. @example Convert the options to a pipeline. options.to_pipeline @return [ Array<Hash> ] The options in pipeline form. @since 2.0.0
[ "Convert", "the", "options", "to", "aggregation", "pipeline", "friendly", "options", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/options.rb#L81-L87
18,615
mongoid/origin
lib/origin/macroable.rb
Origin.Macroable.key
def key(name, strategy, operator, additional = nil, &block) ::Symbol.add_key(name, strategy, operator, additional, &block) end
ruby
def key(name, strategy, operator, additional = nil, &block) ::Symbol.add_key(name, strategy, operator, additional, &block) end
[ "def", "key", "(", "name", ",", "strategy", ",", "operator", ",", "additional", "=", "nil", ",", "&", "block", ")", "::", "Symbol", ".", "add_key", "(", "name", ",", "strategy", ",", "operator", ",", "additional", ",", "block", ")", "end" ]
Adds a method on Symbol for convenience in where queries for the provided operators. @example Add a symbol key. key :all, "$all @param [ Symbol ] name The name of the method. @param [ Symbol ] strategy The merge strategy. @param [ String ] operator The MongoDB operator. @param [ String ] additional The additional MongoDB operator. @since 1.0.0
[ "Adds", "a", "method", "on", "Symbol", "for", "convenience", "in", "where", "queries", "for", "the", "provided", "operators", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/macroable.rb#L19-L21
18,616
mongoid/origin
lib/origin/optional.rb
Origin.Optional.order_by
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
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
[ "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" ]
Adds sorting criterion to the options. @example Add sorting options via a hash with integer directions. optional.order_by(name: 1, dob: -1) @example Add sorting options via a hash with symbol directions. optional.order_by(name: :asc, dob: :desc) @example Add sorting options via a hash with string directions. optional.order_by(name: "asc", dob: "desc") @example Add sorting options via an array with integer directions. optional.order_by([[ name, 1 ], [ dob, -1 ]]) @example Add sorting options via an array with symbol directions. optional.order_by([[ name, :asc ], [ dob, :desc ]]) @example Add sorting options via an array with string directions. optional.order_by([[ name, "asc" ], [ dob, "desc" ]]) @example Add sorting options with keys. optional.order_by(:name.asc, :dob.desc) @example Add sorting options via a string. optional.order_by("name ASC, dob DESC") @param [ Array, Hash, String ] spec The sorting specification. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Adds", "sorting", "criterion", "to", "the", "options", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L170-L179
18,617
mongoid/origin
lib/origin/optional.rb
Origin.Optional.skip
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
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
[ "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" ]
Add the number of documents to skip. @example Add the number to skip. optional.skip(100) @param [ Integer ] value The number to skip. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Add", "the", "number", "of", "documents", "to", "skip", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L208-L214
18,618
mongoid/origin
lib/origin/optional.rb
Origin.Optional.slice
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
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
[ "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" ]
Limit the returned results via slicing embedded arrays. @example Slice the returned results. optional.slice(aliases: [ 0, 5 ]) @param [ Hash ] criterion The slice options. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Limit", "the", "returned", "results", "via", "slicing", "embedded", "arrays", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L227-L235
18,619
mongoid/origin
lib/origin/optional.rb
Origin.Optional.without
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
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
[ "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" ]
Limits the results to only contain the fields not provided. @example Limit the results to the fields not provided. optional.without(:name, :dob) @param [ Array<Symbol> ] args The fields to ignore. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Limits", "the", "results", "to", "only", "contain", "the", "fields", "not", "provided", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L261-L268
18,620
mongoid/origin
lib/origin/optional.rb
Origin.Optional.add_sort_option
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
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
[ "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" ]
Add a single sort option. @api private @example Add a single sort option. optional.add_sort_option({}, :name, 1) @param [ Hash ] options The options. @param [ String ] field The field name. @param [ Integer ] direction The sort direction. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Add", "a", "single", "sort", "option", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L336-L346
18,621
mongoid/origin
lib/origin/optional.rb
Origin.Optional.option
def option(*args) clone.tap do |query| unless args.compact.empty? yield(query.options, query) end end end
ruby
def option(*args) clone.tap do |query| unless args.compact.empty? yield(query.options, query) end end end
[ "def", "option", "(", "*", "args", ")", "clone", ".", "tap", "do", "|", "query", "|", "unless", "args", ".", "compact", ".", "empty?", "yield", "(", "query", ".", "options", ",", "query", ")", "end", "end", "end" ]
Take the provided criterion and store it as an option in the query options. @api private @example Store the option. optional.option({ skip: 10 }) @param [ Array ] args The options. @return [ Queryable ] The cloned queryable. @since 1.0.0
[ "Take", "the", "provided", "criterion", "and", "store", "it", "as", "an", "option", "in", "the", "query", "options", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L361-L367
18,622
mongoid/origin
lib/origin/optional.rb
Origin.Optional.sort_with_list
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
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
[ "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" ]
Add multiple sort options at once. @api private @example Add multiple sort options. optional.sort_with_list(:name, :dob, 1) @param [ Array<String> ] fields The field names. @param [ Integer ] direction The sort direction. @return [ Optional ] The cloned optional. @since 1.0.0
[ "Add", "multiple", "sort", "options", "at", "once", "." ]
b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63
https://github.com/mongoid/origin/blob/b0bb0504d4e9289882cf9cd2fcc8dbd62cc29d63/lib/origin/optional.rb#L382-L389
18,623
technoweenie/guillotine
lib/guillotine.rb
Guillotine.Adapter.parse_url
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
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
[ "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" ]
Parses and sanitizes a URL. url - A String URL. options - A Guillotine::Service::Options object. Returns an Addressable::URI.
[ "Parses", "and", "sanitizes", "a", "URL", "." ]
73afb1c435086b487467914f300bfebe3821c2f3
https://github.com/technoweenie/guillotine/blob/73afb1c435086b487467914f300bfebe3821c2f3/lib/guillotine.rb#L68-L73
18,624
technoweenie/guillotine
lib/guillotine/adapters/riak_adapter.rb
Guillotine.RiakAdapter.add
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
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
[ "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" ]
Initializes the adapter. code_bucket - The Riak::Bucket for all code keys. url_bucket - The Riak::Bucket for all url keys. If this is not given, the code bucket is used for all keys. Public: Stores the shortened version of a URL. url - The String URL to shorten and store. code - Optional String code for the URL. options - Optional Guillotine::Service::Options Returns the unique String code for the URL. If the URL is added multiple times, this should return the same code.
[ "Initializes", "the", "adapter", "." ]
73afb1c435086b487467914f300bfebe3821c2f3
https://github.com/technoweenie/guillotine/blob/73afb1c435086b487467914f300bfebe3821c2f3/lib/guillotine/adapters/riak_adapter.rb#L27-L51
18,625
technoweenie/guillotine
lib/guillotine/adapters/riak_adapter.rb
Guillotine.RiakAdapter.url_object
def url_object(code) @code_bucket.get(code, :r => 1) rescue Riak::FailedRequest => err raise unless err.not_found? end
ruby
def url_object(code) @code_bucket.get(code, :r => 1) rescue Riak::FailedRequest => err raise unless err.not_found? end
[ "def", "url_object", "(", "code", ")", "@code_bucket", ".", "get", "(", "code", ",", ":r", "=>", "1", ")", "rescue", "Riak", "::", "FailedRequest", "=>", "err", "raise", "unless", "err", ".", "not_found?", "end" ]
Retrieves a URL riak value from the code. code - The String code to lookup the URL. Returns a Riak::RObject, or nil if none is found.
[ "Retrieves", "a", "URL", "riak", "value", "from", "the", "code", "." ]
73afb1c435086b487467914f300bfebe3821c2f3
https://github.com/technoweenie/guillotine/blob/73afb1c435086b487467914f300bfebe3821c2f3/lib/guillotine/adapters/riak_adapter.rb#L104-L108
18,626
technoweenie/guillotine
lib/guillotine/adapters/riak_adapter.rb
Guillotine.RiakAdapter.code_object
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
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
[ "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" ]
Retrieves the code riak value for a given URL. url - The String URL to lookup. Returns a Riak::RObject, or nil if none is found.
[ "Retrieves", "the", "code", "riak", "value", "for", "a", "given", "URL", "." ]
73afb1c435086b487467914f300bfebe3821c2f3
https://github.com/technoweenie/guillotine/blob/73afb1c435086b487467914f300bfebe3821c2f3/lib/guillotine/adapters/riak_adapter.rb#L115-L122
18,627
rayh/xcoder
lib/xcode/configuration_list.rb
Xcode.ConfigurationList.create_config
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
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
[ "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" ]
Create a configuration for this ConfigurationList. This configuration needs to have a name. @note unique names are currently not enforced but likely necessary for the the target to be build successfully. @param [Types] name Description
[ "Create", "a", "configuration", "for", "this", "ConfigurationList", ".", "This", "configuration", "needs", "to", "have", "a", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration_list.rb#L39-L52
18,628
rayh/xcoder
lib/xcode/resource.rb
Xcode.Resource.define_property
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
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
[ "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" ]
Definiing a property allows the creation of an alias to the actual value. This level of indirection allows for the replacement of values which are identifiers with a resource representation of it. @note This is used internally by the resource when it is created to create the getter/setter methods. @param [String] name of the property @param [String] value of the property
[ "Definiing", "a", "property", "allows", "the", "creation", "of", "an", "alias", "to", "the", "actual", "value", ".", "This", "level", "of", "indirection", "allows", "for", "the", "replacement", "of", "values", "which", "are", "identifiers", "with", "a", "resource", "representation", "of", "it", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/resource.rb#L113-L167
18,629
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.file
def file(name_with_path) path, name = File.split(name_with_path) group(path).file(name).first end
ruby
def file(name_with_path) path, name = File.split(name_with_path) group(path).file(name).first end
[ "def", "file", "(", "name_with_path", ")", "path", ",", "name", "=", "File", ".", "split", "(", "name_with_path", ")", "group", "(", "path", ")", ".", "file", "(", "name", ")", ".", "first", "end" ]
Return the file that matches the specified path. This will traverse the project's groups and find the file at the end of the path. @param [String] name_with_path the path to the file @return [FileReference] the file that matches the name, nil if no file matches the path.
[ "Return", "the", "file", "that", "matches", "the", "specified", "path", ".", "This", "will", "traverse", "the", "project", "s", "groups", "and", "find", "the", "file", "at", "the", "end", "of", "the", "path", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L156-L159
18,630
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.products_group
def products_group current_group = groups.group('Products').first current_group.instance_eval(&block) if block_given? and current_group current_group end
ruby
def products_group current_group = groups.group('Products').first current_group.instance_eval(&block) if block_given? and current_group current_group end
[ "def", "products_group", "current_group", "=", "groups", ".", "group", "(", "'Products'", ")", ".", "first", "current_group", ".", "instance_eval", "(", "block", ")", "if", "block_given?", "and", "current_group", "current_group", "end" ]
Most Xcode projects have a products group where products are placed. This will generate an exception if there is no products group. @return [Group] the 'Products' group of the project.
[ "Most", "Xcode", "projects", "have", "a", "products", "group", "where", "products", "are", "placed", ".", "This", "will", "generate", "an", "exception", "if", "there", "is", "no", "products", "group", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L166-L170
18,631
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.frameworks_group
def frameworks_group current_group = groups.group('Frameworks').first current_group.instance_eval(&block) if block_given? and current_group current_group end
ruby
def frameworks_group current_group = groups.group('Frameworks').first current_group.instance_eval(&block) if block_given? and current_group current_group end
[ "def", "frameworks_group", "current_group", "=", "groups", ".", "group", "(", "'Frameworks'", ")", ".", "first", "current_group", ".", "instance_eval", "(", "block", ")", "if", "block_given?", "and", "current_group", "current_group", "end" ]
Most Xcode projects have a Frameworks gorup where all the imported frameworks are shown. This will generate an exception if there is no Frameworks group. @return [Group] the 'Frameworks' group of the projet.
[ "Most", "Xcode", "projects", "have", "a", "Frameworks", "gorup", "where", "all", "the", "imported", "frameworks", "are", "shown", ".", "This", "will", "generate", "an", "exception", "if", "there", "is", "no", "Frameworks", "group", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L178-L182
18,632
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.save
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
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
[ "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" ]
Saves the current project at the specified path. @note currently this does not support saving the workspaces associated with the project to their new location. @param [String] path the path to save the project
[ "Saves", "the", "current", "project", "at", "the", "specified", "path", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L217-L227
18,633
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.scheme
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
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
[ "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" ]
Return the scheme with the specified name. Raises an error if no schemes match the specified name. @note if two schemes match names, the first matching scheme is returned. @param [String] name of the specific scheme @return [Scheme] the specific scheme that matches the name specified
[ "Return", "the", "scheme", "with", "the", "specified", "name", ".", "Raises", "an", "error", "if", "no", "schemes", "match", "the", "specified", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L238-L243
18,634
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.target
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
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
[ "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" ]
Return the target with the specified name. Raises an error if no targets match the specified name. @note if two targets match names, the first matching target is returned. @param [String] name of the specific target @return [Target] the specific target that matches the name specified
[ "Return", "the", "target", "with", "the", "specified", "name", ".", "Raises", "an", "error", "if", "no", "targets", "match", "the", "specified", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L267-L272
18,635
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.create_target
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
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
[ "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" ]
Creates a new target within the Xcode project. This will by default not generate all the additional build phases, configurations, and files that create a project. Available targts: * native * aggregate @param [String] name the name to provide to the target. This will also be the value that other defaults will be based on. @param [String,Symbol] type the type of build target to create. @return [Target] the target created.
[ "Creates", "a", "new", "target", "within", "the", "Xcode", "project", ".", "This", "will", "by", "default", "not", "generate", "all", "the", "additional", "build", "phases", "configurations", "and", "files", "that", "create", "a", "project", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L290-L305
18,636
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.remove_target
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
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
[ "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" ]
Remove a target from the Xcode project. @note this will remove the first target that matches the specified name. @note this will remove only the project entry at the moment and not the the files that may be associated with the target. All build phases, build files, and configurations will automatically be cleaned up when Xcode is opened. @param [String] name the name of the target to remove from the Xcode project. @return [Target] the target that has been removed.
[ "Remove", "a", "target", "from", "the", "Xcode", "project", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L322-L329
18,637
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.describe
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
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
[ "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" ]
Prints to STDOUT a description of this project's targets, configuration and schemes.
[ "Prints", "to", "STDOUT", "a", "description", "of", "this", "project", "s", "targets", "configuration", "and", "schemes", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L334-L347
18,638
rayh/xcoder
lib/xcode/project.rb
Xcode.Project.parse_pbxproj
def parse_pbxproj registry = Xcode::PLUTILProjectParser.parse "#{@path}/project.pbxproj" class << registry include Xcode::Registry end registry end
ruby
def parse_pbxproj registry = Xcode::PLUTILProjectParser.parse "#{@path}/project.pbxproj" class << registry include Xcode::Registry end registry end
[ "def", "parse_pbxproj", "registry", "=", "Xcode", "::", "PLUTILProjectParser", ".", "parse", "\"#{@path}/project.pbxproj\"", "class", "<<", "registry", "include", "Xcode", "::", "Registry", "end", "registry", "end" ]
Using the sytem tool plutil, the specified project file is parsed and converted to JSON, which is then converted to a hash object. This content contains all the data within the project file and is used to create the Registry. @return [Registry] the representation of the project, this is a Hash with additional methods to provide easier functionality.
[ "Using", "the", "sytem", "tool", "plutil", "the", "specified", "project", "file", "is", "parsed", "and", "converted", "to", "JSON", "which", "is", "then", "converted", "to", "a", "hash", "object", ".", "This", "content", "contains", "all", "the", "data", "within", "the", "project", "file", "and", "is", "used", "to", "create", "the", "Registry", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project.rb#L360-L368
18,639
rayh/xcoder
lib/xcode/parsers/plutil_project_parser.rb
Xcode.PLUTILProjectParser.parse
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
def parse(path) registry = Plist.parse_xml open_project_file(path) raise "Failed to correctly parse the project file #{path}" unless registry registry end
[ "def", "parse", "(", "path", ")", "registry", "=", "Plist", ".", "parse_xml", "open_project_file", "(", "path", ")", "raise", "\"Failed to correctly parse the project file #{path}\"", "unless", "registry", "registry", "end" ]
Using the sytem tool plutil, the specified project file is parsed and converted to XML, and then converted into a ruby hash object.
[ "Using", "the", "sytem", "tool", "plutil", "the", "specified", "project", "file", "is", "parsed", "and", "converted", "to", "XML", "and", "then", "converted", "into", "a", "ruby", "hash", "object", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/parsers/plutil_project_parser.rb#L13-L19
18,640
rayh/xcoder
lib/xcode/terminal_output.rb
Xcode.TerminalOutput.print_input
def print_input message, level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", "<") + message, :default end
ruby
def print_input message, level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", "<") + message, :default end
[ "def", "print_input", "message", ",", "level", "=", ":debug", "return", "if", "LEVELS", ".", "index", "(", "level", ")", ">", "LEVELS", ".", "index", "(", "@@log_level", ")", "puts", "format_lhs", "(", "\"\"", ",", "\"\"", ",", "\"<\"", ")", "+", "message", ",", ":default", "end" ]
Print an IO input interaction
[ "Print", "an", "IO", "input", "interaction" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/terminal_output.rb#L40-L43
18,641
rayh/xcoder
lib/xcode/terminal_output.rb
Xcode.TerminalOutput.print_output
def print_output message, level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", ">") + message, :default end
ruby
def print_output message, level=:debug return if LEVELS.index(level) > LEVELS.index(@@log_level) puts format_lhs("", "", ">") + message, :default end
[ "def", "print_output", "message", ",", "level", "=", ":debug", "return", "if", "LEVELS", ".", "index", "(", "level", ")", ">", "LEVELS", ".", "index", "(", "@@log_level", ")", "puts", "format_lhs", "(", "\"\"", ",", "\"\"", ",", "\">\"", ")", "+", "message", ",", ":default", "end" ]
Print an IO output interaction
[ "Print", "an", "IO", "output", "interaction" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/terminal_output.rb#L47-L50
18,642
rayh/xcoder
lib/xcode/target.rb
Xcode.Target.create_build_phases
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
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
[ "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" ]
Create multiple build phases at the same time. @param [Array<String,Symbol>] base_phase_names are the names of the phases that you want to create for a target. @return [Array] the phases created.
[ "Create", "multiple", "build", "phases", "at", "the", "same", "time", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/target.rb#L184-L194
18,643
rayh/xcoder
lib/xcode/target.rb
Xcode.Target.create_product_reference
def create_product_reference(name) product = project.products_group.create_product_reference(name) product_reference = product.identifier product end
ruby
def create_product_reference(name) product = project.products_group.create_product_reference(name) product_reference = product.identifier product end
[ "def", "create_product_reference", "(", "name", ")", "product", "=", "project", ".", "products_group", ".", "create_product_reference", "(", "name", ")", "product_reference", "=", "product", ".", "identifier", "product", "end" ]
Create a product reference file and add it to the product. This is by default added to the 'Products' group. @param [String] name of the product reference to add to the product @return [Resource] the product created
[ "Create", "a", "product", "reference", "file", "and", "add", "it", "to", "the", "product", ".", "This", "is", "by", "default", "added", "to", "the", "Products", "group", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/target.rb#L217-L221
18,644
rayh/xcoder
lib/xcode/keychain.rb
Xcode.Keychain.in_search_path
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
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
[ "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" ]
Installs this keychain in the head of teh search path and restores the original on completion of the block @param the block to be invoked with the modified search path
[ "Installs", "this", "keychain", "in", "the", "head", "of", "teh", "search", "path", "and", "restores", "the", "original", "on", "completion", "of", "the", "block" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/keychain.rb#L71-L80
18,645
rayh/xcoder
lib/xcode/keychain.rb
Xcode.Keychain.import
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
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
[ "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" ]
Import the .p12 certificate file into the keychain using the provided password @param [String] the path to the .p12 certificate file @param [String] the password to open the certificate file
[ "Import", "the", ".", "p12", "certificate", "file", "into", "the", "keychain", "using", "the", "provided", "password" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/keychain.rb#L88-L95
18,646
rayh/xcoder
lib/xcode/keychain.rb
Xcode.Keychain.identities
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
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
[ "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", "/", "do", "|", "m", "|", "names", "<<", "m", "[", "0", "]", "end", "names", "end" ]
Returns a list of identities in the keychain. @return [Array<String>] a list of identity names
[ "Returns", "a", "list", "of", "identities", "in", "the", "keychain", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/keychain.rb#L102-L113
18,647
rayh/xcoder
lib/xcode/keychain.rb
Xcode.Keychain.lock
def lock cmd = Xcode::Shell::Command.new "security" cmd << "lock-keychain" cmd << "\"#{@path}\"" cmd.execute end
ruby
def lock cmd = Xcode::Shell::Command.new "security" cmd << "lock-keychain" cmd << "\"#{@path}\"" cmd.execute end
[ "def", "lock", "cmd", "=", "Xcode", "::", "Shell", "::", "Command", ".", "new", "\"security\"", "cmd", "<<", "\"lock-keychain\"", "cmd", "<<", "\"\\\"#{@path}\\\"\"", "cmd", ".", "execute", "end" ]
Secure the keychain
[ "Secure", "the", "keychain" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/keychain.rb#L118-L123
18,648
rayh/xcoder
lib/xcode/keychain.rb
Xcode.Keychain.unlock
def unlock(password) cmd = Xcode::Shell::Command.new "security" cmd << "unlock-keychain" cmd << "-p #{password}" cmd << "\"#{@path}\"" cmd.execute end
ruby
def unlock(password) cmd = Xcode::Shell::Command.new "security" cmd << "unlock-keychain" cmd << "-p #{password}" cmd << "\"#{@path}\"" cmd.execute end
[ "def", "unlock", "(", "password", ")", "cmd", "=", "Xcode", "::", "Shell", "::", "Command", ".", "new", "\"security\"", "cmd", "<<", "\"unlock-keychain\"", "cmd", "<<", "\"-p #{password}\"", "cmd", "<<", "\"\\\"#{@path}\\\"\"", "cmd", ".", "execute", "end" ]
Unlock the keychain using the provided password @param [String] the password to open the keychain
[ "Unlock", "the", "keychain", "using", "the", "provided", "password" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/keychain.rb#L130-L136
18,649
rayh/xcoder
lib/xcode/configuration_owner.rb
Xcode.ConfigurationOwner.config
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
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
[ "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" ]
Return a specific build configuration. @note an exception is raised if no configuration matches the specified name. @param [String] name of a configuration to return @return [BuildConfiguration] a specific build configuration that matches the specified name.
[ "Return", "a", "specific", "build", "configuration", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration_owner.rb#L26-L31
18,650
rayh/xcoder
lib/xcode/configuration_owner.rb
Xcode.ConfigurationOwner.create_configuration
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
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
[ "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" ]
Create a configuration for the target or project. @example creating a new 'App Store Submission' configuration for a project project.create_config 'App Store Submission' # => Configuration @example creating a new 'Ad Hoc' configuration for a target target.create_config 'Ad Hoc' do |config| # configuration the new debug config. end @param [String] name of the configuration to create @return [BuildConfiguration] that is created
[ "Create", "a", "configuration", "for", "the", "target", "or", "project", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration_owner.rb#L49-L57
18,651
rayh/xcoder
lib/xcode/configuration_owner.rb
Xcode.ConfigurationOwner.create_configurations
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
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
[ "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" ]
Create multiple configurations for a target or project. @example creating 'Release' and 'Debug for a new target new_target = project.create_target 'UniversalBinary' new_target.create_configurations 'Debug', 'Release' do |config| # set up the configurations end @param [String,Array<String>] configuration_names the names of the configurations to create.
[ "Create", "multiple", "configurations", "for", "a", "target", "or", "project", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration_owner.rb#L72-L82
18,652
rayh/xcoder
lib/xcode/build_phase.rb
Xcode.BuildPhase.file
def file(name) files.find {|file| file.file_ref.name == name or file.file_ref.path == name } end
ruby
def file(name) files.find {|file| file.file_ref.name == name or file.file_ref.path == name } end
[ "def", "file", "(", "name", ")", "files", ".", "find", "{", "|", "file", "|", "file", ".", "file_ref", ".", "name", "==", "name", "or", "file", ".", "file_ref", ".", "path", "==", "name", "}", "end" ]
Return the BuildFile given the file name. @param [String] name of the FileReference that is being built. @return [BuildFile] the BuildFile that links to the file specified with the name.
[ "Return", "the", "BuildFile", "given", "the", "file", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/build_phase.rb#L79-L81
18,653
rayh/xcoder
lib/xcode/build_phase.rb
Xcode.BuildPhase.build_file
def build_file(name) build_files.find {|file| file.name == name or file.path == name } end
ruby
def build_file(name) build_files.find {|file| file.name == name or file.path == name } end
[ "def", "build_file", "(", "name", ")", "build_files", ".", "find", "{", "|", "file", "|", "file", ".", "name", "==", "name", "or", "file", ".", "path", "==", "name", "}", "end" ]
Find the first file that has the name or path that matches the specified parameter. @note this is the FileReference, the file being built and not the instance of the BuildFile. @see #file @param [String] name the name or the path of the file. @return [FileReference] the file referenced that matches the name or path; nil if no file is found.
[ "Find", "the", "first", "file", "that", "has", "the", "name", "or", "path", "that", "matches", "the", "specified", "parameter", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/build_phase.rb#L108-L110
18,654
rayh/xcoder
lib/xcode/build_phase.rb
Xcode.BuildPhase.add_build_file
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
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
[ "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" ]
Add the specified file to the Build Phase. First a BuildFile entry is created for the file and then the build file entry is added to the particular build phase. A BuildFile identifier must exist for each target. @example adding a source file to the sources build phase spec_file = project.group('Specs/Controller').create_file('FirstControllerSpec.m') project.target('Specs').sources_build_phase.add_build_file spec_file @example adding a source file, that does not use ARC, to the sources build phase spec_file = project.group('Specs/Controller').create_file('FirstControllerSpec.m') project.target('Specs').sources_build_phase.add_build_file spec_file, { 'COMPILER_FLAGS' => "-fno-objc-arc" } @param [FileReference] file the FileReference Resource to add to the build phase. @param [Hash] settings additional build settings that are specifically applied to this individual file.
[ "Add", "the", "specified", "file", "to", "the", "Build", "Phase", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/build_phase.rb#L134-L140
18,655
rayh/xcoder
lib/xcode/registry.rb
Xcode.Registry.add_object
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
def add_object(object_properties) new_identifier = SimpleIdentifierGenerator.generate :existing_keys => objects.keys objects[new_identifier] = object_properties Resource.new new_identifier, self end
[ "def", "add_object", "(", "object_properties", ")", "new_identifier", "=", "SimpleIdentifierGenerator", ".", "generate", ":existing_keys", "=>", "objects", ".", "keys", "objects", "[", "new_identifier", "]", "=", "object_properties", "Resource", ".", "new", "new_identifier", ",", "self", "end" ]
Provides a method to generically add objects to the registry. This will create a unqiue identifier and add the specified parameters to the registry. As all objecst within a the project maintain a reference to this registry they can immediately query for newly created items. @note generally this method should not be called directly and instead resources should provide the ability to assist with generating the correct objects for the registry. @param [Hash] object_properties a hash that contains all the properties that are known for the particular item.
[ "Provides", "a", "method", "to", "generically", "add", "objects", "to", "the", "registry", ".", "This", "will", "create", "a", "unqiue", "identifier", "and", "add", "the", "specified", "parameters", "to", "the", "registry", ".", "As", "all", "objecst", "within", "a", "the", "project", "maintain", "a", "reference", "to", "this", "registry", "they", "can", "immediately", "query", "for", "newly", "created", "items", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/registry.rb#L167-L173
18,656
rayh/xcoder
lib/xcode/workspace.rb
Xcode.Workspace.project
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
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
[ "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" ]
Return the names project. Raises an error if no projects match the specified name. @note if two projects match names, the first matching scheme is returned. @param [String] name of the specific scheme @return [Project] the specific project that matches the name specified
[ "Return", "the", "names", "project", ".", "Raises", "an", "error", "if", "no", "projects", "match", "the", "specified", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/workspace.rb#L63-L68
18,657
rayh/xcoder
lib/xcode/target_dependency.rb
Xcode.TargetDependency.create_dependency_on
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
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
[ "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" ]
Establish the Target that this Target Dependency is dependent. @param [Target] target the target this dependency is based on
[ "Establish", "the", "Target", "that", "this", "Target", "Dependency", "is", "dependent", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/target_dependency.rb#L43-L53
18,658
rayh/xcoder
lib/xcode/configuration.rb
Xcode.Configuration.info_plist
def info_plist info = Xcode::InfoPlist.new(self, info_plist_location) yield info if block_given? info.save info end
ruby
def info_plist info = Xcode::InfoPlist.new(self, info_plist_location) yield info if block_given? info.save info end
[ "def", "info_plist", "info", "=", "Xcode", "::", "InfoPlist", ".", "new", "(", "self", ",", "info_plist_location", ")", "yield", "info", "if", "block_given?", "info", ".", "save", "info", "end" ]
Opens the info plist associated with the configuration and allows you to edit the configuration. @example Editing the configuration config = Xcode.project('MyProject.xcodeproj').target('Application').config('Debug') config.info_plist do |plist| puts plist.version # => 1.0 plist.version = 1.1 marketing_version = 12.1 end @see InfoPlist
[ "Opens", "the", "info", "plist", "associated", "with", "the", "configuration", "and", "allows", "you", "to", "edit", "the", "configuration", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration.rb#L329-L334
18,659
rayh/xcoder
lib/xcode/configuration.rb
Xcode.Configuration.get
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
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
[ "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" ]
Retrieve the configuration value for the given name @param [String] name of the configuration settings to return @return [String,Array,Hash] the value stored for the specified configuration
[ "Retrieve", "the", "configuration", "value", "for", "the", "given", "name" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration.rb#L347-L355
18,660
rayh/xcoder
lib/xcode/configuration.rb
Xcode.Configuration.set
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
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
[ "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" ]
Set the configuration value for the given name @param [String] name of the the configuration setting @param [String,Array,Hash] value the value to store for the specific setting
[ "Set", "the", "configuration", "value", "for", "the", "given", "name" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration.rb#L363-L371
18,661
rayh/xcoder
lib/xcode/configuration.rb
Xcode.Configuration.append
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
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
[ "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" ]
Append a value to the the configuration value for the given name @param [String] name of the the configuration setting @param [String,Array,Hash] value the value to store for the specific setting
[ "Append", "a", "value", "to", "the", "the", "configuration", "value", "for", "the", "given", "name" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/configuration.rb#L379-L412
18,662
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.group
def group(name) groups.find_all {|group| group.name == name or group.path == name } end
ruby
def group(name) groups.find_all {|group| group.name == name or group.path == name } end
[ "def", "group", "(", "name", ")", "groups", ".", "find_all", "{", "|", "group", "|", "group", ".", "name", "==", "name", "or", "group", ".", "path", "==", "name", "}", "end" ]
Find all the child groups that have a name that matches the specified name. @param [String] name of the group that you are looking to return. @return [Array<Group>] the groups with the same matching name. This could be no groups, one group, or multiple groups.
[ "Find", "all", "the", "child", "groups", "that", "have", "a", "name", "that", "matches", "the", "specified", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L66-L68
18,663
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.file
def file(name) files.find_all {|file| file.name == name or file.path == name } end
ruby
def file(name) files.find_all {|file| file.name == name or file.path == name } end
[ "def", "file", "(", "name", ")", "files", ".", "find_all", "{", "|", "file", "|", "file", ".", "name", "==", "name", "or", "file", ".", "path", "==", "name", "}", "end" ]
Find all the files that have have a name that matches the specified name. @param [String] name of the file that you are looking to return. @return [Array<FileReference>] the files with the same mathching name. This could be no files, one file, or multiple files.
[ "Find", "all", "the", "files", "that", "have", "have", "a", "name", "that", "matches", "the", "specified", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L87-L89
18,664
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.exists?
def exists?(name) children.find_all do |child| child.name ? (child.name == name) : (File.basename(child.path) == name) end end
ruby
def exists?(name) children.find_all do |child| child.name ? (child.name == name) : (File.basename(child.path) == name) end end
[ "def", "exists?", "(", "name", ")", "children", ".", "find_all", "do", "|", "child", "|", "child", ".", "name", "?", "(", "child", ".", "name", "==", "name", ")", ":", "(", "File", ".", "basename", "(", "child", ".", "path", ")", "==", "name", ")", "end", "end" ]
Check whether a file or group is contained within this group that has a name that matches the one specified @param [String] name of the group attempting to be found. @return [Array<Resource>] resource with the name that matches; empty array if no matches were found.
[ "Check", "whether", "a", "file", "or", "group", "is", "contained", "within", "this", "group", "that", "has", "a", "name", "that", "matches", "the", "one", "specified" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L100-L104
18,665
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.create_group
def create_group(name) new_group = create_child_object Group.logical_group(name) new_group.supergroup = self new_group end
ruby
def create_group(name) new_group = create_child_object Group.logical_group(name) new_group.supergroup = self new_group end
[ "def", "create_group", "(", "name", ")", "new_group", "=", "create_child_object", "Group", ".", "logical_group", "(", "name", ")", "new_group", ".", "supergroup", "=", "self", "new_group", "end" ]
Adds a group as a child to current group with the given name. @note A group may be added that has the same name as another group as they are distinguished by a unique identifier and not by name. @param [String] name of the group that you want to add as a child group of the specified group. @return [Group] the created group
[ "Adds", "a", "group", "as", "a", "child", "to", "current", "group", "with", "the", "given", "name", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L117-L121
18,666
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.create_file
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
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
[ "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" ]
Add a file to the specified group. Currently the file creation requires the path to the physical file. @example creating a file with just a path project.main_group.create_file 'AppDelegate.m' @example creating a file with a name and path project.main_group.create_file 'name' => 'AppDelegate.m', 'path' => 'Subfolder/AppDelegate.m' @param [String,Hash] path to the file that is being added or a hash that contains the values would be merged with the default values. @return [FileReference] the file created.
[ "Add", "a", "file", "to", "the", "specified", "group", ".", "Currently", "the", "file", "creation", "requires", "the", "path", "to", "the", "physical", "file", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L140-L159
18,667
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.remove!
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
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
[ "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" ]
Remove the resource from the registry. @note all children objects of this group are removed as well.
[ "Remove", "the", "resource", "from", "the", "registry", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L240-L252
18,668
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.find_or_create_child_object
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
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
[ "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" ]
This method is used internally to find the specified object or add the object as a child of this group. @param [Hash] child_properties the hash of resource to add as a child object of this group if it does not already exist as a child. @return [Resource] returns the resource that was added a child
[ "This", "method", "is", "used", "internally", "to", "find", "the", "specified", "object", "or", "add", "the", "object", "as", "a", "child", "of", "this", "group", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L278-L282
18,669
rayh/xcoder
lib/xcode/group.rb
Xcode.Group.remove_child_object
def remove_child_object(identifier) found_child = children.find {|child| child.identifier == identifier } @properties['children'].delete identifier save! found_child end
ruby
def remove_child_object(identifier) found_child = children.find {|child| child.identifier == identifier } @properties['children'].delete identifier save! found_child end
[ "def", "remove_child_object", "(", "identifier", ")", "found_child", "=", "children", ".", "find", "{", "|", "child", "|", "child", ".", "identifier", "==", "identifier", "}", "@properties", "[", "'children'", "]", ".", "delete", "identifier", "save!", "found_child", "end" ]
This method is used internally to remove a child object from this and the registry. @param [String] identifier of the child object to be removed. @return [Resource] the removed child resource
[ "This", "method", "is", "used", "internally", "to", "remove", "a", "child", "object", "from", "this", "and", "the", "registry", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/group.rb#L290-L295
18,670
rayh/xcoder
lib/xcoder/rake_task.rb
Xcode.RakeTask.define_per_project_scheme_builder_tasks
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
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
[ "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" ]
Generate all the Builder Tasks for all the matrix of all the Projects and Schemes
[ "Generate", "all", "the", "Builder", "Tasks", "for", "all", "the", "matrix", "of", "all", "the", "Projects", "and", "Schemes" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcoder/rake_task.rb#L142-L159
18,671
rayh/xcoder
lib/xcoder/rake_task.rb
Xcode.RakeTask.define_per_project_config_builder_tasks
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
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
[ "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" ]
Generate all the Builder Tasks for all the matrix of all the Projects, Targets, and Configs
[ "Generate", "all", "the", "Builder", "Tasks", "for", "all", "the", "matrix", "of", "all", "the", "Projects", "Targets", "and", "Configs" ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcoder/rake_task.rb#L165-L187
18,672
rayh/xcoder
lib/xcode/project_reference.rb
Xcode.ProjectReference.group
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
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
[ "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" ]
Returns the group specified. If any part of the group does not exist along the path the group is created. Also paths can be specified to make the traversing of the groups easier. @note this will attempt to find the paths specified, if it fails to find them it will create one and then continue traversing. @example Traverse a path through the various sub-groups. project.group('Vendor/MyCode/Support Files') # is equivalent to ... project.group('Vendor').first.group('MyCode').first.group('Supporting Files') @note this path functionality current is only exercised from the project level all groups will treat the path division `/` as simply a character. @param [String] name the group name to find/create @return [Group] the group with the specified name.
[ "Returns", "the", "group", "specified", ".", "If", "any", "part", "of", "the", "group", "does", "not", "exist", "along", "the", "path", "the", "group", "is", "created", ".", "Also", "paths", "can", "be", "specified", "to", "make", "the", "traversing", "of", "the", "groups", "easier", "." ]
0affa3e8f0a5c138ea25c004341d62b23c6b6711
https://github.com/rayh/xcoder/blob/0affa3e8f0a5c138ea25c004341d62b23c6b6711/lib/xcode/project_reference.rb#L26-L50
18,673
pusher/cide
lib/cide/runner.rb
CIDE.Runner.run!
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
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
[ "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" ]
!!!! Don't call run twice !!!!
[ "!!!!", "Don", "t", "call", "run", "twice", "!!!!" ]
2827b1d283d7ed3f0db81b7e0428ce2de5a98555
https://github.com/pusher/cide/blob/2827b1d283d7ed3f0db81b7e0428ce2de5a98555/lib/cide/runner.rb#L29-L54
18,674
StuartApp/h3_ruby
lib/h3/regions.rb
H3.Regions.max_polyfill_size
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
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
[ "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" ]
Derive the maximum number of H3 indexes that could be returned from the input. @param [String, Array<Array<Array<Float>>>] geo_polygon Either a GeoJSON string or a coordinates nested array. @param [Integer] resolution Resolution. @example Derive maximum number of hexagons for given GeoJSON document. geo_json = "{\"type\":\"Polygon\",\"coordinates\":[[[-1.735839843749998,52.24630137198303], [-1.8923950195312498,52.05249047600099],[-1.56829833984375,51.891749018068246], [-1.27716064453125,51.91208502557545],[-1.19476318359375,52.032218104145294], [-1.24420166015625,52.19413974159753],[-1.5902709960937498,52.24125614966341], [-1.7358398437499998,52.24630137198303]],[[-1.58203125,52.12590076522272], [-1.476287841796875,52.12590076522272],[-1.46392822265625,52.075285904832334], [-1.58203125,52.06937709602395],[-1.58203125,52.12590076522272]], [[-1.4556884765625,52.01531743663362],[-1.483154296875,51.97642166216334], [-1.3677978515625,51.96626938051444],[-1.3568115234375,52.0102459910103], [-1.4556884765625,52.01531743663362]]]}" H3.max_polyfill_size(geo_json, 9) 33391 @example Derive maximum number of hexagons for a nested array of coordinates. coordinates = [ [ [52.24630137198303, -1.7358398437499998], [52.05249047600099, -1.8923950195312498], [51.891749018068246, -1.56829833984375], [51.91208502557545, -1.27716064453125], [52.032218104145294, -1.19476318359375], [52.19413974159753, -1.24420166015625], [52.24125614966341, -1.5902709960937498], [52.24630137198303, -1.7358398437499998] ], [ [52.12590076522272, -1.58203125], [52.12590076522272, -1.476287841796875], [52.075285904832334, -1.46392822265625], [52.06937709602395, -1.58203125], [52.12590076522272, -1.58203125] ], [ [52.01531743663362, -1.4556884765625], [51.97642166216334, -1.483154296875], [51.96626938051444, -1.3677978515625], [52.0102459910103, -1.3568115234375], [52.01531743663362, -1.4556884765625] ] ] H3.max_polyfill_size(coordinates, 9) 33391 @return [Integer] Maximum number of hexagons needed to polyfill given area.
[ "Derive", "the", "maximum", "number", "of", "H3", "indexes", "that", "could", "be", "returned", "from", "the", "input", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/regions.rb#L51-L54
18,675
StuartApp/h3_ruby
lib/h3/regions.rb
H3.Regions.polyfill
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
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
[ "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" ]
Derive a list of H3 indexes that fall within a given geo polygon structure. @param [String, Array<Array<Array<Float>>>] geo_polygon Either a GeoJSON string or a coordinates nested array. @param [Integer] resolution Resolution. @example Derive hexagons for given GeoJSON document. geo_json = "{\"type\":\"Polygon\",\"coordinates\":[[[-1.735839843799998,52.24630137198303], [-1.8923950195312498,52.05249047600099],[-1.56829833984375,51.891749018068246], [-1.27716064453125,51.91208502557545],[-1.19476318359375,52.032218104145294], [-1.24420166015625,52.19413974159753],[-1.5902709960937498,52.24125614966341], [-1.7358398437499998,52.24630137198303]],[[-1.58203125,52.12590076522272], [-1.476287841796875,52.12590076522272],[-1.46392822265625,52.075285904832334], [-1.58203125,52.06937709602395],[-1.58203125,52.12590076522272]], [[-1.4556884765625,52.01531743663362],[-1.483154296875,51.97642166216334], [-1.3677978515625,51.96626938051444],[-1.3568115234375,52.0102459910103], [-1.4556884765625,52.01531743663362]]]}" H3.polyfill(geo_json, 5) [ 599424968551301119, 599424888020664319, 599424970698784767, 599424964256333823, 599424969625042943, 599425001837297663, 599425000763555839 ] @example Derive hexagons for a nested array of coordinates. coordinates = [ [ [52.24630137198303, -1.7358398437499998], [52.05249047600099, -1.8923950195312498], [51.891749018068246, -1.56829833984375], [51.91208502557545, -1.27716064453125], [52.032218104145294, -1.19476318359375], [52.19413974159753, -1.24420166015625], [52.24125614966341, -1.5902709960937498], [52.24630137198303, -1.7358398437499998] ], [ [52.12590076522272, -1.58203125], [52.12590076522272, -1.476287841796875], [52.075285904832334, -1.46392822265625], [52.06937709602395, -1.58203125], [52.12590076522272, -1.58203125] ], [ [52.01531743663362, -1.4556884765625], [51.97642166216334, -1.483154296875], [51.96626938051444, -1.3677978515625], [52.0102459910103, -1.3568115234375], [52.01531743663362, -1.4556884765625] ] ] H3.polyfill(coordinates, 5) [ 599424968551301119, 599424888020664319, 599424970698784767, 599424964256333823, 599424969625042943, 599425001837297663, 599425000763555839 ] @return [Array<Integer>] Hexagons needed to polyfill given area.
[ "Derive", "a", "list", "of", "H3", "indexes", "that", "fall", "within", "a", "given", "geo", "polygon", "structure", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/regions.rb#L105-L111
18,676
StuartApp/h3_ruby
lib/h3/regions.rb
H3.Regions.h3_set_to_linked_geo
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
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
[ "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" ]
Derive a nested array of coordinates from a list of H3 indexes. @param [Array<Integer>] h3_indexes A list of H3 indexes. @example Get a set of coordinates from a given list of H3 indexes. h3_indexes = [ 599424968551301119, 599424888020664319, 599424970698784767, 599424964256333823, 599424969625042943, 599425001837297663, 599425000763555839 ] H3.h3_set_to_linked_geo(h3_indexes) [ [ [52.24425364171531, -1.6470570189756442], [52.19515282473624, -1.7508281227260887], [52.10973325363767, -1.7265910686763437], [52.06042870859474, -1.8301115887419024], [51.97490199314513, -1.8057974545517919], [51.9387204737266, -1.6783497689296265], [51.853128001893175, -1.654344796003053], [51.81682604752331, -1.5274195136674955], [51.866019925789956, -1.424329996292339], [51.829502535462176, -1.2977583914075301], [51.87843896218677, -1.1946402363628545], [51.96394676922824, -1.21787542551618], [52.01267958543637, -1.1145114691876956], [52.09808058649905, -1.1376655003242908], [52.134791926560325, -1.26456988729442], [52.22012854584846, -1.2880298658365215], [52.25672060485973, -1.4154623025177386], [52.20787927927604, -1.5192658757247421] ] ] @return [Array<Array<Array<Float>>>] Nested array of coordinates.
[ "Derive", "a", "nested", "array", "of", "coordinates", "from", "a", "list", "of", "H3", "indexes", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/regions.rb#L139-L147
18,677
StuartApp/h3_ruby
lib/h3/indexing.rb
H3.Indexing.geo_to_h3
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
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
[ "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" ]
Derive H3 index for the given set of coordinates. @param [Array<Integer>] coords A coordinate pair. @param [Integer] resolution The desired resolution of the H3 index. @example Derive the H3 index for the given coordinates. H3.geo_to_h3([52.24630137198303, -1.7358398437499998], 9) 617439284584775679 @raise [ArgumentError] If coordinates are invalid. @return [Integer] H3 index.
[ "Derive", "H3", "index", "for", "the", "given", "set", "of", "coordinates", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/indexing.rb#L23-L36
18,678
StuartApp/h3_ruby
lib/h3/indexing.rb
H3.Indexing.h3_to_geo
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
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
[ "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" ]
Derive coordinates for a given H3 index. The coordinates map to the centre of the hexagon at the given index. @param [Integer] h3_index A valid H3 index. @example Derive the central coordinates for the given H3 index. H3.h3_to_geo(617439284584775679) [52.245519061399506, -1.7363137757391423] @return [Array<Integer>] A coordinate pair.
[ "Derive", "coordinates", "for", "a", "given", "H3", "index", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/indexing.rb#L49-L53
18,679
StuartApp/h3_ruby
lib/h3/indexing.rb
H3.Indexing.h3_to_geo_boundary
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
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
[ "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" ]
Derive the geographical boundary as coordinates for a given H3 index. This will be a set of 6 coordinate pairs matching the vertexes of the hexagon represented by the given H3 index. If the H3 index is a pentagon, there will be only 5 coordinate pairs returned. @param [Integer] h3_index A valid H3 index. @example Derive the geographical boundary for the given H3 index. H3.h3_to_geo_boundary(617439284584775679) [ [52.247260929171055, -1.736809158397472], [52.24625850761068, -1.7389279144996015], [52.244516619273476, -1.7384324668792375], [52.243777169245725, -1.7358184256304658], [52.24477956752282, -1.7336997597088104], [52.246521439109415, -1.7341950448552204] ] @return [Array<Array<Integer>>] An array of six coordinate pairs.
[ "Derive", "the", "geographical", "boundary", "as", "coordinates", "for", "a", "given", "H3", "index", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/indexing.rb#L73-L79
18,680
StuartApp/h3_ruby
lib/h3/unidirectional_edges.rb
H3.UnidirectionalEdges.h3_indexes_from_unidirectional_edge
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
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
[ "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" ]
Derive origin and destination H3 indexes from edge. Returned in the form [origin, destination] @param [Integer] edge H3 edge index @example Get origin and destination indexes from edge H3.h3_indexes_from_unidirectional_edge(1266218516299644927) [617700169958293503, 617700169961177087] @return [Array<Integer>] H3 index array.
[ "Derive", "origin", "and", "destination", "H3", "indexes", "from", "edge", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/unidirectional_edges.rb#L100-L105
18,681
StuartApp/h3_ruby
lib/h3/unidirectional_edges.rb
H3.UnidirectionalEdges.h3_unidirectional_edges_from_hexagon
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
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
[ "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" ]
Derive unidirectional edges for a H3 index. @param [Integer] origin H3 index @example Get unidirectional indexes from hexagon H3.h3_unidirectional_edges_from_hexagon(612933930963697663) [ 1261452277305049087, 1333509871342977023, 1405567465380904959, 1477625059418832895, 1549682653456760831, 1621740247494688767 ] @return [Array<Integer>] H3 index array.
[ "Derive", "unidirectional", "edges", "for", "a", "H3", "index", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/unidirectional_edges.rb#L119-L124
18,682
StuartApp/h3_ruby
lib/h3/unidirectional_edges.rb
H3.UnidirectionalEdges.h3_unidirectional_edge_boundary
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
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
[ "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" ]
Derive coordinates for edge boundary. @param [Integer] edge H3 edge index @example H3.h3_unidirectional_edge_boundary(612933930963697663) [ [68.92995788193981, 31.831280499087402], [69.39359648991828, 62.345344956509784], [76.163042830191, 94.14309010184775], [87.36469532319619, 145.5581976913368], [81.27137179020497, -34.75841798028461], [73.31022368544393, 0.32561035194326043] ] @return [Array<Array<Float>>] Edge boundary coordinates for a hexagon
[ "Derive", "coordinates", "for", "edge", "boundary", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/unidirectional_edges.rb#L139-L145
18,683
StuartApp/h3_ruby
lib/h3/traversal.rb
H3.Traversal.hex_ring
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
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
[ "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" ]
Derives the hollow hexagonal ring centered at origin with sides of length k. An error is raised when one of the indexes returned is a pentagon or is in the pentagon distortion area. @param [Integer] origin Origin H3 index. @param [Integer] k K distance. @example Derive the hex ring for the H3 index at k = 1 H3.hex_ring(617700169983721471, 1) [ 617700170044014591, 617700170047946751, 617700169984245759, 617700169982672895, 617700169983983615, 617700170044276735 ] @raise [ArgumentError] Raised if the hex ring contains a pentagon. @return [Array<Integer>] Array of H3 indexes within the hex ring.
[ "Derives", "the", "hollow", "hexagonal", "ring", "centered", "at", "origin", "with", "sides", "of", "length", "k", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/traversal.rb#L136-L142
18,684
StuartApp/h3_ruby
lib/h3/traversal.rb
H3.Traversal.hex_ranges
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
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
[ "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" ]
Derives H3 indexes within k distance for each H3 index in the set. @param [Array<Integer>] h3_set Set of H3 indexes @param [Integer] k K distance. @param [Boolean] grouped Whether to group the output. Default true. @example Derive the hex ranges for a given H3 set with k of 0. H3.hex_ranges([617700169983721471, 617700169982672895], 1) { 617700169983721471 => [ [617700169983721471], [ 617700170047946751, 617700169984245759, 617700169982672895, 617700169983983615, 617700170044276735, 617700170044014591 ] ], 617700169982672895 = > [ [617700169982672895], [ 617700169984245759, 617700169983197183, 617700169983459327, 617700169982935039, 617700169983983615, 617700169983721471 ] ] } @example Derive the hex ranges for a given H3 set with k of 0 ungrouped. H3.hex_ranges([617700169983721471, 617700169982672895], 1, grouped: false) [ 617700169983721471, 617700170047946751, 617700169984245759, 617700169982672895, 617700169983983615, 617700170044276735, 617700170044014591, 617700169982672895, 617700169984245759, 617700169983197183, 617700169983459327, 617700169982935039, 617700169983983615, 617700169983721471 ] @raise [ArgumentError] Raised if any of the ranges contains a pentagon. @see #hex_range @return [Hash] Hash of H3 index keys, with array values grouped by k-ring.
[ "Derives", "H3", "indexes", "within", "k", "distance", "for", "each", "H3", "index", "in", "the", "set", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/traversal.rb#L199-L207
18,685
StuartApp/h3_ruby
lib/h3/traversal.rb
H3.Traversal.k_ring_distances
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
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
[ "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" ]
Derives the k-ring for the given origin at k distance, sub-grouped by distance. @param [Integer] origin Origin H3 index. @param [Integer] k K distance. @example Derive k-ring at distance 2 H3.k_ring_distances(617700169983721471, 2) { 0 => [617700169983721471], 1 = >[ 617700170047946751, 617700169984245759, 617700169982672895, 617700169983983615, 617700170044276735, 617700170044014591 ], 2 => [ 617700170048995327, 617700170047684607, 617700170048471039, 617700169988177919, 617700169983197183, 617700169983459327, 617700169982935039, 617700175096053759, 617700175097102335, 617700170043752447, 617700170043490303, 617700170045063167 ] } @return [Hash] Hash of k-ring distances grouped by distance.
[ "Derives", "the", "k", "-", "ring", "for", "the", "given", "origin", "at", "k", "distance", "sub", "-", "grouped", "by", "distance", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/traversal.rb#L270-L282
18,686
StuartApp/h3_ruby
lib/h3/inspection.rb
H3.Inspection.h3_to_string
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
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
[ "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" ]
Derives the hexadecimal string representation for a given H3 index. @param [Integer] h3_index A valid H3 index. @example Derive the given hexadecimal form for the H3 index H3.h3_to_string(617700169958293503) "89283470dcbffff" @return [String] H3 index in hexadecimal form.
[ "Derives", "the", "hexadecimal", "string", "representation", "for", "a", "given", "H3", "index", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/inspection.rb#L99-L103
18,687
StuartApp/h3_ruby
lib/h3/geo_json.rb
H3.GeoJSON.geo_json_to_coordinates
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
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
[ "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" ]
Convert a GeoJSON document to a nested array of coordinates. @param [String] input The GeoJSON document. This can be a feature collection, feature, or polygon. If a feature collection is provided, the first feature is used. @example Convert a GeoJSON document of Banbury to a set of nested coordinates. document = "{\"type\":\"Polygon\",\"coordinates\":[ [ [-1.7358398437499998,52.24630137198303], [-1.8923950195312498,52.05249047600099], [-1.56829833984375,51.891749018068246], [-1.27716064453125,51.91208502557545], [-1.19476318359375,52.032218104145294], [-1.24420166015625,52.19413974159753], [-1.5902709960937498,52.24125614966341], [-1.7358398437499998,52.24630137198303] ], [ [-1.58203125,52.12590076522272], [-1.476287841796875,52.12590076522272], [-1.46392822265625,52.075285904832334], [-1.58203125,52.06937709602395], [-1.58203125,52.12590076522272] ], [ [-1.4556884765625,52.01531743663362], [-1.483154296875,51.97642166216334], [-1.3677978515625,51.96626938051444], [-1.3568115234375,52.0102459910103], [-1.4556884765625,52.01531743663362] ] ]}" H3.geo_json_to_coordinates(document) [ [ [52.24630137198303, -1.7358398437499998], [52.05249047600099, -1.8923950195312498], [51.891749018068246, -1.56829833984375], [51.91208502557545, -1.27716064453125], [52.032218104145294, -1.19476318359375], [52.19413974159753, -1.24420166015625], [52.24125614966341, -1.5902709960937498], [52.24630137198303, -1.7358398437499998] ], [ [52.12590076522272, -1.58203125], [52.12590076522272, -1.476287841796875], [52.075285904832334, -1.46392822265625], [52.06937709602395, -1.58203125], [52.12590076522272, -1.58203125] ], [ [52.01531743663362, -1.4556884765625], [51.97642166216334, -1.483154296875], [51.96626938051444, -1.3677978515625], [52.0102459910103, -1.3568115234375], [52.01531743663362, -1.4556884765625] ] ] @raise [ArgumentError] Failed to parse the GeoJSON document. @return [Array<Array<Array>>] Nested array of coordinates.
[ "Convert", "a", "GeoJSON", "document", "to", "a", "nested", "array", "of", "coordinates", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/geo_json.rb#L78-L84
18,688
StuartApp/h3_ruby
lib/h3/geo_json.rb
H3.GeoJSON.coordinates_to_geo_json
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
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
[ "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" ]
Convert a nested array of coordinates to a GeoJSON document @param [Array<Array<Array>>] coordinates Nested array of coordinates. @example Convert a set of nested coordinates of Banbury to a GeoJSON document. coordinates = [ [ [52.24630137198303, -1.7358398437499998], [52.05249047600099, -1.8923950195312498], [51.891749018068246, -1.56829833984375], [51.91208502557545, -1.27716064453125], [52.032218104145294, -1.19476318359375], [52.19413974159753, -1.24420166015625], [52.24125614966341, -1.5902709960937498], [52.24630137198303, -1.7358398437499998] ], [ [52.12590076522272, -1.58203125], [52.12590076522272, -1.476287841796875], [52.075285904832334, -1.46392822265625], [52.06937709602395, -1.58203125], [52.12590076522272, -1.58203125] ], [ [52.01531743663362, -1.4556884765625], [51.97642166216334, -1.483154296875], [51.96626938051444, -1.3677978515625], [52.0102459910103, -1.3568115234375], [52.01531743663362, -1.4556884765625] ] ] H3.coordinates_to_geo_json(coordinates) "{\"type\":\"Polygon\",\"coordinates\":[ [ [-1.7358398437499998,52.24630137198303], [-1.8923950195312498,52.05249047600099], [-1.56829833984375,51.891749018068246], [-1.27716064453125,51.91208502557545], [-1.19476318359375,52.032218104145294], [-1.24420166015625,52.19413974159753], [-1.5902709960937498,52.24125614966341], [-1.7358398437499998,52.24630137198303] ], [ [-1.58203125,52.12590076522272], [-1.476287841796875,52.12590076522272], [-1.46392822265625,52.075285904832334], [-1.58203125,52.06937709602395], [-1.58203125,52.12590076522272] ], [ [-1.4556884765625,52.01531743663362], [-1.483154296875,51.97642166216334], [-1.3677978515625,51.96626938051444], [-1.3568115234375,52.0102459910103], [-1.4556884765625,52.01531743663362] ] ]}" @raise [ArgumentError] Failed to parse the given coordinates. @return [String] GeoJSON document.
[ "Convert", "a", "nested", "array", "of", "coordinates", "to", "a", "GeoJSON", "document" ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/geo_json.rb#L132-L144
18,689
StuartApp/h3_ruby
lib/h3/hierarchy.rb
H3.Hierarchy.h3_to_children
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
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
[ "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" ]
Derive child hexagons contained within the hexagon at the given H3 index. @param [Integer] h3_index A valid H3 index. @param [Integer] child_resolution The desired resolution of hexagons returned. @example Find the child hexagons for a H3 index. H3.h3_to_children(613196570357137407, 9) [ 617700169982672895, 617700169982935039, 617700169983197183, 617700169983459327, 617700169983721471, 617700169983983615, 617700169984245759 ] @return [Array<Integer>] H3 indexes of child hexagons.
[ "Derive", "child", "hexagons", "contained", "within", "the", "hexagon", "at", "the", "given", "H3", "index", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/hierarchy.rb#L49-L54
18,690
StuartApp/h3_ruby
lib/h3/hierarchy.rb
H3.Hierarchy.max_uncompact_size
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
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
[ "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" ]
Find the maximum uncompacted size of the given set of H3 indexes. @param [Array<Integer>] compacted_set An array of valid H3 indexes. @param [Integer] resolution The desired resolution to uncompact to. @example Find the maximum uncompacted size of the given set. h3_set = [ 617700440093229055, 617700440092704767, 617700440100569087, 617700440013012991, 617700440013275135, 617700440092180479, 617700440091656191, 617700440092966911, 617700440100831231, 617700440100044799, 617700440101617663, 617700440081956863, 613196840447246335 ] H3.max_uncompact_size(h3_set, 10) 133 @raise [ArgumentError] Given resolution is invalid for h3_set. @return [Integer] Maximum size of uncompacted set.
[ "Find", "the", "maximum", "uncompacted", "size", "of", "the", "given", "set", "of", "H3", "indexes", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/hierarchy.rb#L74-L79
18,691
StuartApp/h3_ruby
lib/h3/hierarchy.rb
H3.Hierarchy.compact
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
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
[ "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" ]
Compact a set of H3 indexes as best as possible. In the case where the set cannot be compacted, the set is returned unchanged. @param [Array<Integer>] h3_set An array of valid H3 indexes. @example Compact the given set. h3_set = [ 617700440073043967, 617700440072781823, 617700440073568255, 617700440093229055, 617700440092704767, 617700440100569087, 617700440074092543, 617700440073830399, 617700440074354687, 617700440073306111, 617700440013012991, 617700440013275135, 617700440092180479, 617700440091656191, 617700440092966911, 617700440100831231, 617700440100044799, 617700440101617663, 617700440081956863 ] H3.compact(h3_set) [ 617700440093229055, 617700440092704767, 617700440100569087, 617700440013012991, 617700440013275135, 617700440092180479, 617700440091656191, 617700440092966911, 617700440100831231, 617700440100044799, 617700440101617663, 617700440081956863, 613196840447246335 ] @raise [RuntimeError] Couldn't attempt to compact given H3 indexes. @return [Array<Integer>] Compacted set of H3 indexes.
[ "Compact", "a", "set", "of", "H3", "indexes", "as", "best", "as", "possible", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/hierarchy.rb#L106-L113
18,692
StuartApp/h3_ruby
lib/h3/hierarchy.rb
H3.Hierarchy.uncompact
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
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
[ "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" ]
Uncompact a set of H3 indexes to the given resolution. @param [Array<Integer>] compacted_set An array of valid H3 indexes. @param [Integer] resolution The desired resolution to uncompact to. @example Compact the given set. h3_set = [ 617700440093229055, 617700440092704767, 617700440100569087, 617700440013012991, 617700440013275135, 617700440092180479, 617700440091656191, 617700440092966911, 617700440100831231, 617700440100044799, 617700440101617663, 617700440081956863, 613196840447246335 ] H3.uncompact(h3_set) [ 617700440093229055, 617700440092704767, 617700440100569087, 617700440013012991, 617700440013275135, 617700440092180479, 617700440091656191, 617700440092966911, 617700440100831231, 617700440100044799, 617700440101617663, 617700440081956863, 617700440072781823, 617700440073043967, 617700440073306111, 617700440073568255, 617700440073830399, 617700440074092543, 617700440074354687 ] @raise [RuntimeError] Couldn't attempt to umcompact H3 indexes. @return [Array<Integer>] Uncompacted set of H3 indexes.
[ "Uncompact", "a", "set", "of", "H3", "indexes", "to", "the", "given", "resolution", "." ]
f32e91fe1d4d1b1428e940941cb51f0ea260c46d
https://github.com/StuartApp/h3_ruby/blob/f32e91fe1d4d1b1428e940941cb51f0ea260c46d/lib/h3/hierarchy.rb#L139-L148
18,693
piotrmurach/necromancer
lib/necromancer/conversion_target.rb
Necromancer.ConversionTarget.to
def to(target, options = {}) conversion = conversions[source || detect(object, false), detect(target)] conversion.call(object, options) end
ruby
def to(target, options = {}) conversion = conversions[source || detect(object, false), detect(target)] conversion.call(object, options) end
[ "def", "to", "(", "target", ",", "options", "=", "{", "}", ")", "conversion", "=", "conversions", "[", "source", "||", "detect", "(", "object", ",", "false", ")", ",", "detect", "(", "target", ")", "]", "conversion", ".", "call", "(", "object", ",", "options", ")", "end" ]
Runs a given conversion @example converter.convert('1').to(:numeric) # => 1 @example converter.convert('1') >> Integer # => 1 @return [Object] the converted target type @api public
[ "Runs", "a", "given", "conversion" ]
8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e
https://github.com/piotrmurach/necromancer/blob/8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e/lib/necromancer/conversion_target.rb#L59-L62
18,694
piotrmurach/necromancer
lib/necromancer/conversion_target.rb
Necromancer.ConversionTarget.detect
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
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
[ "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" ]
Detect object type and coerce into known key type @param [Object] object @api private
[ "Detect", "object", "type", "and", "coerce", "into", "known", "key", "type" ]
8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e
https://github.com/piotrmurach/necromancer/blob/8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e/lib/necromancer/conversion_target.rb#L79-L91
18,695
piotrmurach/necromancer
lib/necromancer/conversions.rb
Necromancer.Conversions.load
def load ArrayConverters.load(self) BooleanConverters.load(self) DateTimeConverters.load(self) NumericConverters.load(self) RangeConverters.load(self) end
ruby
def load ArrayConverters.load(self) BooleanConverters.load(self) DateTimeConverters.load(self) NumericConverters.load(self) RangeConverters.load(self) end
[ "def", "load", "ArrayConverters", ".", "load", "(", "self", ")", "BooleanConverters", ".", "load", "(", "self", ")", "DateTimeConverters", ".", "load", "(", "self", ")", "NumericConverters", ".", "load", "(", "self", ")", "RangeConverters", ".", "load", "(", "self", ")", "end" ]
Creates a new conversions map @example conversion = Necromancer::Conversions.new @api public Load converters @api private
[ "Creates", "a", "new", "conversions", "map" ]
8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e
https://github.com/piotrmurach/necromancer/blob/8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e/lib/necromancer/conversions.rb#L33-L39
18,696
piotrmurach/necromancer
lib/necromancer/conversions.rb
Necromancer.Conversions.register
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
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
[ "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" ]
Register a converter @example with simple object conversions.register NullConverter.new(:array, :array) @example with block conversions.register do |c| c.source = :array c.target = :array c.convert = -> { |val, options| val } end @api public
[ "Register", "a", "converter" ]
8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e
https://github.com/piotrmurach/necromancer/blob/8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e/lib/necromancer/conversions.rb#L74-L81
18,697
piotrmurach/necromancer
lib/necromancer/conversions.rb
Necromancer.Conversions.add_config
def add_config(converter, config) converter.instance_exec(:"@config") do |var| instance_variable_set(var, config) end converter end
ruby
def add_config(converter, config) converter.instance_exec(:"@config") do |var| instance_variable_set(var, config) end converter end
[ "def", "add_config", "(", "converter", ",", "config", ")", "converter", ".", "instance_exec", "(", ":\"", "\"", ")", "do", "|", "var", "|", "instance_variable_set", "(", "var", ",", "config", ")", "end", "converter", "end" ]
Inject config into converter @api private
[ "Inject", "config", "into", "converter" ]
8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e
https://github.com/piotrmurach/necromancer/blob/8d18fbfc4b9b3ed569aeda74c4b76eaaa6f88e8e/lib/necromancer/conversions.rb#L112-L117
18,698
molybdenum-99/tlaw
lib/tlaw/data_table.rb
TLAW.DataTable.[]
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
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
[ "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" ]
Allows access to one column or row. @overload [](index) Returns one row from a DataTable. @param index [Integer] Row number @return [Hash] Row as a hash @overload [](column_name) Returns one column from a DataTable. @param column_name [String] Name of column @return [Array] Column as an array of all values in it
[ "Allows", "access", "to", "one", "column", "or", "row", "." ]
922ecb7994b91aafda56582d7a69e230d14a19db
https://github.com/molybdenum-99/tlaw/blob/922ecb7994b91aafda56582d7a69e230d14a19db/lib/tlaw/data_table.rb#L74-L85
18,699
molybdenum-99/tlaw
lib/tlaw/data_table.rb
TLAW.DataTable.columns
def columns(*names) names.map!(&:to_s) DataTable.new(map { |h| names.map { |n| [n, h[n]] }.to_h }) end
ruby
def columns(*names) names.map!(&:to_s) DataTable.new(map { |h| names.map { |n| [n, h[n]] }.to_h }) end
[ "def", "columns", "(", "*", "names", ")", "names", ".", "map!", "(", ":to_s", ")", "DataTable", ".", "new", "(", "map", "{", "|", "h", "|", "names", ".", "map", "{", "|", "n", "|", "[", "n", ",", "h", "[", "n", "]", "]", "}", ".", "to_h", "}", ")", "end" ]
Slice of a DataTable with only specified columns left. @param names [Array<String>] What columns to leave in a DataTable @return [DataTable]
[ "Slice", "of", "a", "DataTable", "with", "only", "specified", "columns", "left", "." ]
922ecb7994b91aafda56582d7a69e230d14a19db
https://github.com/molybdenum-99/tlaw/blob/922ecb7994b91aafda56582d7a69e230d14a19db/lib/tlaw/data_table.rb#L91-L94