repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
sunspot/sunspot | sunspot/lib/sunspot/session.rb | Sunspot.Session.remove_by_id | def remove_by_id(clazz, *ids)
class_name =
if clazz.is_a?(Class)
clazz.name
else
clazz.to_s
end
indexer.remove_by_id(class_name, ids)
end | ruby | def remove_by_id(clazz, *ids)
class_name =
if clazz.is_a?(Class)
clazz.name
else
clazz.to_s
end
indexer.remove_by_id(class_name, ids)
end | [
"def",
"remove_by_id",
"(",
"clazz",
",",
"*",
"ids",
")",
"class_name",
"=",
"if",
"clazz",
".",
"is_a?",
"(",
"Class",
")",
"clazz",
".",
"name",
"else",
"clazz",
".",
"to_s",
"end",
"indexer",
".",
"remove_by_id",
"(",
"class_name",
",",
"ids",
")",... | See Sunspot.remove_by_id | [
"See",
"Sunspot",
".",
"remove_by_id"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/session.rb#L169-L177 | train |
sunspot/sunspot | sunspot/lib/sunspot/session.rb | Sunspot.Session.remove_all | def remove_all(*classes)
classes.flatten!
if classes.empty?
@deletes += 1
indexer.remove_all
else
@deletes += classes.length
classes.each { |clazz| indexer.remove_all(clazz) }
end
end | ruby | def remove_all(*classes)
classes.flatten!
if classes.empty?
@deletes += 1
indexer.remove_all
else
@deletes += classes.length
classes.each { |clazz| indexer.remove_all(clazz) }
end
end | [
"def",
"remove_all",
"(",
"*",
"classes",
")",
"classes",
".",
"flatten!",
"if",
"classes",
".",
"empty?",
"@deletes",
"+=",
"1",
"indexer",
".",
"remove_all",
"else",
"@deletes",
"+=",
"classes",
".",
"length",
"classes",
".",
"each",
"{",
"|",
"clazz",
... | See Sunspot.remove_all | [
"See",
"Sunspot",
".",
"remove_all"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/session.rb#L190-L199 | train |
sunspot/sunspot | sunspot/lib/sunspot/session.rb | Sunspot.Session.connection | def connection
@connection ||= self.class.connection_class.connect(
url: config.solr.url,
read_timeout: config.solr.read_timeout,
open_timeout: config.solr.open_timeout,
proxy: config.solr.proxy,
update_format: config.solr.update_format || :xml
)
end | ruby | def connection
@connection ||= self.class.connection_class.connect(
url: config.solr.url,
read_timeout: config.solr.read_timeout,
open_timeout: config.solr.open_timeout,
proxy: config.solr.proxy,
update_format: config.solr.update_format || :xml
)
end | [
"def",
"connection",
"@connection",
"||=",
"self",
".",
"class",
".",
"connection_class",
".",
"connect",
"(",
"url",
":",
"config",
".",
"solr",
".",
"url",
",",
"read_timeout",
":",
"config",
".",
"solr",
".",
"read_timeout",
",",
"open_timeout",
":",
"c... | Retrieve the Solr connection for this session, creating one if it does not
already exist.
==== Returns
RSolr::Connection::Base:: The connection for this session | [
"Retrieve",
"the",
"Solr",
"connection",
"for",
"this",
"session",
"creating",
"one",
"if",
"it",
"does",
"not",
"already",
"exist",
"."
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/session.rb#L256-L264 | train |
sunspot/sunspot | sunspot/lib/sunspot/schema.rb | Sunspot.Schema.dynamic_fields | def dynamic_fields
fields = []
variant_combinations.each do |field_variants|
FIELD_TYPES.each do |type|
fields << DynamicField.new(type, field_variants)
end
end
fields
end | ruby | def dynamic_fields
fields = []
variant_combinations.each do |field_variants|
FIELD_TYPES.each do |type|
fields << DynamicField.new(type, field_variants)
end
end
fields
end | [
"def",
"dynamic_fields",
"fields",
"=",
"[",
"]",
"variant_combinations",
".",
"each",
"do",
"|",
"field_variants",
"|",
"FIELD_TYPES",
".",
"each",
"do",
"|",
"type",
"|",
"fields",
"<<",
"DynamicField",
".",
"new",
"(",
"type",
",",
"field_variants",
")",
... | DynamicField instances representing all the available types and variants | [
"DynamicField",
"instances",
"representing",
"all",
"the",
"available",
"types",
"and",
"variants"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/schema.rb#L53-L61 | train |
sunspot/sunspot | sunspot/lib/sunspot/schema.rb | Sunspot.Schema.to_xml | def to_xml
template_path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'schema.xml.erb')
template_text = File.read(template_path)
erb = if RUBY_VERSION >= '2.6'
ERB.new(template_text, trim_mode: '-')
else
ERB.new(template_text, nil, '-')
end
erb.resul... | ruby | def to_xml
template_path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'schema.xml.erb')
template_text = File.read(template_path)
erb = if RUBY_VERSION >= '2.6'
ERB.new(template_text, trim_mode: '-')
else
ERB.new(template_text, nil, '-')
end
erb.resul... | [
"def",
"to_xml",
"template_path",
"=",
"File",
".",
"join",
"(",
"File",
".",
"dirname",
"(",
"__FILE__",
")",
",",
"'..'",
",",
"'..'",
",",
"'templates'",
",",
"'schema.xml.erb'",
")",
"template_text",
"=",
"File",
".",
"read",
"(",
"template_path",
")",... | Return an XML representation of this schema using the ERB template | [
"Return",
"an",
"XML",
"representation",
"of",
"this",
"schema",
"using",
"the",
"ERB",
"template"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/schema.rb#L90-L101 | train |
sunspot/sunspot | sunspot/lib/sunspot/schema.rb | Sunspot.Schema.variant_combinations | def variant_combinations
combinations = []
0.upto(2 ** FIELD_VARIANTS.length - 1) do |b|
combinations << combination = []
FIELD_VARIANTS.each_with_index do |variant, i|
combination << variant if b & 1<<i > 0
end
end
combinations
end | ruby | def variant_combinations
combinations = []
0.upto(2 ** FIELD_VARIANTS.length - 1) do |b|
combinations << combination = []
FIELD_VARIANTS.each_with_index do |variant, i|
combination << variant if b & 1<<i > 0
end
end
combinations
end | [
"def",
"variant_combinations",
"combinations",
"=",
"[",
"]",
"0",
".",
"upto",
"(",
"2",
"**",
"FIELD_VARIANTS",
".",
"length",
"-",
"1",
")",
"do",
"|",
"b",
"|",
"combinations",
"<<",
"combination",
"=",
"[",
"]",
"FIELD_VARIANTS",
".",
"each_with_index... | All of the possible combinations of variants | [
"All",
"of",
"the",
"possible",
"combinations",
"of",
"variants"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/schema.rb#L108-L117 | train |
sunspot/sunspot | sunspot/lib/sunspot/composite_setup.rb | Sunspot.CompositeSetup.text_fields | def text_fields(field_name)
if text_fields = text_fields_hash[field_name.to_sym]
text_fields.to_a
else
raise(
UnrecognizedFieldError,
"No text field configured for #{@types * ', '} with name '#{field_name}'"
)
end
end | ruby | def text_fields(field_name)
if text_fields = text_fields_hash[field_name.to_sym]
text_fields.to_a
else
raise(
UnrecognizedFieldError,
"No text field configured for #{@types * ', '} with name '#{field_name}'"
)
end
end | [
"def",
"text_fields",
"(",
"field_name",
")",
"if",
"text_fields",
"=",
"text_fields_hash",
"[",
"field_name",
".",
"to_sym",
"]",
"text_fields",
".",
"to_a",
"else",
"raise",
"(",
"UnrecognizedFieldError",
",",
"\"No text field configured for #{@types * ', '} with name '... | Get a text field object by its public name. A field will be returned if
it is configured for any of the enclosed types.
==== Returns
Sunspot::FulltextField:: Text field with the given public name
==== Raises
UnrecognizedFieldError::
If no field with that name is configured for any of the enclosed types. | [
"Get",
"a",
"text",
"field",
"object",
"by",
"its",
"public",
"name",
".",
"A",
"field",
"will",
"be",
"returned",
"if",
"it",
"is",
"configured",
"for",
"any",
"of",
"the",
"enclosed",
"types",
"."
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/composite_setup.rb#L51-L60 | train |
sunspot/sunspot | sunspot/lib/sunspot/composite_setup.rb | Sunspot.CompositeSetup.text_fields_hash | def text_fields_hash
@text_fields_hash ||=
setups.inject({}) do |hash, setup|
setup.all_text_fields.each do |text_field|
(hash[text_field.name] ||= Set.new) << text_field
end
hash
end
end | ruby | def text_fields_hash
@text_fields_hash ||=
setups.inject({}) do |hash, setup|
setup.all_text_fields.each do |text_field|
(hash[text_field.name] ||= Set.new) << text_field
end
hash
end
end | [
"def",
"text_fields_hash",
"@text_fields_hash",
"||=",
"setups",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"hash",
",",
"setup",
"|",
"setup",
".",
"all_text_fields",
".",
"each",
"do",
"|",
"text_field",
"|",
"(",
"hash",
"[",
"text_field",
".",
"na... | Return a hash of field names to text field objects, containing all fields
that are configured for any of the types enclosed.
==== Returns
Hash:: Hash of field names to text field objects. | [
"Return",
"a",
"hash",
"of",
"field",
"names",
"to",
"text",
"field",
"objects",
"containing",
"all",
"fields",
"that",
"are",
"configured",
"for",
"any",
"of",
"the",
"types",
"enclosed",
"."
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/composite_setup.rb#L129-L137 | train |
sunspot/sunspot | sunspot/lib/sunspot/composite_setup.rb | Sunspot.CompositeSetup.fields_hash | def fields_hash
@fields_hash ||=
begin
field_sets_hash = Hash.new { |h, k| h[k] = Set.new }
@types.each do |type|
Setup.for(type).fields.each do |field|
field_sets_hash[field.name.to_sym] << field
end
end
fields_hash = {}
... | ruby | def fields_hash
@fields_hash ||=
begin
field_sets_hash = Hash.new { |h, k| h[k] = Set.new }
@types.each do |type|
Setup.for(type).fields.each do |field|
field_sets_hash[field.name.to_sym] << field
end
end
fields_hash = {}
... | [
"def",
"fields_hash",
"@fields_hash",
"||=",
"begin",
"field_sets_hash",
"=",
"Hash",
".",
"new",
"{",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"Set",
".",
"new",
"}",
"@types",
".",
"each",
"do",
"|",
"type",
"|",
"Setup",
".",
"for",
"... | Return a hash of field names to field objects, containing all fields
that are common to all of the classes enclosed. In order for fields
to be common, they must be of the same type and have the same
value for allow_multiple? and stored?. This method is memoized.
==== Returns
Hash:: field names keyed to field obj... | [
"Return",
"a",
"hash",
"of",
"field",
"names",
"to",
"field",
"objects",
"containing",
"all",
"fields",
"that",
"are",
"common",
"to",
"all",
"of",
"the",
"classes",
"enclosed",
".",
"In",
"order",
"for",
"fields",
"to",
"be",
"common",
"they",
"must",
"... | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/composite_setup.rb#L159-L176 | train |
sunspot/sunspot | sunspot/lib/sunspot/setup.rb | Sunspot.Setup.add_text_field_factory | def add_text_field_factory(name, options = {}, &block)
stored, more_like_this = options[:stored], options[:more_like_this]
field_factory = FieldFactory::Static.new(name, Type::TextType.instance, options, &block)
@text_field_factories[name] = field_factory
@text_field_factories_cache[field_factor... | ruby | def add_text_field_factory(name, options = {}, &block)
stored, more_like_this = options[:stored], options[:more_like_this]
field_factory = FieldFactory::Static.new(name, Type::TextType.instance, options, &block)
@text_field_factories[name] = field_factory
@text_field_factories_cache[field_factor... | [
"def",
"add_text_field_factory",
"(",
"name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"stored",
",",
"more_like_this",
"=",
"options",
"[",
":stored",
"]",
",",
"options",
"[",
":more_like_this",
"]",
"field_factory",
"=",
"FieldFactory",
"::"... | Add field_factories for fulltext search
==== Parameters
field_factories<Array>:: Array of Sunspot::Field objects | [
"Add",
"field_factories",
"for",
"fulltext",
"search"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/setup.rb#L59-L70 | train |
sunspot/sunspot | sunspot/lib/sunspot/setup.rb | Sunspot.Setup.add_dynamic_field_factory | def add_dynamic_field_factory(name, type, options = {}, &block)
stored, more_like_this = options[:stored], options[:more_like_this]
field_factory = FieldFactory::Dynamic.new(name, type, options, &block)
@dynamic_field_factories[field_factory.signature] = field_factory
@dynamic_field_factories_ca... | ruby | def add_dynamic_field_factory(name, type, options = {}, &block)
stored, more_like_this = options[:stored], options[:more_like_this]
field_factory = FieldFactory::Dynamic.new(name, type, options, &block)
@dynamic_field_factories[field_factory.signature] = field_factory
@dynamic_field_factories_ca... | [
"def",
"add_dynamic_field_factory",
"(",
"name",
",",
"type",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"stored",
",",
"more_like_this",
"=",
"options",
"[",
":stored",
"]",
",",
"options",
"[",
":more_like_this",
"]",
"field_factory",
"=",
"F... | Add dynamic field_factories
==== Parameters
field_factories<Array>:: Array of dynamic field objects | [
"Add",
"dynamic",
"field_factories"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/setup.rb#L79-L90 | train |
sunspot/sunspot | sunspot/lib/sunspot/setup.rb | Sunspot.Setup.all_more_like_this_fields | def all_more_like_this_fields
@more_like_this_field_factories_cache.values.map do |field_factories|
field_factories.map { |field_factory| field_factory.build }
end.flatten
end | ruby | def all_more_like_this_fields
@more_like_this_field_factories_cache.values.map do |field_factories|
field_factories.map { |field_factory| field_factory.build }
end.flatten
end | [
"def",
"all_more_like_this_fields",
"@more_like_this_field_factories_cache",
".",
"values",
".",
"map",
"do",
"|",
"field_factories",
"|",
"field_factories",
".",
"map",
"{",
"|",
"field_factory",
"|",
"field_factory",
".",
"build",
"}",
"end",
".",
"flatten",
"end"... | Return all more_like_this fields | [
"Return",
"all",
"more_like_this",
"fields"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/setup.rb#L200-L204 | train |
sunspot/sunspot | sunspot/lib/sunspot/setup.rb | Sunspot.Setup.all_field_factories | def all_field_factories
all_field_factories = []
all_field_factories.concat(field_factories).concat(text_field_factories).concat(dynamic_field_factories)
all_field_factories
end | ruby | def all_field_factories
all_field_factories = []
all_field_factories.concat(field_factories).concat(text_field_factories).concat(dynamic_field_factories)
all_field_factories
end | [
"def",
"all_field_factories",
"all_field_factories",
"=",
"[",
"]",
"all_field_factories",
".",
"concat",
"(",
"field_factories",
")",
".",
"concat",
"(",
"text_field_factories",
")",
".",
"concat",
"(",
"dynamic_field_factories",
")",
"all_field_factories",
"end"
] | Get all static, dynamic, and text field_factories associated with this setup as
well as all inherited field_factories
==== Returns
Array:: Collection of all text and scope field_factories associated with this setup | [
"Get",
"all",
"static",
"dynamic",
"and",
"text",
"field_factories",
"associated",
"with",
"this",
"setup",
"as",
"well",
"as",
"all",
"inherited",
"field_factories"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/setup.rb#L237-L241 | train |
sunspot/sunspot | sunspot/lib/sunspot/indexer.rb | Sunspot.Indexer.add_atomic_update | def add_atomic_update(clazz, updates={})
documents = updates.map { |id, m| prepare_atomic_update(clazz, id, m) }
add_batch_documents(documents)
end | ruby | def add_atomic_update(clazz, updates={})
documents = updates.map { |id, m| prepare_atomic_update(clazz, id, m) }
add_batch_documents(documents)
end | [
"def",
"add_atomic_update",
"(",
"clazz",
",",
"updates",
"=",
"{",
"}",
")",
"documents",
"=",
"updates",
".",
"map",
"{",
"|",
"id",
",",
"m",
"|",
"prepare_atomic_update",
"(",
"clazz",
",",
"id",
",",
"m",
")",
"}",
"add_batch_documents",
"(",
"doc... | Construct a representation of the given class instances for atomic properties update
and send it to the connection for indexing
==== Parameters
clazz<Class>:: the class of the models to be updated
updates<Hash>:: hash of updates where keys are model ids
and values are hash with property name/valu... | [
"Construct",
"a",
"representation",
"of",
"the",
"given",
"class",
"instances",
"for",
"atomic",
"properties",
"update",
"and",
"send",
"it",
"to",
"the",
"connection",
"for",
"indexing"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/indexer.rb#L39-L42 | train |
sunspot/sunspot | sunspot/lib/sunspot/indexer.rb | Sunspot.Indexer.remove | def remove(*models)
@connection.delete_by_id(
models.map { |model| Adapters::InstanceAdapter.adapt(model).index_id }
)
end | ruby | def remove(*models)
@connection.delete_by_id(
models.map { |model| Adapters::InstanceAdapter.adapt(model).index_id }
)
end | [
"def",
"remove",
"(",
"*",
"models",
")",
"@connection",
".",
"delete_by_id",
"(",
"models",
".",
"map",
"{",
"|",
"model",
"|",
"Adapters",
"::",
"InstanceAdapter",
".",
"adapt",
"(",
"model",
")",
".",
"index_id",
"}",
")",
"end"
] | Remove the given model from the Solr index | [
"Remove",
"the",
"given",
"model",
"from",
"the",
"Solr",
"index"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/indexer.rb#L47-L51 | train |
sunspot/sunspot | sunspot/lib/sunspot/indexer.rb | Sunspot.Indexer.remove_by_id | def remove_by_id(class_name, *ids)
ids.flatten!
@connection.delete_by_id(
ids.map { |id| Adapters::InstanceAdapter.index_id_for(class_name, id) }
)
end | ruby | def remove_by_id(class_name, *ids)
ids.flatten!
@connection.delete_by_id(
ids.map { |id| Adapters::InstanceAdapter.index_id_for(class_name, id) }
)
end | [
"def",
"remove_by_id",
"(",
"class_name",
",",
"*",
"ids",
")",
"ids",
".",
"flatten!",
"@connection",
".",
"delete_by_id",
"(",
"ids",
".",
"map",
"{",
"|",
"id",
"|",
"Adapters",
"::",
"InstanceAdapter",
".",
"index_id_for",
"(",
"class_name",
",",
"id",... | Remove the model from the Solr index by specifying the class and ID | [
"Remove",
"the",
"model",
"from",
"the",
"Solr",
"index",
"by",
"specifying",
"the",
"class",
"and",
"ID"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/indexer.rb#L56-L61 | train |
sunspot/sunspot | sunspot/lib/sunspot/indexer.rb | Sunspot.Indexer.prepare_full_update | def prepare_full_update(model)
document = document_for_full_update(model)
setup = setup_for_object(model)
if boost = setup.document_boost_for(model)
document.attrs[:boost] = boost
end
setup.all_field_factories.each do |field_factory|
field_factory.populate_document(document... | ruby | def prepare_full_update(model)
document = document_for_full_update(model)
setup = setup_for_object(model)
if boost = setup.document_boost_for(model)
document.attrs[:boost] = boost
end
setup.all_field_factories.each do |field_factory|
field_factory.populate_document(document... | [
"def",
"prepare_full_update",
"(",
"model",
")",
"document",
"=",
"document_for_full_update",
"(",
"model",
")",
"setup",
"=",
"setup_for_object",
"(",
"model",
")",
"if",
"boost",
"=",
"setup",
".",
"document_boost_for",
"(",
"model",
")",
"document",
".",
"a... | Convert documents into hash of indexed properties | [
"Convert",
"documents",
"into",
"hash",
"of",
"indexed",
"properties"
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/indexer.rb#L104-L114 | train |
sunspot/sunspot | sunspot/lib/sunspot/indexer.rb | Sunspot.Indexer.document_for_full_update | def document_for_full_update(model)
RSolr::Xml::Document.new(
id: Adapters::InstanceAdapter.adapt(model).index_id,
type: Util.superclasses_for(model.class).map(&:name)
)
end | ruby | def document_for_full_update(model)
RSolr::Xml::Document.new(
id: Adapters::InstanceAdapter.adapt(model).index_id,
type: Util.superclasses_for(model.class).map(&:name)
)
end | [
"def",
"document_for_full_update",
"(",
"model",
")",
"RSolr",
"::",
"Xml",
"::",
"Document",
".",
"new",
"(",
"id",
":",
"Adapters",
"::",
"InstanceAdapter",
".",
"adapt",
"(",
"model",
")",
".",
"index_id",
",",
"type",
":",
"Util",
".",
"superclasses_fo... | All indexed documents index and store the +id+ and +type+ fields.
These methods construct the document hash containing those key-value
pairs. | [
"All",
"indexed",
"documents",
"index",
"and",
"store",
"the",
"+",
"id",
"+",
"and",
"+",
"type",
"+",
"fields",
".",
"These",
"methods",
"construct",
"the",
"document",
"hash",
"containing",
"those",
"key",
"-",
"value",
"pairs",
"."
] | 31dd76cd7a14a4ef7bd541de97483d8cd72ff685 | https://github.com/sunspot/sunspot/blob/31dd76cd7a14a4ef7bd541de97483d8cd72ff685/sunspot/lib/sunspot/indexer.rb#L143-L148 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.analyze | def analyze(phone, passed_country)
country = country_or_default_country passed_country
result = parse_country(phone, country)
d_result = case
when result && result.values.find { |e| e[:valid].any? }
# all is good, return result
when passed_country.... | ruby | def analyze(phone, passed_country)
country = country_or_default_country passed_country
result = parse_country(phone, country)
d_result = case
when result && result.values.find { |e| e[:valid].any? }
# all is good, return result
when passed_country.... | [
"def",
"analyze",
"(",
"phone",
",",
"passed_country",
")",
"country",
"=",
"country_or_default_country",
"passed_country",
"result",
"=",
"parse_country",
"(",
"phone",
",",
"country",
")",
"d_result",
"=",
"case",
"when",
"result",
"&&",
"result",
".",
"values... | parses provided phone if it is valid for country data and
returns result of analyze
==== Attributes
* +phone+ - Phone number for parsing
* +passed_country+ - Country provided for parsing. Must be ISO code of
country (2 letters) like 'US', 'us' or :us for United States | [
"parses",
"provided",
"phone",
"if",
"it",
"is",
"valid",
"for",
"country",
"data",
"and",
"returns",
"result",
"of",
"analyze"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L18-L33 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.better_result | def better_result(base_result, result = nil)
base_result ||= {}
return base_result unless result
return result unless base_result.values.find { |e| e[:possible].any? }
return result if result.values.find { |e| e[:valid].any? }
base_result
end | ruby | def better_result(base_result, result = nil)
base_result ||= {}
return base_result unless result
return result unless base_result.values.find { |e| e[:possible].any? }
return result if result.values.find { |e| e[:valid].any? }
base_result
end | [
"def",
"better_result",
"(",
"base_result",
",",
"result",
"=",
"nil",
")",
"base_result",
"||=",
"{",
"}",
"return",
"base_result",
"unless",
"result",
"return",
"result",
"unless",
"base_result",
".",
"values",
".",
"find",
"{",
"|",
"e",
"|",
"e",
"[",
... | method checks which result is better to return | [
"method",
"checks",
"which",
"result",
"is",
"better",
"to",
"return"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L38-L47 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.with_replaced_national_prefix | def with_replaced_national_prefix(phone, data)
return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})")
match = phone.match pattern
if match && match.captures.compact.size > 0
phone.gsub(pattern, data[Core::NATIONAL_PR... | ruby | def with_replaced_national_prefix(phone, data)
return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})")
match = phone.match pattern
if match && match.captures.compact.size > 0
phone.gsub(pattern, data[Core::NATIONAL_PR... | [
"def",
"with_replaced_national_prefix",
"(",
"phone",
",",
"data",
")",
"return",
"phone",
"unless",
"data",
"[",
"Core",
"::",
"NATIONAL_PREFIX_TRANSFORM_RULE",
"]",
"pattern",
"=",
"cr",
"(",
"\"^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})\"",
")",
"match",
"=",
... | replacing national prefix to simplified format | [
"replacing",
"national",
"prefix",
"to",
"simplified",
"format"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L50-L59 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.parse_country | def parse_country(phone, country)
data = Phonelib.phone_data[country]
return nil unless data
# if country was provided and it's a valid country, trying to
# create e164 representation of phone number,
# kind of normalization for parsing
e164 = convert_to_e164 with_replaced_national_... | ruby | def parse_country(phone, country)
data = Phonelib.phone_data[country]
return nil unless data
# if country was provided and it's a valid country, trying to
# create e164 representation of phone number,
# kind of normalization for parsing
e164 = convert_to_e164 with_replaced_national_... | [
"def",
"parse_country",
"(",
"phone",
",",
"country",
")",
"data",
"=",
"Phonelib",
".",
"phone_data",
"[",
"country",
"]",
"return",
"nil",
"unless",
"data",
"# if country was provided and it's a valid country, trying to",
"# create e164 representation of phone number,",
"... | trying to parse phone for single country including international prefix
check for provided country
==== Attributes
* +phone+ - phone for parsing
* +country+ - country to parse phone with | [
"trying",
"to",
"parse",
"phone",
"for",
"single",
"country",
"including",
"international",
"prefix",
"check",
"for",
"provided",
"country"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L68-L82 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.parse_single_country | def parse_single_country(e164, data)
valid_match = phone_match_data?(e164, data)
if valid_match
national_and_data(data, valid_match)
else
possible_match = phone_match_data?(e164, data, true)
possible_match && national_and_data(data, possible_match, true)
end
end | ruby | def parse_single_country(e164, data)
valid_match = phone_match_data?(e164, data)
if valid_match
national_and_data(data, valid_match)
else
possible_match = phone_match_data?(e164, data, true)
possible_match && national_and_data(data, possible_match, true)
end
end | [
"def",
"parse_single_country",
"(",
"e164",
",",
"data",
")",
"valid_match",
"=",
"phone_match_data?",
"(",
"e164",
",",
"data",
")",
"if",
"valid_match",
"national_and_data",
"(",
"data",
",",
"valid_match",
")",
"else",
"possible_match",
"=",
"phone_match_data?"... | method checks if phone is valid against single provided country data
==== Attributes
* +e164+ - e164 representation of phone for parsing
* +data+ - country data for single country for parsing | [
"method",
"checks",
"if",
"phone",
"is",
"valid",
"against",
"single",
"provided",
"country",
"data"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L90-L98 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.detect_and_parse | def detect_and_parse(phone, country)
result = {}
Phonelib.phone_data.each do |key, data|
parsed = parse_single_country(phone, data)
if (!Phonelib.strict_double_prefix_check || key == country) && double_prefix_allowed?(data, phone, parsed && parsed[key])
parsed = parse_single_countr... | ruby | def detect_and_parse(phone, country)
result = {}
Phonelib.phone_data.each do |key, data|
parsed = parse_single_country(phone, data)
if (!Phonelib.strict_double_prefix_check || key == country) && double_prefix_allowed?(data, phone, parsed && parsed[key])
parsed = parse_single_countr... | [
"def",
"detect_and_parse",
"(",
"phone",
",",
"country",
")",
"result",
"=",
"{",
"}",
"Phonelib",
".",
"phone_data",
".",
"each",
"do",
"|",
"key",
",",
"data",
"|",
"parsed",
"=",
"parse_single_country",
"(",
"phone",
",",
"data",
")",
"if",
"(",
"!"... | method tries to detect what is the country for provided phone
==== Attributes
* +phone+ - phone number for parsing | [
"method",
"tries",
"to",
"detect",
"what",
"is",
"the",
"country",
"for",
"provided",
"phone"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L105-L115 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.convert_to_e164 | def convert_to_e164(phone, data)
match = phone.match full_regex_for_data(data, Core::VALID_PATTERN, !original_starts_with_plus?)
case
when match
"#{data[Core::COUNTRY_CODE]}#{match.to_a.last}"
when phone.match(cr("^#{data[Core::INTERNATIONAL_PREFIX]}"))
phone.sub(cr("^#{data[Core... | ruby | def convert_to_e164(phone, data)
match = phone.match full_regex_for_data(data, Core::VALID_PATTERN, !original_starts_with_plus?)
case
when match
"#{data[Core::COUNTRY_CODE]}#{match.to_a.last}"
when phone.match(cr("^#{data[Core::INTERNATIONAL_PREFIX]}"))
phone.sub(cr("^#{data[Core... | [
"def",
"convert_to_e164",
"(",
"phone",
",",
"data",
")",
"match",
"=",
"phone",
".",
"match",
"full_regex_for_data",
"(",
"data",
",",
"Core",
"::",
"VALID_PATTERN",
",",
"!",
"original_starts_with_plus?",
")",
"case",
"when",
"match",
"\"#{data[Core::COUNTRY_COD... | Create phone representation in e164 format
==== Attributes
* +phone+ - phone number for parsing
* +data+ - country data to be based on for creating e164 representation | [
"Create",
"phone",
"representation",
"in",
"e164",
"format"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L123-L135 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.national_and_data | def national_and_data(data, country_match, not_valid = false)
result = data.select { |k, _v| k != :types && k != :formats }
phone = country_match.to_a.last
result[:national] = phone
result[:format] = number_format(phone, data[Core::FORMATS])
result.merge! all_number_types(phone, data[Core:... | ruby | def national_and_data(data, country_match, not_valid = false)
result = data.select { |k, _v| k != :types && k != :formats }
phone = country_match.to_a.last
result[:national] = phone
result[:format] = number_format(phone, data[Core::FORMATS])
result.merge! all_number_types(phone, data[Core:... | [
"def",
"national_and_data",
"(",
"data",
",",
"country_match",
",",
"not_valid",
"=",
"false",
")",
"result",
"=",
"data",
".",
"select",
"{",
"|",
"k",
",",
"_v",
"|",
"k",
"!=",
":types",
"&&",
"k",
"!=",
":formats",
"}",
"phone",
"=",
"country_match... | returns national number and analyzing results for provided phone number
==== Attributes
* +data+ - country data
* +country_match+ - result of match of phone within full regex
* +not_valid+ - specifies that number is not valid by general desc pattern | [
"returns",
"national",
"number",
"and",
"analyzing",
"results",
"for",
"provided",
"phone",
"number"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L144-L153 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.all_number_types | def all_number_types(phone, data, not_valid = false)
response = { valid: [], possible: [] }
types_for_check(data).each do |type|
possible, valid = get_patterns(data, type)
valid_and_possible, possible_result =
number_valid_and_possible?(phone, possible, valid, not_valid)
... | ruby | def all_number_types(phone, data, not_valid = false)
response = { valid: [], possible: [] }
types_for_check(data).each do |type|
possible, valid = get_patterns(data, type)
valid_and_possible, possible_result =
number_valid_and_possible?(phone, possible, valid, not_valid)
... | [
"def",
"all_number_types",
"(",
"phone",
",",
"data",
",",
"not_valid",
"=",
"false",
")",
"response",
"=",
"{",
"valid",
":",
"[",
"]",
",",
"possible",
":",
"[",
"]",
"}",
"types_for_check",
"(",
"data",
")",
".",
"each",
"do",
"|",
"type",
"|",
... | Returns all valid and possible phone number types for currently parsed
phone for provided data hash.
==== Attributes
* +phone+ - phone number for parsing
* +data+ - country data
* +not_valid+ - specifies that number is not valid by general desc pattern | [
"Returns",
"all",
"valid",
"and",
"possible",
"phone",
"number",
"types",
"for",
"currently",
"parsed",
"phone",
"for",
"provided",
"data",
"hash",
"."
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L163-L176 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.number_format | def number_format(national, format_data)
format_data && format_data.find do |format|
(format[Core::LEADING_DIGITS].nil? || \
national.match(cr("^(#{format[Core::LEADING_DIGITS]})"))) && \
national.match(cr("^(#{format[Core::PATTERN]})$"))
end || Core::DEFAULT_NUMBER_FORMAT
... | ruby | def number_format(national, format_data)
format_data && format_data.find do |format|
(format[Core::LEADING_DIGITS].nil? || \
national.match(cr("^(#{format[Core::LEADING_DIGITS]})"))) && \
national.match(cr("^(#{format[Core::PATTERN]})$"))
end || Core::DEFAULT_NUMBER_FORMAT
... | [
"def",
"number_format",
"(",
"national",
",",
"format_data",
")",
"format_data",
"&&",
"format_data",
".",
"find",
"do",
"|",
"format",
"|",
"(",
"format",
"[",
"Core",
"::",
"LEADING_DIGITS",
"]",
".",
"nil?",
"||",
"national",
".",
"match",
"(",
"cr",
... | Gets matched number formatting rule or default one
==== Attributes
* +national+ - national phone number
* +format_data+ - formatting data from country data | [
"Gets",
"matched",
"number",
"formatting",
"rule",
"or",
"default",
"one"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L184-L190 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer.rb | Phonelib.PhoneAnalyzer.get_patterns | def get_patterns(all_patterns, type)
type = Core::FIXED_LINE if type == Core::FIXED_OR_MOBILE
patterns = all_patterns[type]
if patterns
[
type_regex(patterns, Core::POSSIBLE_PATTERN),
type_regex(patterns, Core::VALID_PATTERN)
]
else
[nil, nil]
e... | ruby | def get_patterns(all_patterns, type)
type = Core::FIXED_LINE if type == Core::FIXED_OR_MOBILE
patterns = all_patterns[type]
if patterns
[
type_regex(patterns, Core::POSSIBLE_PATTERN),
type_regex(patterns, Core::VALID_PATTERN)
]
else
[nil, nil]
e... | [
"def",
"get_patterns",
"(",
"all_patterns",
",",
"type",
")",
"type",
"=",
"Core",
"::",
"FIXED_LINE",
"if",
"type",
"==",
"Core",
"::",
"FIXED_OR_MOBILE",
"patterns",
"=",
"all_patterns",
"[",
"type",
"]",
"if",
"patterns",
"[",
"type_regex",
"(",
"patterns... | Returns possible and valid patterns for validation for provided type
==== Attributes
* +all_patterns+ - hash of all patterns for validation
* +type+ - type of phone to get patterns for | [
"Returns",
"possible",
"and",
"valid",
"patterns",
"for",
"validation",
"for",
"provided",
"type"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer.rb#L198-L210 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.vanity_converted | def vanity_converted(phone)
return phone unless Phonelib.vanity_conversion
(phone || '').gsub(cr('[a-zA-Z]')) do |c|
c.upcase!
# subtract "A"
n = (c.ord - 65) / 3
# account for #7 & #9 which have 4 chars
n -= 1 if c.match(Core::VANITY_4_LETTERS_KEYS_REGEX)
(n... | ruby | def vanity_converted(phone)
return phone unless Phonelib.vanity_conversion
(phone || '').gsub(cr('[a-zA-Z]')) do |c|
c.upcase!
# subtract "A"
n = (c.ord - 65) / 3
# account for #7 & #9 which have 4 chars
n -= 1 if c.match(Core::VANITY_4_LETTERS_KEYS_REGEX)
(n... | [
"def",
"vanity_converted",
"(",
"phone",
")",
"return",
"phone",
"unless",
"Phonelib",
".",
"vanity_conversion",
"(",
"phone",
"||",
"''",
")",
".",
"gsub",
"(",
"cr",
"(",
"'[a-zA-Z]'",
")",
")",
"do",
"|",
"c",
"|",
"c",
".",
"upcase!",
"# subtract \"A... | converts symbols in phone to numbers | [
"converts",
"symbols",
"in",
"phone",
"to",
"numbers"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L11-L22 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.passed_country | def passed_country(country)
code = country_prefix(country)
if Core::PLUS_SIGN == @original[0] && code && !sanitized.start_with?(code)
# in case number passed with + but it doesn't start with passed
# country prefix
country = nil
end
country
end | ruby | def passed_country(country)
code = country_prefix(country)
if Core::PLUS_SIGN == @original[0] && code && !sanitized.start_with?(code)
# in case number passed with + but it doesn't start with passed
# country prefix
country = nil
end
country
end | [
"def",
"passed_country",
"(",
"country",
")",
"code",
"=",
"country_prefix",
"(",
"country",
")",
"if",
"Core",
"::",
"PLUS_SIGN",
"==",
"@original",
"[",
"0",
"]",
"&&",
"code",
"&&",
"!",
"sanitized",
".",
"start_with?",
"(",
"code",
")",
"# in case numb... | defines if to validate against single country or not | [
"defines",
"if",
"to",
"validate",
"against",
"single",
"country",
"or",
"not"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L25-L33 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.country_prefix | def country_prefix(country)
country = country.to_s.upcase
Phonelib.phone_data[country] && \
Phonelib.phone_data[country][Core::COUNTRY_CODE]
end | ruby | def country_prefix(country)
country = country.to_s.upcase
Phonelib.phone_data[country] && \
Phonelib.phone_data[country][Core::COUNTRY_CODE]
end | [
"def",
"country_prefix",
"(",
"country",
")",
"country",
"=",
"country",
".",
"to_s",
".",
"upcase",
"Phonelib",
".",
"phone_data",
"[",
"country",
"]",
"&&",
"Phonelib",
".",
"phone_data",
"[",
"country",
"]",
"[",
"Core",
"::",
"COUNTRY_CODE",
"]",
"end"... | returns country prefix for provided country or nil | [
"returns",
"country",
"prefix",
"for",
"provided",
"country",
"or",
"nil"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L36-L40 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.country_can_dp? | def country_can_dp?(country)
Phonelib.phone_data[country] &&
Phonelib.phone_data[country][Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
!original_starts_with_plus?
end | ruby | def country_can_dp?(country)
Phonelib.phone_data[country] &&
Phonelib.phone_data[country][Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
!original_starts_with_plus?
end | [
"def",
"country_can_dp?",
"(",
"country",
")",
"Phonelib",
".",
"phone_data",
"[",
"country",
"]",
"&&",
"Phonelib",
".",
"phone_data",
"[",
"country",
"]",
"[",
"Core",
"::",
"DOUBLE_COUNTRY_PREFIX_FLAG",
"]",
"&&",
"!",
"original_starts_with_plus?",
"end"
] | defines whether country can have double country prefix in number | [
"defines",
"whether",
"country",
"can",
"have",
"double",
"country",
"prefix",
"in",
"number"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L48-L52 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.double_prefix_allowed? | def double_prefix_allowed?(data, phone, parsed = {})
data[Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
phone =~ cr("^#{data[Core::COUNTRY_CODE]}") &&
parsed && (parsed[:valid].nil? || parsed[:valid].empty?) &&
!original_starts_with_plus?
end | ruby | def double_prefix_allowed?(data, phone, parsed = {})
data[Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
phone =~ cr("^#{data[Core::COUNTRY_CODE]}") &&
parsed && (parsed[:valid].nil? || parsed[:valid].empty?) &&
!original_starts_with_plus?
end | [
"def",
"double_prefix_allowed?",
"(",
"data",
",",
"phone",
",",
"parsed",
"=",
"{",
"}",
")",
"data",
"[",
"Core",
"::",
"DOUBLE_COUNTRY_PREFIX_FLAG",
"]",
"&&",
"phone",
"=~",
"cr",
"(",
"\"^#{data[Core::COUNTRY_CODE]}\"",
")",
"&&",
"parsed",
"&&",
"(",
"... | checks if country can have numbers with double country prefixes
==== Attributes
* +data+ - country data used for parsing
* +phone+ - phone number being parsed
* +parsed+ - parsed regex match for phone | [
"checks",
"if",
"country",
"can",
"have",
"numbers",
"with",
"double",
"country",
"prefixes"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L74-L79 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.country_or_default_country | def country_or_default_country(country)
country ||= (original_starts_with_plus? ? nil : Phonelib.default_country)
country && country.to_s.upcase
end | ruby | def country_or_default_country(country)
country ||= (original_starts_with_plus? ? nil : Phonelib.default_country)
country && country.to_s.upcase
end | [
"def",
"country_or_default_country",
"(",
"country",
")",
"country",
"||=",
"(",
"original_starts_with_plus?",
"?",
"nil",
":",
"Phonelib",
".",
"default_country",
")",
"country",
"&&",
"country",
".",
"to_s",
".",
"upcase",
"end"
] | Get country that was provided or default country in needable format
==== Attributes
* +country+ - country passed for parsing | [
"Get",
"country",
"that",
"was",
"provided",
"or",
"default",
"country",
"in",
"needable",
"format"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L91-L94 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.type_regex | def type_regex(data, type)
regex = [data[type]]
if Phonelib.parse_special && data[Core::SHORT] && data[Core::SHORT][type]
regex << data[Core::SHORT][type]
end
regex.join('|')
end | ruby | def type_regex(data, type)
regex = [data[type]]
if Phonelib.parse_special && data[Core::SHORT] && data[Core::SHORT][type]
regex << data[Core::SHORT][type]
end
regex.join('|')
end | [
"def",
"type_regex",
"(",
"data",
",",
"type",
")",
"regex",
"=",
"[",
"data",
"[",
"type",
"]",
"]",
"if",
"Phonelib",
".",
"parse_special",
"&&",
"data",
"[",
"Core",
"::",
"SHORT",
"]",
"&&",
"data",
"[",
"Core",
"::",
"SHORT",
"]",
"[",
"type",... | Returns regex for type with special types if needed
==== Attributes
* +data+ - country types data for single type
* +type+ - possible or valid regex type needed | [
"Returns",
"regex",
"for",
"type",
"with",
"special",
"types",
"if",
"needed"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L120-L126 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.phone_match_data? | def phone_match_data?(phone, data, possible = false)
country_code = "#{data[Core::COUNTRY_CODE]}"
inter_prefix = "(#{data[Core::INTERNATIONAL_PREFIX]})?"
return unless phone.match cr("^0{2}?#{inter_prefix}#{country_code}")
type = possible ? Core::POSSIBLE_PATTERN : Core::VALID_PATTERN
pho... | ruby | def phone_match_data?(phone, data, possible = false)
country_code = "#{data[Core::COUNTRY_CODE]}"
inter_prefix = "(#{data[Core::INTERNATIONAL_PREFIX]})?"
return unless phone.match cr("^0{2}?#{inter_prefix}#{country_code}")
type = possible ? Core::POSSIBLE_PATTERN : Core::VALID_PATTERN
pho... | [
"def",
"phone_match_data?",
"(",
"phone",
",",
"data",
",",
"possible",
"=",
"false",
")",
"country_code",
"=",
"\"#{data[Core::COUNTRY_CODE]}\"",
"inter_prefix",
"=",
"\"(#{data[Core::INTERNATIONAL_PREFIX]})?\"",
"return",
"unless",
"phone",
".",
"match",
"cr",
"(",
... | Check if phone match country data
==== Attributes
* +phone+ - phone number for parsing
* +data+ - country data | [
"Check",
"if",
"phone",
"match",
"country",
"data"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L134-L141 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.types_for_check | def types_for_check(data)
exclude_list = PhoneAnalyzer::NOT_FOR_CHECK
exclude_list += Phonelib::Core::SHORT_CODES unless Phonelib.parse_special
Core::TYPES_DESC.keys - exclude_list + fixed_and_mobile_keys(data)
end | ruby | def types_for_check(data)
exclude_list = PhoneAnalyzer::NOT_FOR_CHECK
exclude_list += Phonelib::Core::SHORT_CODES unless Phonelib.parse_special
Core::TYPES_DESC.keys - exclude_list + fixed_and_mobile_keys(data)
end | [
"def",
"types_for_check",
"(",
"data",
")",
"exclude_list",
"=",
"PhoneAnalyzer",
"::",
"NOT_FOR_CHECK",
"exclude_list",
"+=",
"Phonelib",
"::",
"Core",
"::",
"SHORT_CODES",
"unless",
"Phonelib",
".",
"parse_special",
"Core",
"::",
"TYPES_DESC",
".",
"keys",
"-",
... | returns array of phone types for check for current country data
==== Attributes
* +data+ - country data hash | [
"returns",
"array",
"of",
"phone",
"types",
"for",
"check",
"for",
"current",
"country",
"data"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L160-L164 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.fixed_and_mobile_keys | def fixed_and_mobile_keys(data)
if data[Core::FIXED_LINE] == data[Core::MOBILE]
[Core::FIXED_OR_MOBILE]
else
[Core::FIXED_LINE, Core::MOBILE]
end
end | ruby | def fixed_and_mobile_keys(data)
if data[Core::FIXED_LINE] == data[Core::MOBILE]
[Core::FIXED_OR_MOBILE]
else
[Core::FIXED_LINE, Core::MOBILE]
end
end | [
"def",
"fixed_and_mobile_keys",
"(",
"data",
")",
"if",
"data",
"[",
"Core",
"::",
"FIXED_LINE",
"]",
"==",
"data",
"[",
"Core",
"::",
"MOBILE",
"]",
"[",
"Core",
"::",
"FIXED_OR_MOBILE",
"]",
"else",
"[",
"Core",
"::",
"FIXED_LINE",
",",
"Core",
"::",
... | Checks if fixed line pattern and mobile pattern are the same and returns
appropriate keys
==== Attributes
* +data+ - country data | [
"Checks",
"if",
"fixed",
"line",
"pattern",
"and",
"mobile",
"pattern",
"are",
"the",
"same",
"and",
"returns",
"appropriate",
"keys"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L172-L178 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.number_valid_and_possible? | def number_valid_and_possible?(number, p_regex, v_regex, not_valid = false)
possible = number_match?(number, p_regex)
return [!not_valid && possible, possible] if p_regex == v_regex
valid = !not_valid && possible && number_match?(number, v_regex)
[valid && possible, possible]
end | ruby | def number_valid_and_possible?(number, p_regex, v_regex, not_valid = false)
possible = number_match?(number, p_regex)
return [!not_valid && possible, possible] if p_regex == v_regex
valid = !not_valid && possible && number_match?(number, v_regex)
[valid && possible, possible]
end | [
"def",
"number_valid_and_possible?",
"(",
"number",
",",
"p_regex",
",",
"v_regex",
",",
"not_valid",
"=",
"false",
")",
"possible",
"=",
"number_match?",
"(",
"number",
",",
"p_regex",
")",
"return",
"[",
"!",
"not_valid",
"&&",
"possible",
",",
"possible",
... | Checks if passed number matches valid and possible patterns
==== Attributes
* +number+ - phone number for validation
* +p_regex+ - possible regex pattern for validation
* +v_regex+ - valid regex pattern for validation
* +not_valid+ - specifies that number is not valid by general desc pattern | [
"Checks",
"if",
"passed",
"number",
"matches",
"valid",
"and",
"possible",
"patterns"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L188-L195 | train |
daddyz/phonelib | lib/phonelib/phone_analyzer_helper.rb | Phonelib.PhoneAnalyzerHelper.number_match? | def number_match?(number, regex)
match = number.match(cr("^(?:#{regex})$"))
match && match.to_s.length == number.length
end | ruby | def number_match?(number, regex)
match = number.match(cr("^(?:#{regex})$"))
match && match.to_s.length == number.length
end | [
"def",
"number_match?",
"(",
"number",
",",
"regex",
")",
"match",
"=",
"number",
".",
"match",
"(",
"cr",
"(",
"\"^(?:#{regex})$\"",
")",
")",
"match",
"&&",
"match",
".",
"to_s",
".",
"length",
"==",
"number",
".",
"length",
"end"
] | Checks number against regex and compares match length
==== Attributes
* +number+ - phone number for validation
* +regex+ - regex for perfoming a validation | [
"Checks",
"number",
"against",
"regex",
"and",
"compares",
"match",
"length"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_analyzer_helper.rb#L203-L206 | train |
daddyz/phonelib | lib/phonelib/phone.rb | Phonelib.Phone.local_number | def local_number
return national unless possible?
format_match, format_string = formatting_data
if format_string =~ /^.*[0-9]+.*\$1/ && format_match
format_string.gsub(/^.*\$2/, '$2')
.gsub(/\$\d/) { |el| format_match[el[1].to_i] }
else
national
end
end | ruby | def local_number
return national unless possible?
format_match, format_string = formatting_data
if format_string =~ /^.*[0-9]+.*\$1/ && format_match
format_string.gsub(/^.*\$2/, '$2')
.gsub(/\$\d/) { |el| format_match[el[1].to_i] }
else
national
end
end | [
"def",
"local_number",
"return",
"national",
"unless",
"possible?",
"format_match",
",",
"format_string",
"=",
"formatting_data",
"if",
"format_string",
"=~",
"/",
"\\$",
"/",
"&&",
"format_match",
"format_string",
".",
"gsub",
"(",
"/",
"\\$",
"/",
",",
"'$2'",... | returns local number
@return [String] local number | [
"returns",
"local",
"number"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone.rb#L140-L150 | train |
daddyz/phonelib | lib/phonelib/phone.rb | Phonelib.Phone.valid_for_country? | def valid_for_country?(country)
country = country.to_s.upcase
tdata = analyze(sanitized, passed_country(country))
tdata.find do |iso2, data|
country == iso2 && data[:valid].any?
end.is_a? Array
end | ruby | def valid_for_country?(country)
country = country.to_s.upcase
tdata = analyze(sanitized, passed_country(country))
tdata.find do |iso2, data|
country == iso2 && data[:valid].any?
end.is_a? Array
end | [
"def",
"valid_for_country?",
"(",
"country",
")",
"country",
"=",
"country",
".",
"to_s",
".",
"upcase",
"tdata",
"=",
"analyze",
"(",
"sanitized",
",",
"passed_country",
"(",
"country",
")",
")",
"tdata",
".",
"find",
"do",
"|",
"iso2",
",",
"data",
"|"... | Returns whether a current parsed phone number is valid for specified
country
@param country [String|Symbol] ISO code of country (2 letters) like 'US',
'us' or :us for United States
@return [Boolean] parsed phone number is valid | [
"Returns",
"whether",
"a",
"current",
"parsed",
"phone",
"number",
"is",
"valid",
"for",
"specified",
"country"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone.rb#L157-L163 | train |
daddyz/phonelib | lib/phonelib/data_importer_helper.rb | Phonelib.DataImporterHelper.save_data_file | def save_data_file
File.open(file_path(Phonelib::Core::FILE_MAIN_DATA), 'wb+') do |f|
Marshal.dump(@data, f)
end
end | ruby | def save_data_file
File.open(file_path(Phonelib::Core::FILE_MAIN_DATA), 'wb+') do |f|
Marshal.dump(@data, f)
end
end | [
"def",
"save_data_file",
"File",
".",
"open",
"(",
"file_path",
"(",
"Phonelib",
"::",
"Core",
"::",
"FILE_MAIN_DATA",
")",
",",
"'wb+'",
")",
"do",
"|",
"f",
"|",
"Marshal",
".",
"dump",
"(",
"@data",
",",
"f",
")",
"end",
"end"
] | method saves parsed data to data files | [
"method",
"saves",
"parsed",
"data",
"to",
"data",
"files"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/data_importer_helper.rb#L14-L18 | train |
daddyz/phonelib | lib/phonelib/data_importer_helper.rb | Phonelib.DataImporterHelper.save_extended_data_file | def save_extended_data_file
extended = {
Phonelib::Core::EXT_PREFIXES => @prefixes,
Phonelib::Core::EXT_GEO_NAMES => @geo_names,
Phonelib::Core::EXT_COUNTRY_NAMES => @countries,
Phonelib::Core::EXT_TIMEZONES => @timezones,
Phonelib::Core::EXT_CARRIERS => @carriers
}
... | ruby | def save_extended_data_file
extended = {
Phonelib::Core::EXT_PREFIXES => @prefixes,
Phonelib::Core::EXT_GEO_NAMES => @geo_names,
Phonelib::Core::EXT_COUNTRY_NAMES => @countries,
Phonelib::Core::EXT_TIMEZONES => @timezones,
Phonelib::Core::EXT_CARRIERS => @carriers
}
... | [
"def",
"save_extended_data_file",
"extended",
"=",
"{",
"Phonelib",
"::",
"Core",
"::",
"EXT_PREFIXES",
"=>",
"@prefixes",
",",
"Phonelib",
"::",
"Core",
"::",
"EXT_GEO_NAMES",
"=>",
"@geo_names",
",",
"Phonelib",
"::",
"Core",
"::",
"EXT_COUNTRY_NAMES",
"=>",
"... | method saves extended data file | [
"method",
"saves",
"extended",
"data",
"file"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/data_importer_helper.rb#L21-L33 | train |
daddyz/phonelib | lib/phonelib/data_importer_helper.rb | Phonelib.DataImporterHelper.fill_prefixes | def fill_prefixes(key, value, prefix, prefixes)
prefixes = {} if prefixes.nil?
if prefix.size == 1
pr = prefix.to_i
prefixes[pr] ||= {}
prefixes[pr][key] = value
else
pr = prefix[0].to_i
prefixes[pr] = fill_prefixes(key, value, prefix[1..-1], prefixes[pr])
... | ruby | def fill_prefixes(key, value, prefix, prefixes)
prefixes = {} if prefixes.nil?
if prefix.size == 1
pr = prefix.to_i
prefixes[pr] ||= {}
prefixes[pr][key] = value
else
pr = prefix[0].to_i
prefixes[pr] = fill_prefixes(key, value, prefix[1..-1], prefixes[pr])
... | [
"def",
"fill_prefixes",
"(",
"key",
",",
"value",
",",
"prefix",
",",
"prefixes",
")",
"prefixes",
"=",
"{",
"}",
"if",
"prefixes",
".",
"nil?",
"if",
"prefix",
".",
"size",
"==",
"1",
"pr",
"=",
"prefix",
".",
"to_i",
"prefixes",
"[",
"pr",
"]",
"... | method updates prefixes hash recursively | [
"method",
"updates",
"prefixes",
"hash",
"recursively"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/data_importer_helper.rb#L36-L47 | train |
daddyz/phonelib | lib/phonelib/data_importer_helper.rb | Phonelib.DataImporterHelper.parse_raw_file | def parse_raw_file(file)
data = {}
File.readlines(file).each do |line|
line = str_clean line, false
next if line.empty? || line[0] == '#'
prefix, line_data = line.split('|')
data[prefix] = line_data && line_data.strip.split('&')
end
data
end | ruby | def parse_raw_file(file)
data = {}
File.readlines(file).each do |line|
line = str_clean line, false
next if line.empty? || line[0] == '#'
prefix, line_data = line.split('|')
data[prefix] = line_data && line_data.strip.split('&')
end
data
end | [
"def",
"parse_raw_file",
"(",
"file",
")",
"data",
"=",
"{",
"}",
"File",
".",
"readlines",
"(",
"file",
")",
".",
"each",
"do",
"|",
"line",
"|",
"line",
"=",
"str_clean",
"line",
",",
"false",
"next",
"if",
"line",
".",
"empty?",
"||",
"line",
"[... | method parses raw data file | [
"method",
"parses",
"raw",
"data",
"file"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/data_importer_helper.rb#L98-L107 | train |
daddyz/phonelib | lib/phonelib/data_importer_helper.rb | Phonelib.DataImporterHelper.main_from_xml | def main_from_xml(file)
xml_data = File.read(file)
xml_data.force_encoding('utf-8')
doc = Nokogiri::XML(xml_data)
doc.elements.first.elements.first
end | ruby | def main_from_xml(file)
xml_data = File.read(file)
xml_data.force_encoding('utf-8')
doc = Nokogiri::XML(xml_data)
doc.elements.first.elements.first
end | [
"def",
"main_from_xml",
"(",
"file",
")",
"xml_data",
"=",
"File",
".",
"read",
"(",
"file",
")",
"xml_data",
".",
"force_encoding",
"(",
"'utf-8'",
")",
"doc",
"=",
"Nokogiri",
"::",
"XML",
"(",
"xml_data",
")",
"doc",
".",
"elements",
".",
"first",
"... | get main body from parsed xml document | [
"get",
"main",
"body",
"from",
"parsed",
"xml",
"document"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/data_importer_helper.rb#L110-L116 | train |
daddyz/phonelib | lib/phonelib/phone_formatter.rb | Phonelib.PhoneFormatter.national | def national(formatted = true)
return @national_number unless valid?
format_match, format_string = formatting_data
if format_match
out = format_string.gsub(/\$\d/) { |el| format_match[el[1].to_i] }
formatted ? out : out.gsub(/[^0-9]/, '')
else
@national_number
end
... | ruby | def national(formatted = true)
return @national_number unless valid?
format_match, format_string = formatting_data
if format_match
out = format_string.gsub(/\$\d/) { |el| format_match[el[1].to_i] }
formatted ? out : out.gsub(/[^0-9]/, '')
else
@national_number
end
... | [
"def",
"national",
"(",
"formatted",
"=",
"true",
")",
"return",
"@national_number",
"unless",
"valid?",
"format_match",
",",
"format_string",
"=",
"formatting_data",
"if",
"format_match",
"out",
"=",
"format_string",
".",
"gsub",
"(",
"/",
"\\$",
"\\d",
"/",
... | Returns formatted national number
@param formatted [Boolean] whether to return numbers only or formatted
@return [String] formatted national number | [
"Returns",
"formatted",
"national",
"number"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_formatter.rb#L7-L17 | train |
daddyz/phonelib | lib/phonelib/phone_formatter.rb | Phonelib.PhoneFormatter.raw_national | def raw_national
return nil if sanitized.nil? || sanitized.empty?
if valid?
@national_number
elsif country_code && sanitized.start_with?(country_code)
sanitized[country_code.size..-1]
else
sanitized
end
end | ruby | def raw_national
return nil if sanitized.nil? || sanitized.empty?
if valid?
@national_number
elsif country_code && sanitized.start_with?(country_code)
sanitized[country_code.size..-1]
else
sanitized
end
end | [
"def",
"raw_national",
"return",
"nil",
"if",
"sanitized",
".",
"nil?",
"||",
"sanitized",
".",
"empty?",
"if",
"valid?",
"@national_number",
"elsif",
"country_code",
"&&",
"sanitized",
".",
"start_with?",
"(",
"country_code",
")",
"sanitized",
"[",
"country_code"... | Returns the raw national number that was defined during parsing
@return [String] raw national number | [
"Returns",
"the",
"raw",
"national",
"number",
"that",
"was",
"defined",
"during",
"parsing"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_formatter.rb#L21-L30 | train |
daddyz/phonelib | lib/phonelib/phone_formatter.rb | Phonelib.PhoneFormatter.international | def international(formatted = true, prefix = '+')
prefix = formatted if formatted.is_a?(String)
return nil if sanitized.empty?
return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless valid?
return country_code + @national_number unless formatted
fmt = @data[country][:format]
n... | ruby | def international(formatted = true, prefix = '+')
prefix = formatted if formatted.is_a?(String)
return nil if sanitized.empty?
return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless valid?
return country_code + @national_number unless formatted
fmt = @data[country][:format]
n... | [
"def",
"international",
"(",
"formatted",
"=",
"true",
",",
"prefix",
"=",
"'+'",
")",
"prefix",
"=",
"formatted",
"if",
"formatted",
".",
"is_a?",
"(",
"String",
")",
"return",
"nil",
"if",
"sanitized",
".",
"empty?",
"return",
"\"#{prefix}#{country_prefix_or... | Returns e164 formatted phone number. Method can receive single string parameter that will be defined as prefix
@param formatted [Boolean] whether to return numbers only or formatted
@param prefix [String] prefix to be placed before the number, "+" by default
@return [String] formatted international number | [
"Returns",
"e164",
"formatted",
"phone",
"number",
".",
"Method",
"can",
"receive",
"single",
"string",
"parameter",
"that",
"will",
"be",
"defined",
"as",
"prefix"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_formatter.rb#L43-L57 | train |
daddyz/phonelib | lib/phonelib/phone_formatter.rb | Phonelib.PhoneFormatter.area_code | def area_code
return nil unless area_code_possible?
format_match, _format_string = formatting_data
take_group = 1
if type == Core::MOBILE && Core::AREA_CODE_MOBILE_TOKENS[country] && \
format_match[1] == Core::AREA_CODE_MOBILE_TOKENS[country]
take_group = 2
end
form... | ruby | def area_code
return nil unless area_code_possible?
format_match, _format_string = formatting_data
take_group = 1
if type == Core::MOBILE && Core::AREA_CODE_MOBILE_TOKENS[country] && \
format_match[1] == Core::AREA_CODE_MOBILE_TOKENS[country]
take_group = 2
end
form... | [
"def",
"area_code",
"return",
"nil",
"unless",
"area_code_possible?",
"format_match",
",",
"_format_string",
"=",
"formatting_data",
"take_group",
"=",
"1",
"if",
"type",
"==",
"Core",
"::",
"MOBILE",
"&&",
"Core",
"::",
"AREA_CODE_MOBILE_TOKENS",
"[",
"country",
... | returns area code of parsed number
@return [String|nil] parsed phone area code if available | [
"returns",
"area",
"code",
"of",
"parsed",
"number"
] | aa0023eab7c896b71275bf342bc7f49735cbdbbf | https://github.com/daddyz/phonelib/blob/aa0023eab7c896b71275bf342bc7f49735cbdbbf/lib/phonelib/phone_formatter.rb#L89-L99 | train |
ruby/psych | lib/psych/scalar_scanner.rb | Psych.ScalarScanner.tokenize | def tokenize string
return nil if string.empty?
return string if @string_cache.key?(string)
return @symbol_cache[string] if @symbol_cache.key?(string)
case string
# Check for a String type, being careful not to get caught by hash keys, hex values, and
# special floats (e.g., -.inf).... | ruby | def tokenize string
return nil if string.empty?
return string if @string_cache.key?(string)
return @symbol_cache[string] if @symbol_cache.key?(string)
case string
# Check for a String type, being careful not to get caught by hash keys, hex values, and
# special floats (e.g., -.inf).... | [
"def",
"tokenize",
"string",
"return",
"nil",
"if",
"string",
".",
"empty?",
"return",
"string",
"if",
"@string_cache",
".",
"key?",
"(",
"string",
")",
"return",
"@symbol_cache",
"[",
"string",
"]",
"if",
"@symbol_cache",
".",
"key?",
"(",
"string",
")",
... | Create a new scanner
Tokenize +string+ returning the Ruby object | [
"Create",
"a",
"new",
"scanner",
"Tokenize",
"+",
"string",
"+",
"returning",
"the",
"Ruby",
"object"
] | f3a37e6bc1c2a98bfc9fafc389ea05622c744af9 | https://github.com/ruby/psych/blob/f3a37e6bc1c2a98bfc9fafc389ea05622c744af9/lib/psych/scalar_scanner.rb#L32-L111 | train |
ruby/psych | lib/psych/scalar_scanner.rb | Psych.ScalarScanner.parse_time | def parse_time string
klass = class_loader.load 'Time'
date, time = *(string.split(/[ tT]/, 2))
(yy, m, dd) = date.match(/^(-?\d{4})-(\d{1,2})-(\d{1,2})/).captures.map { |x| x.to_i }
md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
(hh, mm, ss) = md[1].split(':').map {... | ruby | def parse_time string
klass = class_loader.load 'Time'
date, time = *(string.split(/[ tT]/, 2))
(yy, m, dd) = date.match(/^(-?\d{4})-(\d{1,2})-(\d{1,2})/).captures.map { |x| x.to_i }
md = time.match(/(\d+:\d+:\d+)(?:\.(\d*))?\s*(Z|[-+]\d+(:\d\d)?)?/)
(hh, mm, ss) = md[1].split(':').map {... | [
"def",
"parse_time",
"string",
"klass",
"=",
"class_loader",
".",
"load",
"'Time'",
"date",
",",
"time",
"=",
"(",
"string",
".",
"split",
"(",
"/",
"/",
",",
"2",
")",
")",
"(",
"yy",
",",
"m",
",",
"dd",
")",
"=",
"date",
".",
"match",
"(",
"... | Parse and return a Time from +string+ | [
"Parse",
"and",
"return",
"a",
"Time",
"from",
"+",
"string",
"+"
] | f3a37e6bc1c2a98bfc9fafc389ea05622c744af9 | https://github.com/ruby/psych/blob/f3a37e6bc1c2a98bfc9fafc389ea05622c744af9/lib/psych/scalar_scanner.rb#L122-L147 | train |
ruby/psych | lib/psych/tree_builder.rb | Psych.TreeBuilder.start_document | def start_document version, tag_directives, implicit
n = Nodes::Document.new version, tag_directives, implicit
set_start_location(n)
@last.children << n
push n
end | ruby | def start_document version, tag_directives, implicit
n = Nodes::Document.new version, tag_directives, implicit
set_start_location(n)
@last.children << n
push n
end | [
"def",
"start_document",
"version",
",",
"tag_directives",
",",
"implicit",
"n",
"=",
"Nodes",
"::",
"Document",
".",
"new",
"version",
",",
"tag_directives",
",",
"implicit",
"set_start_location",
"(",
"n",
")",
"@last",
".",
"children",
"<<",
"n",
"push",
... | Handles start_document events with +version+, +tag_directives+,
and +implicit+ styling.
See Psych::Handler#start_document | [
"Handles",
"start_document",
"events",
"with",
"+",
"version",
"+",
"+",
"tag_directives",
"+",
"and",
"+",
"implicit",
"+",
"styling",
"."
] | f3a37e6bc1c2a98bfc9fafc389ea05622c744af9 | https://github.com/ruby/psych/blob/f3a37e6bc1c2a98bfc9fafc389ea05622c744af9/lib/psych/tree_builder.rb#L65-L70 | train |
ruby/psych | lib/psych/tree_builder.rb | Psych.TreeBuilder.end_document | def end_document implicit_end = !streaming?
@last.implicit_end = implicit_end
n = pop
set_end_location(n)
n
end | ruby | def end_document implicit_end = !streaming?
@last.implicit_end = implicit_end
n = pop
set_end_location(n)
n
end | [
"def",
"end_document",
"implicit_end",
"=",
"!",
"streaming?",
"@last",
".",
"implicit_end",
"=",
"implicit_end",
"n",
"=",
"pop",
"set_end_location",
"(",
"n",
")",
"n",
"end"
] | Handles end_document events with +version+, +tag_directives+,
and +implicit+ styling.
See Psych::Handler#start_document | [
"Handles",
"end_document",
"events",
"with",
"+",
"version",
"+",
"+",
"tag_directives",
"+",
"and",
"+",
"implicit",
"+",
"styling",
"."
] | f3a37e6bc1c2a98bfc9fafc389ea05622c744af9 | https://github.com/ruby/psych/blob/f3a37e6bc1c2a98bfc9fafc389ea05622c744af9/lib/psych/tree_builder.rb#L77-L82 | train |
etewiah/property_web_builder | app/controllers/pwb/api/v1/translations_controller.rb | Pwb.Api::V1::TranslationsController.delete_translation_values | def delete_translation_values
field_key = FieldKey.find_by_global_key(params[:i18n_key])
field_key.visible = false
# not convinced it makes sense to delete the associated translations
# phrases = I18n::Backend::ActiveRecord::Translation.where(:key => params[:i18n_key])
# phrases.destroy_a... | ruby | def delete_translation_values
field_key = FieldKey.find_by_global_key(params[:i18n_key])
field_key.visible = false
# not convinced it makes sense to delete the associated translations
# phrases = I18n::Backend::ActiveRecord::Translation.where(:key => params[:i18n_key])
# phrases.destroy_a... | [
"def",
"delete_translation_values",
"field_key",
"=",
"FieldKey",
".",
"find_by_global_key",
"(",
"params",
"[",
":i18n_key",
"]",
")",
"field_key",
".",
"visible",
"=",
"false",
"# not convinced it makes sense to delete the associated translations",
"# phrases = I18n::Backend:... | deletes the field_key referencing the translation | [
"deletes",
"the",
"field_key",
"referencing",
"the",
"translation"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/controllers/pwb/api/v1/translations_controller.rb#L49-L59 | train |
etewiah/property_web_builder | app/controllers/pwb/api/v1/translations_controller.rb | Pwb.Api::V1::TranslationsController.create_for_locale | def create_for_locale
field_key = FieldKey.find_by_global_key(params[:i18n_key])
phrase = I18n::Backend::ActiveRecord::Translation.find_or_create_by(
key: field_key.global_key,
locale: params[:locale]
)
unless phrase.value.present?
I18n.backend.reload!
phrase.value = para... | ruby | def create_for_locale
field_key = FieldKey.find_by_global_key(params[:i18n_key])
phrase = I18n::Backend::ActiveRecord::Translation.find_or_create_by(
key: field_key.global_key,
locale: params[:locale]
)
unless phrase.value.present?
I18n.backend.reload!
phrase.value = para... | [
"def",
"create_for_locale",
"field_key",
"=",
"FieldKey",
".",
"find_by_global_key",
"(",
"params",
"[",
":i18n_key",
"]",
")",
"phrase",
"=",
"I18n",
"::",
"Backend",
"::",
"ActiveRecord",
"::",
"Translation",
".",
"find_or_create_by",
"(",
"key",
":",
"field_k... | below for adding new locale to an existing translation | [
"below",
"for",
"adding",
"new",
"locale",
"to",
"an",
"existing",
"translation"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/controllers/pwb/api/v1/translations_controller.rb#L109-L121 | train |
etewiah/property_web_builder | app/controllers/pwb/search_controller.rb | Pwb.SearchController.buy | def buy
@page = Pwb::Page.find_by_slug "buy"
@page_title = @current_agency.company_name
# @content_to_show = []
if @page.present?
@page_title = @page.page_title + ' - ' + @current_agency.company_name
# TODO: - allow addition of custom content
# @page.ordered_visible_page_... | ruby | def buy
@page = Pwb::Page.find_by_slug "buy"
@page_title = @current_agency.company_name
# @content_to_show = []
if @page.present?
@page_title = @page.page_title + ' - ' + @current_agency.company_name
# TODO: - allow addition of custom content
# @page.ordered_visible_page_... | [
"def",
"buy",
"@page",
"=",
"Pwb",
"::",
"Page",
".",
"find_by_slug",
"\"buy\"",
"@page_title",
"=",
"@current_agency",
".",
"company_name",
"# @content_to_show = []",
"if",
"@page",
".",
"present?",
"@page_title",
"=",
"@page",
".",
"page_title",
"+",
"' - '",
... | ordering of results happens client-side with paloma search.js | [
"ordering",
"of",
"results",
"happens",
"client",
"-",
"side",
"with",
"paloma",
"search",
".",
"js"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/controllers/pwb/search_controller.rb#L33-L75 | train |
etewiah/property_web_builder | app/models/pwb/prop.rb | Pwb.Prop.set_features= | def set_features=(features_json)
# return unless features_json.class == Hash
features_json.keys.each do |feature_key|
# TODO - create feature_key if its missing
if features_json[feature_key] == "true" || features_json[feature_key] == true
features.find_or_create_by( feature_key: fe... | ruby | def set_features=(features_json)
# return unless features_json.class == Hash
features_json.keys.each do |feature_key|
# TODO - create feature_key if its missing
if features_json[feature_key] == "true" || features_json[feature_key] == true
features.find_or_create_by( feature_key: fe... | [
"def",
"set_features",
"=",
"(",
"features_json",
")",
"# return unless features_json.class == Hash",
"features_json",
".",
"keys",
".",
"each",
"do",
"|",
"feature_key",
"|",
"# TODO - create feature_key if its missing",
"if",
"features_json",
"[",
"feature_key",
"]",
"=... | Setter- called by update_extras in properties controller
expects a hash with keys like "cl.casafactory.fieldLabels.extras.alarma"
each with a value of true or false | [
"Setter",
"-",
"called",
"by",
"update_extras",
"in",
"properties",
"controller",
"expects",
"a",
"hash",
"with",
"keys",
"like",
"cl",
".",
"casafactory",
".",
"fieldLabels",
".",
"extras",
".",
"alarma",
"each",
"with",
"a",
"value",
"of",
"true",
"or",
... | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/models/pwb/prop.rb#L113-L123 | train |
etewiah/property_web_builder | app/models/pwb/prop.rb | Pwb.Prop.contextual_price_with_currency | def contextual_price_with_currency(rent_or_sale)
contextual_price = self.contextual_price rent_or_sale
if contextual_price.zero?
return nil
else
return contextual_price.format(no_cents: true)
end
# return contextual_price.zero? ? nil : contextual_price.format(:no_cents => ... | ruby | def contextual_price_with_currency(rent_or_sale)
contextual_price = self.contextual_price rent_or_sale
if contextual_price.zero?
return nil
else
return contextual_price.format(no_cents: true)
end
# return contextual_price.zero? ? nil : contextual_price.format(:no_cents => ... | [
"def",
"contextual_price_with_currency",
"(",
"rent_or_sale",
")",
"contextual_price",
"=",
"self",
".",
"contextual_price",
"rent_or_sale",
"if",
"contextual_price",
".",
"zero?",
"return",
"nil",
"else",
"return",
"contextual_price",
".",
"format",
"(",
"no_cents",
... | will return nil if price is 0 | [
"will",
"return",
"nil",
"if",
"price",
"is",
"0"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/models/pwb/prop.rb#L211-L220 | train |
etewiah/property_web_builder | app/controllers/pwb/api/v1/web_contents_controller.rb | Pwb.Api::V1::WebContentsController.update_photo | def update_photo
content_tag = params[:content_tag]
# photo = ContentPhoto.find(params[:id])
# find would throw error if not found
photo = ContentPhoto.find_by_id(params[:id])
unless photo
if content_tag
# where photo has never been set before, associated Content will not... | ruby | def update_photo
content_tag = params[:content_tag]
# photo = ContentPhoto.find(params[:id])
# find would throw error if not found
photo = ContentPhoto.find_by_id(params[:id])
unless photo
if content_tag
# where photo has never been set before, associated Content will not... | [
"def",
"update_photo",
"content_tag",
"=",
"params",
"[",
":content_tag",
"]",
"# photo = ContentPhoto.find(params[:id])",
"# find would throw error if not found",
"photo",
"=",
"ContentPhoto",
".",
"find_by_id",
"(",
"params",
"[",
":id",
"]",
")",
"unless",
"photo",
"... | below is used by logo_photo and about_us_photo,
where only one photo is allowed | [
"below",
"is",
"used",
"by",
"logo_photo",
"and",
"about_us_photo",
"where",
"only",
"one",
"photo",
"is",
"allowed"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/controllers/pwb/api/v1/web_contents_controller.rb#L9-L35 | train |
etewiah/property_web_builder | app/controllers/pwb/api/v1/web_contents_controller.rb | Pwb.Api::V1::WebContentsController.create_content_with_photo | def create_content_with_photo
tag = params[:tag]
photo = ContentPhoto.create
key = tag.underscore.camelize + photo.id.to_s
new_content = Content.create(tag: tag, key: key)
# photo.subdomain = subdomain
# photo.folder = current_tenant_model.whitelabel_country_code
# photo.tena... | ruby | def create_content_with_photo
tag = params[:tag]
photo = ContentPhoto.create
key = tag.underscore.camelize + photo.id.to_s
new_content = Content.create(tag: tag, key: key)
# photo.subdomain = subdomain
# photo.folder = current_tenant_model.whitelabel_country_code
# photo.tena... | [
"def",
"create_content_with_photo",
"tag",
"=",
"params",
"[",
":tag",
"]",
"photo",
"=",
"ContentPhoto",
".",
"create",
"key",
"=",
"tag",
".",
"underscore",
".",
"camelize",
"+",
"photo",
".",
"id",
".",
"to_s",
"new_content",
"=",
"Content",
".",
"creat... | below used when uploading carousel images | [
"below",
"used",
"when",
"uploading",
"carousel",
"images"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/controllers/pwb/api/v1/web_contents_controller.rb#L38-L85 | train |
etewiah/property_web_builder | app/services/pwb/page_part_manager.rb | Pwb.PagePartManager.seed_container_block_content | def seed_container_block_content(locale, seed_content)
page_part_editor_setup = page_part.editor_setup
raise "Invalid editorBlocks for page_part_editor_setup" unless page_part_editor_setup && page_part_editor_setup["editorBlocks"].present?
# page = page_part.page
# page_part_key uniquely identif... | ruby | def seed_container_block_content(locale, seed_content)
page_part_editor_setup = page_part.editor_setup
raise "Invalid editorBlocks for page_part_editor_setup" unless page_part_editor_setup && page_part_editor_setup["editorBlocks"].present?
# page = page_part.page
# page_part_key uniquely identif... | [
"def",
"seed_container_block_content",
"(",
"locale",
",",
"seed_content",
")",
"page_part_editor_setup",
"=",
"page_part",
".",
"editor_setup",
"raise",
"\"Invalid editorBlocks for page_part_editor_setup\"",
"unless",
"page_part_editor_setup",
"&&",
"page_part_editor_setup",
"["... | seed_content is ... | [
"seed_content",
"is",
"..."
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/services/pwb/page_part_manager.rb#L56-L97 | train |
etewiah/property_web_builder | app/services/pwb/page_part_manager.rb | Pwb.PagePartManager.set_page_part_block_contents | def set_page_part_block_contents(_page_part_key, locale, fragment_details)
# page_part = self.page_parts.find_by_page_part_key page_part_key
if page_part.present?
page_part.block_contents[locale] = fragment_details
page_part.save!
# fragment_details passed in might be a params object... | ruby | def set_page_part_block_contents(_page_part_key, locale, fragment_details)
# page_part = self.page_parts.find_by_page_part_key page_part_key
if page_part.present?
page_part.block_contents[locale] = fragment_details
page_part.save!
# fragment_details passed in might be a params object... | [
"def",
"set_page_part_block_contents",
"(",
"_page_part_key",
",",
"locale",
",",
"fragment_details",
")",
"# page_part = self.page_parts.find_by_page_part_key page_part_key",
"if",
"page_part",
".",
"present?",
"page_part",
".",
"block_contents",
"[",
"locale",
"]",
"=",
"... | set block contents
on page_part model | [
"set",
"block",
"contents",
"on",
"page_part",
"model"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/services/pwb/page_part_manager.rb#L138-L149 | train |
etewiah/property_web_builder | app/services/pwb/page_part_manager.rb | Pwb.PagePartManager.rebuild_page_content | def rebuild_page_content(locale)
unless page_part && page_part.template
raise "page_part with valid template not available"
end
# page_part = self.page_parts.find_by_page_part_key page_part_key
if page_part.present?
l_template = Liquid::Template.parse(page_part.template)
... | ruby | def rebuild_page_content(locale)
unless page_part && page_part.template
raise "page_part with valid template not available"
end
# page_part = self.page_parts.find_by_page_part_key page_part_key
if page_part.present?
l_template = Liquid::Template.parse(page_part.template)
... | [
"def",
"rebuild_page_content",
"(",
"locale",
")",
"unless",
"page_part",
"&&",
"page_part",
".",
"template",
"raise",
"\"page_part with valid template not available\"",
"end",
"# page_part = self.page_parts.find_by_page_part_key page_part_key",
"if",
"page_part",
".",
"present?"... | Will retrieve saved page_part blocks and use that along with template
to rebuild page_content html | [
"Will",
"retrieve",
"saved",
"page_part",
"blocks",
"and",
"use",
"that",
"along",
"with",
"template",
"to",
"rebuild",
"page_content",
"html"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/services/pwb/page_part_manager.rb#L153-L183 | train |
etewiah/property_web_builder | app/services/pwb/page_part_manager.rb | Pwb.PagePartManager.seed_fragment_photo | def seed_fragment_photo(block_label, photo_file)
# content_key = self.slug + "_" + page_part_key
# get in content model associated with page and fragment
# join_model = page_contents.find_or_create_by(page_part_key: page_part_key)
# page_fragment_content = join_model.create_content(page_part_key... | ruby | def seed_fragment_photo(block_label, photo_file)
# content_key = self.slug + "_" + page_part_key
# get in content model associated with page and fragment
# join_model = page_contents.find_or_create_by(page_part_key: page_part_key)
# page_fragment_content = join_model.create_content(page_part_key... | [
"def",
"seed_fragment_photo",
"(",
"block_label",
",",
"photo_file",
")",
"# content_key = self.slug + \"_\" + page_part_key",
"# get in content model associated with page and fragment",
"# join_model = page_contents.find_or_create_by(page_part_key: page_part_key)",
"# page_fragment_content = jo... | when seeding I only need to ensure that a photo exists for the fragment
so will return existing photo if it can be found | [
"when",
"seeding",
"I",
"only",
"need",
"to",
"ensure",
"that",
"a",
"photo",
"exists",
"for",
"the",
"fragment",
"so",
"will",
"return",
"existing",
"photo",
"if",
"it",
"can",
"be",
"found"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/services/pwb/page_part_manager.rb#L187-L223 | train |
etewiah/property_web_builder | app/models/pwb/website.rb | Pwb.Website.get_element_class | def get_element_class(element_name)
style_details = style_variables_for_theme["vic"] || Pwb::PresetStyle.default_values
style_associations = style_details["associations"] || []
style_associations[element_name] || ""
end | ruby | def get_element_class(element_name)
style_details = style_variables_for_theme["vic"] || Pwb::PresetStyle.default_values
style_associations = style_details["associations"] || []
style_associations[element_name] || ""
end | [
"def",
"get_element_class",
"(",
"element_name",
")",
"style_details",
"=",
"style_variables_for_theme",
"[",
"\"vic\"",
"]",
"||",
"Pwb",
"::",
"PresetStyle",
".",
"default_values",
"style_associations",
"=",
"style_details",
"[",
"\"associations\"",
"]",
"||",
"[",
... | spt 2017 - above 2 will be redundant once vic becomes default layout
below used when rendering to decide which class names
to use for which elements | [
"spt",
"2017",
"-",
"above",
"2",
"will",
"be",
"redundant",
"once",
"vic",
"becomes",
"default",
"layout",
"below",
"used",
"when",
"rendering",
"to",
"decide",
"which",
"class",
"names",
"to",
"use",
"for",
"which",
"elements"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/models/pwb/website.rb#L152-L156 | train |
etewiah/property_web_builder | app/models/pwb/website.rb | Pwb.Website.style_settings_from_preset= | def style_settings_from_preset=(preset_style_name)
preset_style = Pwb::PresetStyle.where(name: preset_style_name).first
if preset_style
style_variables_for_theme["vic"] = preset_style.attributes.as_json
end
end | ruby | def style_settings_from_preset=(preset_style_name)
preset_style = Pwb::PresetStyle.where(name: preset_style_name).first
if preset_style
style_variables_for_theme["vic"] = preset_style.attributes.as_json
end
end | [
"def",
"style_settings_from_preset",
"=",
"(",
"preset_style_name",
")",
"preset_style",
"=",
"Pwb",
"::",
"PresetStyle",
".",
"where",
"(",
"name",
":",
"preset_style_name",
")",
".",
"first",
"if",
"preset_style",
"style_variables_for_theme",
"[",
"\"vic\"",
"]",
... | allow setting of styles to a preset config from admin UI | [
"allow",
"setting",
"of",
"styles",
"to",
"a",
"preset",
"config",
"from",
"admin",
"UI"
] | fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21 | https://github.com/etewiah/property_web_builder/blob/fba4e6d4ffa7bc1f4d3b50dfa5a6a9fbfee23f21/app/models/pwb/website.rb#L172-L177 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.invoke_question | def invoke_question(object, message, *args, &block)
options = Utils.extract_options!(args)
options[:messages] = self.class.messages
question = object.new(self, options)
question.(message, &block)
end | ruby | def invoke_question(object, message, *args, &block)
options = Utils.extract_options!(args)
options[:messages] = self.class.messages
question = object.new(self, options)
question.(message, &block)
end | [
"def",
"invoke_question",
"(",
"object",
",",
"message",
",",
"*",
"args",
",",
"&",
"block",
")",
"options",
"=",
"Utils",
".",
"extract_options!",
"(",
"args",
")",
"options",
"[",
":messages",
"]",
"=",
"self",
".",
"class",
".",
"messages",
"question... | Initialize a Prompt
@param [Hash] options
@option options [IO] :input
the input stream
@option options [IO] :output
the output stream
@option options [Hash] :env
the environment variables
@option options [String] :prefix
the prompt prefix, by default empty
@option options [Boolean] :enable_color
e... | [
"Initialize",
"a",
"Prompt"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L164-L169 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.invoke_select | def invoke_select(object, question, *args, &block)
options = Utils.extract_options!(args)
choices = if block
[]
elsif args.empty?
possible = options.dup
options = {}
possible
elsif args.size == 1 && args[... | ruby | def invoke_select(object, question, *args, &block)
options = Utils.extract_options!(args)
choices = if block
[]
elsif args.empty?
possible = options.dup
options = {}
possible
elsif args.size == 1 && args[... | [
"def",
"invoke_select",
"(",
"object",
",",
"question",
",",
"*",
"args",
",",
"&",
"block",
")",
"options",
"=",
"Utils",
".",
"extract_options!",
"(",
"args",
")",
"choices",
"=",
"if",
"block",
"[",
"]",
"elsif",
"args",
".",
"empty?",
"possible",
"... | Invoke a list type of prompt
@example
prompt = TTY::Prompt.new
editors = %w(emacs nano vim)
prompt.invoke_select(EnumList, "Select editor: ", editors)
@return [String]
@api public | [
"Invoke",
"a",
"list",
"type",
"of",
"prompt"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L223-L239 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.yes? | def yes?(message, *args, &block)
defaults = { default: true }
options = Utils.extract_options!(args)
options.merge!(defaults.reject { |k, _| options.key?(k) })
question = ConfirmQuestion.new(self, options)
question.call(message, &block)
end | ruby | def yes?(message, *args, &block)
defaults = { default: true }
options = Utils.extract_options!(args)
options.merge!(defaults.reject { |k, _| options.key?(k) })
question = ConfirmQuestion.new(self, options)
question.call(message, &block)
end | [
"def",
"yes?",
"(",
"message",
",",
"*",
"args",
",",
"&",
"block",
")",
"defaults",
"=",
"{",
"default",
":",
"true",
"}",
"options",
"=",
"Utils",
".",
"extract_options!",
"(",
"args",
")",
"options",
".",
"merge!",
"(",
"defaults",
".",
"reject",
... | A shortcut method to ask the user positive question and return
true for 'yes' reply, false for 'no'.
@example
prompt = TTY::Prompt.new
prompt.yes?('Are you human?')
# => Are you human? (Y/n)
@return [Boolean]
@api public | [
"A",
"shortcut",
"method",
"to",
"ask",
"the",
"user",
"positive",
"question",
"and",
"return",
"true",
"for",
"yes",
"reply",
"false",
"for",
"no",
"."
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L329-L336 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.slider | def slider(question, *args, &block)
options = Utils.extract_options!(args)
slider = Slider.new(self, options)
slider.call(question, &block)
end | ruby | def slider(question, *args, &block)
options = Utils.extract_options!(args)
slider = Slider.new(self, options)
slider.call(question, &block)
end | [
"def",
"slider",
"(",
"question",
",",
"*",
"args",
",",
"&",
"block",
")",
"options",
"=",
"Utils",
".",
"extract_options!",
"(",
"args",
")",
"slider",
"=",
"Slider",
".",
"new",
"(",
"self",
",",
"options",
")",
"slider",
".",
"call",
"(",
"questi... | Ask a question with a range slider
@example
prompt = TTY::Prompt.new
prompt.slider('What size?', min: 32, max: 54, step: 2)
@param [String] question
the question to ask
@return [String]
@api public | [
"Ask",
"a",
"question",
"with",
"a",
"range",
"slider"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L393-L397 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.say | def say(message = '', options = {})
message = message.to_s
return if message.empty?
statement = Statement.new(self, options)
statement.call(message)
end | ruby | def say(message = '', options = {})
message = message.to_s
return if message.empty?
statement = Statement.new(self, options)
statement.call(message)
end | [
"def",
"say",
"(",
"message",
"=",
"''",
",",
"options",
"=",
"{",
"}",
")",
"message",
"=",
"message",
".",
"to_s",
"return",
"if",
"message",
".",
"empty?",
"statement",
"=",
"Statement",
".",
"new",
"(",
"self",
",",
"options",
")",
"statement",
"... | Print statement out. If the supplied message ends with a space or
tab character, a new line will not be appended.
@example
say("Simple things.", color: :red)
@param [String] message
@return [String]
@api public | [
"Print",
"statement",
"out",
".",
"If",
"the",
"supplied",
"message",
"ends",
"with",
"a",
"space",
"or",
"tab",
"character",
"a",
"new",
"line",
"will",
"not",
"be",
"appended",
"."
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L410-L416 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.debug | def debug(*messages)
longest = messages.max_by(&:length).size
width = TTY::Screen.width - longest
print cursor.save
messages.each_with_index do |msg, i|
print cursor.move_to(width, i)
print cursor.clear_line_after
print msg
end
print cursor.restore
end | ruby | def debug(*messages)
longest = messages.max_by(&:length).size
width = TTY::Screen.width - longest
print cursor.save
messages.each_with_index do |msg, i|
print cursor.move_to(width, i)
print cursor.clear_line_after
print msg
end
print cursor.restore
end | [
"def",
"debug",
"(",
"*",
"messages",
")",
"longest",
"=",
"messages",
".",
"max_by",
"(",
":length",
")",
".",
"size",
"width",
"=",
"TTY",
"::",
"Screen",
".",
"width",
"-",
"longest",
"print",
"cursor",
".",
"save",
"messages",
".",
"each_with_index",... | Print debug information in terminal top right corner
@example
prompt.debug "info1", "info2"
@param [Array] messages
@retrun [nil]
@api public | [
"Print",
"debug",
"information",
"in",
"terminal",
"top",
"right",
"corner"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L476-L486 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.suggest | def suggest(message, possibilities, options = {})
suggestion = Suggestion.new(options)
say(suggestion.suggest(message, possibilities))
end | ruby | def suggest(message, possibilities, options = {})
suggestion = Suggestion.new(options)
say(suggestion.suggest(message, possibilities))
end | [
"def",
"suggest",
"(",
"message",
",",
"possibilities",
",",
"options",
"=",
"{",
"}",
")",
"suggestion",
"=",
"Suggestion",
".",
"new",
"(",
"options",
")",
"say",
"(",
"suggestion",
".",
"suggest",
"(",
"message",
",",
"possibilities",
")",
")",
"end"
... | Takes the string provided by the user and compare it with other possible
matches to suggest an unambigous string
@example
prompt.suggest('sta', ['status', 'stage', 'commit', 'branch'])
# => "status, stage"
@param [String] message
@param [Array] possibilities
@param [Hash] options
@option options [String... | [
"Takes",
"the",
"string",
"provided",
"by",
"the",
"user",
"and",
"compare",
"it",
"with",
"other",
"possible",
"matches",
"to",
"suggest",
"an",
"unambigous",
"string"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L510-L513 | train |
piotrmurach/tty-prompt | lib/tty/prompt.rb | TTY.Prompt.collect | def collect(options = {}, &block)
collector = AnswersCollector.new(self, options)
collector.call(&block)
end | ruby | def collect(options = {}, &block)
collector = AnswersCollector.new(self, options)
collector.call(&block)
end | [
"def",
"collect",
"(",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"collector",
"=",
"AnswersCollector",
".",
"new",
"(",
"self",
",",
"options",
")",
"collector",
".",
"call",
"(",
"block",
")",
"end"
] | Gathers more than one aswer
@example
prompt.collect do
key(:name).ask('Name?')
end
@return [Hash]
the collection of answers
@api public | [
"Gathers",
"more",
"than",
"one",
"aswer"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt.rb#L526-L529 | train |
piotrmurach/tty-prompt | lib/tty/prompt/utils.rb | TTY.Utils.extract_options | def extract_options(args)
options = args.last
options.respond_to?(:to_hash) ? options.to_hash.dup : {}
end | ruby | def extract_options(args)
options = args.last
options.respond_to?(:to_hash) ? options.to_hash.dup : {}
end | [
"def",
"extract_options",
"(",
"args",
")",
"options",
"=",
"args",
".",
"last",
"options",
".",
"respond_to?",
"(",
":to_hash",
")",
"?",
"options",
".",
"to_hash",
".",
"dup",
":",
"{",
"}",
"end"
] | Extract options hash from array argument
@param [Array[Object]] args
@api public | [
"Extract",
"options",
"hash",
"from",
"array",
"argument"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt/utils.rb#L14-L17 | train |
piotrmurach/tty-prompt | lib/tty/prompt/utils.rb | TTY.Utils.blank? | def blank?(value)
value.nil? ||
value.respond_to?(:empty?) && value.empty? ||
BLANK_REGEX === value
end | ruby | def blank?(value)
value.nil? ||
value.respond_to?(:empty?) && value.empty? ||
BLANK_REGEX === value
end | [
"def",
"blank?",
"(",
"value",
")",
"value",
".",
"nil?",
"||",
"value",
".",
"respond_to?",
"(",
":empty?",
")",
"&&",
"value",
".",
"empty?",
"||",
"BLANK_REGEX",
"===",
"value",
"end"
] | Check if value is nil or an empty string
@param [Object] value
the value to check
@return [Boolean]
@api public | [
"Check",
"if",
"value",
"is",
"nil",
"or",
"an",
"empty",
"string"
] | b1ff627afff98fa6477e5ef3ac4a718c52eff05a | https://github.com/piotrmurach/tty-prompt/blob/b1ff627afff98fa6477e5ef3ac4a718c52eff05a/lib/tty/prompt/utils.rb#L31-L35 | train |
rails/spring | lib/spring/application.rb | Spring.Application.shush_backtraces | def shush_backtraces
Kernel.module_eval do
old_raise = Kernel.method(:raise)
remove_method :raise
define_method :raise do |*args|
begin
old_raise.call(*args)
ensure
if $!
lib = File.expand_path("..", __FILE__)
$!.backt... | ruby | def shush_backtraces
Kernel.module_eval do
old_raise = Kernel.method(:raise)
remove_method :raise
define_method :raise do |*args|
begin
old_raise.call(*args)
ensure
if $!
lib = File.expand_path("..", __FILE__)
$!.backt... | [
"def",
"shush_backtraces",
"Kernel",
".",
"module_eval",
"do",
"old_raise",
"=",
"Kernel",
".",
"method",
"(",
":raise",
")",
"remove_method",
":raise",
"define_method",
":raise",
"do",
"|",
"*",
"args",
"|",
"begin",
"old_raise",
".",
"call",
"(",
"args",
"... | This feels very naughty | [
"This",
"feels",
"very",
"naughty"
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/application.rb#L291-L307 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.decode | def decode(s)
ts = lex(s)
v, ts = textparse(ts)
if ts.length > 0
raise Error, 'trailing garbage'
end
v
end | ruby | def decode(s)
ts = lex(s)
v, ts = textparse(ts)
if ts.length > 0
raise Error, 'trailing garbage'
end
v
end | [
"def",
"decode",
"(",
"s",
")",
"ts",
"=",
"lex",
"(",
"s",
")",
"v",
",",
"ts",
"=",
"textparse",
"(",
"ts",
")",
"if",
"ts",
".",
"length",
">",
"0",
"raise",
"Error",
",",
"'trailing garbage'",
"end",
"v",
"end"
] | Decodes a json document in string s and
returns the corresponding ruby value.
String s must be valid UTF-8. If you have
a string in some other encoding, convert
it first.
String values in the resulting structure
will be UTF-8. | [
"Decodes",
"a",
"json",
"document",
"in",
"string",
"s",
"and",
"returns",
"the",
"corresponding",
"ruby",
"value",
".",
"String",
"s",
"must",
"be",
"valid",
"UTF",
"-",
"8",
".",
"If",
"you",
"have",
"a",
"string",
"in",
"some",
"other",
"encoding",
... | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L68-L75 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.objparse | def objparse(ts)
ts = eat('{', ts)
obj = {}
if ts[0][0] == '}'
return obj, ts[1..-1]
end
k, v, ts = pairparse(ts)
obj[k] = v
if ts[0][0] == '}'
return obj, ts[1..-1]
end
loop do
ts = eat(',', ts)
k, v, ts = pairparse(ts)
obj[k] = v
if ts[0][0... | ruby | def objparse(ts)
ts = eat('{', ts)
obj = {}
if ts[0][0] == '}'
return obj, ts[1..-1]
end
k, v, ts = pairparse(ts)
obj[k] = v
if ts[0][0] == '}'
return obj, ts[1..-1]
end
loop do
ts = eat(',', ts)
k, v, ts = pairparse(ts)
obj[k] = v
if ts[0][0... | [
"def",
"objparse",
"(",
"ts",
")",
"ts",
"=",
"eat",
"(",
"'{'",
",",
"ts",
")",
"obj",
"=",
"{",
"}",
"if",
"ts",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"'}'",
"return",
"obj",
",",
"ts",
"[",
"1",
"..",
"-",
"1",
"]",
"end",
"k",
",",
"v... | Parses an "object" in the sense of RFC 4627.
Returns the parsed value and any trailing tokens. | [
"Parses",
"an",
"object",
"in",
"the",
"sense",
"of",
"RFC",
"4627",
".",
"Returns",
"the",
"parsed",
"value",
"and",
"any",
"trailing",
"tokens",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L154-L179 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.pairparse | def pairparse(ts)
(typ, _, k), ts = ts[0], ts[1..-1]
if typ != :str
raise Error, "unexpected #{k.inspect}"
end
ts = eat(':', ts)
v, ts = valparse(ts)
[k, v, ts]
end | ruby | def pairparse(ts)
(typ, _, k), ts = ts[0], ts[1..-1]
if typ != :str
raise Error, "unexpected #{k.inspect}"
end
ts = eat(':', ts)
v, ts = valparse(ts)
[k, v, ts]
end | [
"def",
"pairparse",
"(",
"ts",
")",
"(",
"typ",
",",
"_",
",",
"k",
")",
",",
"ts",
"=",
"ts",
"[",
"0",
"]",
",",
"ts",
"[",
"1",
"..",
"-",
"1",
"]",
"if",
"typ",
"!=",
":str",
"raise",
"Error",
",",
"\"unexpected #{k.inspect}\"",
"end",
"ts"... | Parses a "member" in the sense of RFC 4627.
Returns the parsed values and any trailing tokens. | [
"Parses",
"a",
"member",
"in",
"the",
"sense",
"of",
"RFC",
"4627",
".",
"Returns",
"the",
"parsed",
"values",
"and",
"any",
"trailing",
"tokens",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L184-L192 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.arrparse | def arrparse(ts)
ts = eat('[', ts)
arr = []
if ts[0][0] == ']'
return arr, ts[1..-1]
end
v, ts = valparse(ts)
arr << v
if ts[0][0] == ']'
return arr, ts[1..-1]
end
loop do
ts = eat(',', ts)
v, ts = valparse(ts)
arr << v
if ts[0][0] == ']'
... | ruby | def arrparse(ts)
ts = eat('[', ts)
arr = []
if ts[0][0] == ']'
return arr, ts[1..-1]
end
v, ts = valparse(ts)
arr << v
if ts[0][0] == ']'
return arr, ts[1..-1]
end
loop do
ts = eat(',', ts)
v, ts = valparse(ts)
arr << v
if ts[0][0] == ']'
... | [
"def",
"arrparse",
"(",
"ts",
")",
"ts",
"=",
"eat",
"(",
"'['",
",",
"ts",
")",
"arr",
"=",
"[",
"]",
"if",
"ts",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"']'",
"return",
"arr",
",",
"ts",
"[",
"1",
"..",
"-",
"1",
"]",
"end",
"v",
",",
"t... | Parses an "array" in the sense of RFC 4627.
Returns the parsed value and any trailing tokens. | [
"Parses",
"an",
"array",
"in",
"the",
"sense",
"of",
"RFC",
"4627",
".",
"Returns",
"the",
"parsed",
"value",
"and",
"any",
"trailing",
"tokens",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L197-L222 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.tok | def tok(s)
case s[0]
when ?{ then ['{', s[0,1], s[0,1]]
when ?} then ['}', s[0,1], s[0,1]]
when ?: then [':', s[0,1], s[0,1]]
when ?, then [',', s[0,1], s[0,1]]
when ?[ then ['[', s[0,1], s[0,1]]
when ?] then [']', s[0,1], s[0,1]]
when ?n then nulltok(s)
when ?t then truetok(s)
w... | ruby | def tok(s)
case s[0]
when ?{ then ['{', s[0,1], s[0,1]]
when ?} then ['}', s[0,1], s[0,1]]
when ?: then [':', s[0,1], s[0,1]]
when ?, then [',', s[0,1], s[0,1]]
when ?[ then ['[', s[0,1], s[0,1]]
when ?] then [']', s[0,1], s[0,1]]
when ?n then nulltok(s)
when ?t then truetok(s)
w... | [
"def",
"tok",
"(",
"s",
")",
"case",
"s",
"[",
"0",
"]",
"when",
"?{",
"then",
"[",
"'{'",
",",
"s",
"[",
"0",
",",
"1",
"]",
",",
"s",
"[",
"0",
",",
"1",
"]",
"]",
"when",
"?}",
"then",
"[",
"'}'",
",",
"s",
"[",
"0",
",",
"1",
"]",... | Scans the first token in s and
returns a 3-element list, or nil
if s does not begin with a valid token.
The first list element is one of
'{', '}', ':', ',', '[', ']',
:val, :str, and :space.
The second element is the lexeme.
The third element is the value of the
token for :val and :str, otherwise
it is the ... | [
"Scans",
"the",
"first",
"token",
"in",
"s",
"and",
"returns",
"a",
"3",
"-",
"element",
"list",
"or",
"nil",
"if",
"s",
"does",
"not",
"begin",
"with",
"a",
"valid",
"token",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L264-L280 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.unquote | def unquote(q)
q = q[1...-1]
a = q.dup # allocate a big enough string
# In ruby >= 1.9, a[w] is a codepoint, not a byte.
if rubydoesenc?
a.force_encoding('UTF-8')
end
r, w = 0, 0
while r < q.length
c = q[r]
if c == ?\\
r += 1
if r >= q.length
raise... | ruby | def unquote(q)
q = q[1...-1]
a = q.dup # allocate a big enough string
# In ruby >= 1.9, a[w] is a codepoint, not a byte.
if rubydoesenc?
a.force_encoding('UTF-8')
end
r, w = 0, 0
while r < q.length
c = q[r]
if c == ?\\
r += 1
if r >= q.length
raise... | [
"def",
"unquote",
"(",
"q",
")",
"q",
"=",
"q",
"[",
"1",
"...",
"-",
"1",
"]",
"a",
"=",
"q",
".",
"dup",
"# allocate a big enough string",
"# In ruby >= 1.9, a[w] is a codepoint, not a byte.",
"if",
"rubydoesenc?",
"a",
".",
"force_encoding",
"(",
"'UTF-8'",
... | Converts a quoted json string literal q into a UTF-8-encoded string.
The rules are different than for Ruby, so we cannot use eval.
Unquote will raise an error if q contains control characters. | [
"Converts",
"a",
"quoted",
"json",
"string",
"literal",
"q",
"into",
"a",
"UTF",
"-",
"8",
"-",
"encoded",
"string",
".",
"The",
"rules",
"are",
"different",
"than",
"for",
"Ruby",
"so",
"we",
"cannot",
"use",
"eval",
".",
"Unquote",
"will",
"raise",
"... | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L325-L391 | train |
rails/spring | lib/spring/json.rb | Spring.OkJson.ucharenc | def ucharenc(a, i, u)
if u <= Uchar1max
a[i] = (u & 0xff).chr
1
elsif u <= Uchar2max
a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
a[i+1] = (Utagx | (u&Umaskx)).chr
2
elsif u <= Uchar3max
a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
a[i+... | ruby | def ucharenc(a, i, u)
if u <= Uchar1max
a[i] = (u & 0xff).chr
1
elsif u <= Uchar2max
a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
a[i+1] = (Utagx | (u&Umaskx)).chr
2
elsif u <= Uchar3max
a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
a[i+... | [
"def",
"ucharenc",
"(",
"a",
",",
"i",
",",
"u",
")",
"if",
"u",
"<=",
"Uchar1max",
"a",
"[",
"i",
"]",
"=",
"(",
"u",
"&",
"0xff",
")",
".",
"chr",
"1",
"elsif",
"u",
"<=",
"Uchar2max",
"a",
"[",
"i",
"+",
"0",
"]",
"=",
"(",
"Utag2",
"|... | Encodes unicode character u as UTF-8
bytes in string a at position i.
Returns the number of bytes written. | [
"Encodes",
"unicode",
"character",
"u",
"as",
"UTF",
"-",
"8",
"bytes",
"in",
"string",
"a",
"at",
"position",
"i",
".",
"Returns",
"the",
"number",
"of",
"bytes",
"written",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/json.rb#L397-L417 | train |
rails/spring | lib/spring/application_manager.rb | Spring.ApplicationManager.run | def run(client)
with_child do
child.send_io client
child.gets or raise Errno::EPIPE
end
pid = child.gets.to_i
unless pid.zero?
log "got worker pid #{pid}"
pid
end
rescue Errno::ECONNRESET, Errno::EPIPE => e
log "#{e} while reading from child; ret... | ruby | def run(client)
with_child do
child.send_io client
child.gets or raise Errno::EPIPE
end
pid = child.gets.to_i
unless pid.zero?
log "got worker pid #{pid}"
pid
end
rescue Errno::ECONNRESET, Errno::EPIPE => e
log "#{e} while reading from child; ret... | [
"def",
"run",
"(",
"client",
")",
"with_child",
"do",
"child",
".",
"send_io",
"client",
"child",
".",
"gets",
"or",
"raise",
"Errno",
"::",
"EPIPE",
"end",
"pid",
"=",
"child",
".",
"gets",
".",
"to_i",
"unless",
"pid",
".",
"zero?",
"log",
"\"got wor... | Returns the pid of the process running the command, or nil if the application process died. | [
"Returns",
"the",
"pid",
"of",
"the",
"process",
"running",
"the",
"command",
"or",
"nil",
"if",
"the",
"application",
"process",
"died",
"."
] | e7a36afa436fcc59b6945f68dbc08f1076e65585 | https://github.com/rails/spring/blob/e7a36afa436fcc59b6945f68dbc08f1076e65585/lib/spring/application_manager.rb#L59-L76 | train |
arsduo/koala | lib/koala/utils.rb | Koala.Utils.symbolize_hash | def symbolize_hash(hash)
return hash unless hash.is_a?(Hash)
hash.inject({}){ |memo,(key,value)| memo[key.to_sym] = symbolize_hash(value); memo }
end | ruby | def symbolize_hash(hash)
return hash unless hash.is_a?(Hash)
hash.inject({}){ |memo,(key,value)| memo[key.to_sym] = symbolize_hash(value); memo }
end | [
"def",
"symbolize_hash",
"(",
"hash",
")",
"return",
"hash",
"unless",
"hash",
".",
"is_a?",
"(",
"Hash",
")",
"hash",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"memo",
",",
"(",
"key",
",",
"value",
")",
"|",
"memo",
"[",
"key",
".",
"to_sym"... | Ensures that a hash uses symbols as opposed to strings
Useful for allowing either syntax for end users | [
"Ensures",
"that",
"a",
"hash",
"uses",
"symbols",
"as",
"opposed",
"to",
"strings",
"Useful",
"for",
"allowing",
"either",
"syntax",
"for",
"end",
"users"
] | 3c7037eea67062f05eccb16836bebec403ddbfec | https://github.com/arsduo/koala/blob/3c7037eea67062f05eccb16836bebec403ddbfec/lib/koala/utils.rb#L35-L39 | train |
chaps-io/public_activity | lib/public_activity/utility/view_helpers.rb | PublicActivity.ViewHelpers.single_content_for | def single_content_for(name, content = nil, &block)
@view_flow.set(name, ActiveSupport::SafeBuffer.new)
content_for(name, content, &block)
end | ruby | def single_content_for(name, content = nil, &block)
@view_flow.set(name, ActiveSupport::SafeBuffer.new)
content_for(name, content, &block)
end | [
"def",
"single_content_for",
"(",
"name",
",",
"content",
"=",
"nil",
",",
"&",
"block",
")",
"@view_flow",
".",
"set",
"(",
"name",
",",
"ActiveSupport",
"::",
"SafeBuffer",
".",
"new",
")",
"content_for",
"(",
"name",
",",
"content",
",",
"block",
")",... | Helper for setting content_for in activity partial, needed to
flush remains in between partial renders. | [
"Helper",
"for",
"setting",
"content_for",
"in",
"activity",
"partial",
"needed",
"to",
"flush",
"remains",
"in",
"between",
"partial",
"renders",
"."
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/utility/view_helpers.rb#L21-L24 | train |
chaps-io/public_activity | lib/public_activity/common.rb | PublicActivity.Common.create_activity! | def create_activity!(*args)
return unless self.public_activity_enabled?
options = prepare_settings(*args)
if call_hook_safe(options[:key].split('.').last)
reset_activity_instance_options
return PublicActivity::Adapter.create_activity!(self, options)
end
end | ruby | def create_activity!(*args)
return unless self.public_activity_enabled?
options = prepare_settings(*args)
if call_hook_safe(options[:key].split('.').last)
reset_activity_instance_options
return PublicActivity::Adapter.create_activity!(self, options)
end
end | [
"def",
"create_activity!",
"(",
"*",
"args",
")",
"return",
"unless",
"self",
".",
"public_activity_enabled?",
"options",
"=",
"prepare_settings",
"(",
"args",
")",
"if",
"call_hook_safe",
"(",
"options",
"[",
":key",
"]",
".",
"split",
"(",
"'.'",
")",
".",... | Directly saves activity to database. Works the same as create_activity
but throws validation error for each supported ORM.
@see #create_activity | [
"Directly",
"saves",
"activity",
"to",
"database",
".",
"Works",
"the",
"same",
"as",
"create_activity",
"but",
"throws",
"validation",
"error",
"for",
"each",
"supported",
"ORM",
"."
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/common.rb#L266-L274 | train |
chaps-io/public_activity | lib/public_activity/common.rb | PublicActivity.Common.prepare_custom_fields | def prepare_custom_fields(options)
customs = self.class.activity_custom_fields_global.clone
customs.merge!(self.activity_custom_fields) if self.activity_custom_fields
customs.merge!(options)
customs.each do |k, v|
customs[k] = PublicActivity.resolve_value(self, v)
end
end | ruby | def prepare_custom_fields(options)
customs = self.class.activity_custom_fields_global.clone
customs.merge!(self.activity_custom_fields) if self.activity_custom_fields
customs.merge!(options)
customs.each do |k, v|
customs[k] = PublicActivity.resolve_value(self, v)
end
end | [
"def",
"prepare_custom_fields",
"(",
"options",
")",
"customs",
"=",
"self",
".",
"class",
".",
"activity_custom_fields_global",
".",
"clone",
"customs",
".",
"merge!",
"(",
"self",
".",
"activity_custom_fields",
")",
"if",
"self",
".",
"activity_custom_fields",
"... | Prepares and resolves custom fields
users can pass to `tracked` method
@private | [
"Prepares",
"and",
"resolves",
"custom",
"fields",
"users",
"can",
"pass",
"to",
"tracked",
"method"
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/common.rb#L307-L314 | train |
chaps-io/public_activity | lib/public_activity/common.rb | PublicActivity.Common.prepare_key | def prepare_key(action, options = {})
(
options[:key] ||
self.activity_key ||
((self.class.name.underscore.gsub('/', '_') + "." + action.to_s) if action)
).try(:to_s)
end | ruby | def prepare_key(action, options = {})
(
options[:key] ||
self.activity_key ||
((self.class.name.underscore.gsub('/', '_') + "." + action.to_s) if action)
).try(:to_s)
end | [
"def",
"prepare_key",
"(",
"action",
",",
"options",
"=",
"{",
"}",
")",
"(",
"options",
"[",
":key",
"]",
"||",
"self",
".",
"activity_key",
"||",
"(",
"(",
"self",
".",
"class",
".",
"name",
".",
"underscore",
".",
"gsub",
"(",
"'/'",
",",
"'_'",... | Helper method to serialize class name into relevant key
@return [String] the resulted key
@param [Symbol] or [String] the name of the operation to be done on class
@param [Hash] options to be used on key generation, defaults to {} | [
"Helper",
"method",
"to",
"serialize",
"class",
"name",
"into",
"relevant",
"key"
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/common.rb#L343-L349 | train |
chaps-io/public_activity | lib/public_activity/renderable.rb | PublicActivity.Renderable.text | def text(params = {})
# TODO: some helper for key transformation for two supported formats
k = key.split('.')
k.unshift('activity') if k.first != 'activity'
k = k.join('.')
I18n.t(k, parameters.merge(params) || {})
end | ruby | def text(params = {})
# TODO: some helper for key transformation for two supported formats
k = key.split('.')
k.unshift('activity') if k.first != 'activity'
k = k.join('.')
I18n.t(k, parameters.merge(params) || {})
end | [
"def",
"text",
"(",
"params",
"=",
"{",
"}",
")",
"# TODO: some helper for key transformation for two supported formats",
"k",
"=",
"key",
".",
"split",
"(",
"'.'",
")",
"k",
".",
"unshift",
"(",
"'activity'",
")",
"if",
"k",
".",
"first",
"!=",
"'activity'",
... | Virtual attribute returning text description of the activity
using the activity's key to translate using i18n. | [
"Virtual",
"attribute",
"returning",
"text",
"description",
"of",
"the",
"activity",
"using",
"the",
"activity",
"s",
"key",
"to",
"translate",
"using",
"i18n",
"."
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/renderable.rb#L9-L16 | train |
chaps-io/public_activity | lib/public_activity/renderable.rb | PublicActivity.Renderable.render | def render(context, params = {})
partial_root = params.delete(:root) || 'public_activity'
partial_path = nil
layout_root = params.delete(:layout_root) || 'layouts'
if params.has_key? :display
if params[:display].to_sym == :"i18n"
text = self.text(params)
... | ruby | def render(context, params = {})
partial_root = params.delete(:root) || 'public_activity'
partial_path = nil
layout_root = params.delete(:layout_root) || 'layouts'
if params.has_key? :display
if params[:display].to_sym == :"i18n"
text = self.text(params)
... | [
"def",
"render",
"(",
"context",
",",
"params",
"=",
"{",
"}",
")",
"partial_root",
"=",
"params",
".",
"delete",
"(",
":root",
")",
"||",
"'public_activity'",
"partial_path",
"=",
"nil",
"layout_root",
"=",
"params",
".",
"delete",
"(",
":layout_root",
")... | Renders activity from views.
@param [ActionView::Base] context
@return [nil] nil
Renders activity to the given ActionView context with included
AV::Helpers::RenderingHelper (most commonly just ActionView::Base)
The *preferred* *way* of rendering activities is
to provide a template specifying how the rendering ... | [
"Renders",
"activity",
"from",
"views",
"."
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/renderable.rb#L98-L119 | train |
chaps-io/public_activity | lib/public_activity/renderable.rb | PublicActivity.Renderable.template_path | def template_path(key, partial_root)
path = key.split(".")
path.delete_at(0) if path[0] == "activity"
path.unshift partial_root
path.join("/")
end | ruby | def template_path(key, partial_root)
path = key.split(".")
path.delete_at(0) if path[0] == "activity"
path.unshift partial_root
path.join("/")
end | [
"def",
"template_path",
"(",
"key",
",",
"partial_root",
")",
"path",
"=",
"key",
".",
"split",
"(",
"\".\"",
")",
"path",
".",
"delete_at",
"(",
"0",
")",
"if",
"path",
"[",
"0",
"]",
"==",
"\"activity\"",
"path",
".",
"unshift",
"partial_root",
"path... | Builds the path to template based on activity key | [
"Builds",
"the",
"path",
"to",
"template",
"based",
"on",
"activity",
"key"
] | e4357cd14db67299e0cbbd656300f51b7069ea9b | https://github.com/chaps-io/public_activity/blob/e4357cd14db67299e0cbbd656300f51b7069ea9b/lib/public_activity/renderable.rb#L159-L164 | train |
restforce/restforce | lib/restforce/collection.rb | Restforce.Collection.each | def each
@raw_page['records'].each { |record| yield Restforce::Mash.build(record, @client) }
np = next_page
while np
np.current_page.each { |record| yield record }
np = np.next_page
end
end | ruby | def each
@raw_page['records'].each { |record| yield Restforce::Mash.build(record, @client) }
np = next_page
while np
np.current_page.each { |record| yield record }
np = np.next_page
end
end | [
"def",
"each",
"@raw_page",
"[",
"'records'",
"]",
".",
"each",
"{",
"|",
"record",
"|",
"yield",
"Restforce",
"::",
"Mash",
".",
"build",
"(",
"record",
",",
"@client",
")",
"}",
"np",
"=",
"next_page",
"while",
"np",
"np",
".",
"current_page",
".",
... | Given a hash and client, will create an Enumerator that will lazily
request Salesforce for the next page of results.
Yield each value on each page. | [
"Given",
"a",
"hash",
"and",
"client",
"will",
"create",
"an",
"Enumerator",
"that",
"will",
"lazily",
"request",
"Salesforce",
"for",
"the",
"next",
"page",
"of",
"results",
".",
"Yield",
"each",
"value",
"on",
"each",
"page",
"."
] | 74cbc9c745320dbea5117e2e3cc8d54d66db6562 | https://github.com/restforce/restforce/blob/74cbc9c745320dbea5117e2e3cc8d54d66db6562/lib/restforce/collection.rb#L15-L23 | train |
restforce/restforce | lib/restforce/middleware/authentication.rb | Restforce.Middleware::Authentication.encode_www_form | def encode_www_form(params)
if URI.respond_to?(:encode_www_form)
URI.encode_www_form(params)
else
params.map do |k, v|
k = CGI.escape(k.to_s)
v = CGI.escape(v.to_s)
"#{k}=#{v}"
end.join('&')
end
end | ruby | def encode_www_form(params)
if URI.respond_to?(:encode_www_form)
URI.encode_www_form(params)
else
params.map do |k, v|
k = CGI.escape(k.to_s)
v = CGI.escape(v.to_s)
"#{k}=#{v}"
end.join('&')
end
end | [
"def",
"encode_www_form",
"(",
"params",
")",
"if",
"URI",
".",
"respond_to?",
"(",
":encode_www_form",
")",
"URI",
".",
"encode_www_form",
"(",
"params",
")",
"else",
"params",
".",
"map",
"do",
"|",
"k",
",",
"v",
"|",
"k",
"=",
"CGI",
".",
"escape",... | Featured detect form encoding.
URI in 1.8 does not include encode_www_form | [
"Featured",
"detect",
"form",
"encoding",
".",
"URI",
"in",
"1",
".",
"8",
"does",
"not",
"include",
"encode_www_form"
] | 74cbc9c745320dbea5117e2e3cc8d54d66db6562 | https://github.com/restforce/restforce/blob/74cbc9c745320dbea5117e2e3cc8d54d66db6562/lib/restforce/middleware/authentication.rb#L70-L80 | train |
rmagick/rmagick | ext/RMagick/extconf.rb | RMagick.Extconf.have_enum_values | def have_enum_values(enum, values, headers = nil, &b)
values.each do |value|
have_enum_value(enum, value, headers, &b)
end
end | ruby | def have_enum_values(enum, values, headers = nil, &b)
values.each do |value|
have_enum_value(enum, value, headers, &b)
end
end | [
"def",
"have_enum_values",
"(",
"enum",
",",
"values",
",",
"headers",
"=",
"nil",
",",
"&",
"b",
")",
"values",
".",
"each",
"do",
"|",
"value",
"|",
"have_enum_value",
"(",
"enum",
",",
"value",
",",
"headers",
",",
"b",
")",
"end",
"end"
] | Test for multiple values of the same enum type | [
"Test",
"for",
"multiple",
"values",
"of",
"the",
"same",
"enum",
"type"
] | ef6688ed9d76bf123c2ea1a483eff8635051adb7 | https://github.com/rmagick/rmagick/blob/ef6688ed9d76bf123c2ea1a483eff8635051adb7/ext/RMagick/extconf.rb#L136-L140 | train |
rmagick/rmagick | lib/rvg/rvg.rb | Magick.RVG.bgfill | def bgfill
if @background_fill.nil?
color = Magick::Pixel.new(0, 0, 0, Magick::TransparentOpacity)
else
color = @background_fill
color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
end
color
end | ruby | def bgfill
if @background_fill.nil?
color = Magick::Pixel.new(0, 0, 0, Magick::TransparentOpacity)
else
color = @background_fill
color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
end
color
end | [
"def",
"bgfill",
"if",
"@background_fill",
".",
"nil?",
"color",
"=",
"Magick",
"::",
"Pixel",
".",
"new",
"(",
"0",
",",
"0",
",",
"0",
",",
"Magick",
"::",
"TransparentOpacity",
")",
"else",
"color",
"=",
"@background_fill",
"color",
".",
"opacity",
"=... | background_fill defaults to 'none'. If background_fill has been set to something
else, combine it with the background_fill_opacity. | [
"background_fill",
"defaults",
"to",
"none",
".",
"If",
"background_fill",
"has",
"been",
"set",
"to",
"something",
"else",
"combine",
"it",
"with",
"the",
"background_fill_opacity",
"."
] | ef6688ed9d76bf123c2ea1a483eff8635051adb7 | https://github.com/rmagick/rmagick/blob/ef6688ed9d76bf123c2ea1a483eff8635051adb7/lib/rvg/rvg.rb#L61-L69 | train |
Subsets and Splits
SQL Console for semeru/code-text-ruby
Retrieves 20,000 non-null code samples labeled as Ruby, providing a basic overview of the dataset but without deeper analysis.