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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.drop_while | def drop_while(&block)
raise Erlang::ImproperListError if improper?
return enum_for(:drop_while) unless block_given?
list = self
list = list.tail while !list.empty? && yield(list.head)
return list
end | ruby | def drop_while(&block)
raise Erlang::ImproperListError if improper?
return enum_for(:drop_while) unless block_given?
list = self
list = list.tail while !list.empty? && yield(list.head)
return list
end | [
"def",
"drop_while",
"(",
"&",
"block",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"enum_for",
"(",
":drop_while",
")",
"unless",
"block_given?",
"list",
"=",
"self",
"list",
"=",
"list",
".",
"tail",
"while",
"!",
"list"... | Return a `List` which contains all elements starting from the
first element for which the block returns `nil` or `false`.
@example
Erlang::List[1, 3, 5, 7, 6, 4, 2].drop_while { |e| e < 5 }
# => Erlang::List[5, 7, 6, 4, 2]
@return [List, Enumerator]
@yield [item] | [
"Return",
"a",
"List",
"which",
"contains",
"all",
"elements",
"starting",
"from",
"the",
"first",
"element",
"for",
"which",
"the",
"block",
"returns",
"nil",
"or",
"false",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L317-L323 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.pop | def pop
raise Erlang::ImproperListError if improper?
return self if empty?
new_size = size - 1
return Erlang::List.new(head, tail.take(new_size - 1)) if new_size >= 1
return Erlang::Nil
end | ruby | def pop
raise Erlang::ImproperListError if improper?
return self if empty?
new_size = size - 1
return Erlang::List.new(head, tail.take(new_size - 1)) if new_size >= 1
return Erlang::Nil
end | [
"def",
"pop",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"empty?",
"new_size",
"=",
"size",
"-",
"1",
"return",
"Erlang",
"::",
"List",
".",
"new",
"(",
"head",
",",
"tail",
".",
"take",
"(",
"new_size",
"-",... | Return a `List` containing all but the last item from this `List`.
@example
Erlang::List["A", "B", "C"].pop # => Erlang::List["A", "B"]
@return [List] | [
"Return",
"a",
"List",
"containing",
"all",
"but",
"the",
"last",
"item",
"from",
"this",
"List",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L363-L369 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.drop | def drop(number)
raise Erlang::ImproperListError if improper?
list = self
while !list.empty? && number > 0
number -= 1
list = list.tail
end
return list
end | ruby | def drop(number)
raise Erlang::ImproperListError if improper?
list = self
while !list.empty? && number > 0
number -= 1
list = list.tail
end
return list
end | [
"def",
"drop",
"(",
"number",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"list",
"=",
"self",
"while",
"!",
"list",
".",
"empty?",
"&&",
"number",
">",
"0",
"number",
"-=",
"1",
"list",
"=",
"list",
".",
"tail",
"end",
"retur... | Return a `List` containing all items after the first `number` items from
this `List`.
@example
Erlang::List[1, 3, 5, 7, 6, 4, 2].drop(3)
# => Erlang::List[7, 6, 4, 2]
@param number [Integer] The number of items to skip over
@return [List] | [
"Return",
"a",
"List",
"containing",
"all",
"items",
"after",
"the",
"first",
"number",
"items",
"from",
"this",
"List",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L380-L388 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.append | def append(other)
# raise Erlang::ImproperListError if improper?
other = Erlang.from(other)
return self if not improper? and Erlang.is_list(other) and other.empty?
return other if Erlang.is_list(other) and empty?
is_improper = Erlang.is_list(other) ? other.improper? : true
out = tail... | ruby | def append(other)
# raise Erlang::ImproperListError if improper?
other = Erlang.from(other)
return self if not improper? and Erlang.is_list(other) and other.empty?
return other if Erlang.is_list(other) and empty?
is_improper = Erlang.is_list(other) ? other.improper? : true
out = tail... | [
"def",
"append",
"(",
"other",
")",
"other",
"=",
"Erlang",
".",
"from",
"(",
"other",
")",
"return",
"self",
"if",
"not",
"improper?",
"and",
"Erlang",
".",
"is_list",
"(",
"other",
")",
"and",
"other",
".",
"empty?",
"return",
"other",
"if",
"Erlang"... | Return a `List` with all items from this `List`, followed by all items from
`other`.
@example
Erlang::List[1, 2, 3].append(Erlang::List[4, 5])
# => Erlang::List[1, 2, 3, 4, 5]
@param other [List] The list to add onto the end of this one
@return [List] | [
"Return",
"a",
"List",
"with",
"all",
"items",
"from",
"this",
"List",
"followed",
"by",
"all",
"items",
"from",
"other",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L399-L433 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.transpose | def transpose
raise Erlang::ImproperListError if improper?
return Erlang::Nil if empty?
return Erlang::Nil if any? { |list| list.empty? }
heads, tails = Erlang::Nil, Erlang::Nil
reverse_each { |list| heads, tails = heads.cons(list.head), tails.cons(list.tail) }
return Erlang::Cons.ne... | ruby | def transpose
raise Erlang::ImproperListError if improper?
return Erlang::Nil if empty?
return Erlang::Nil if any? { |list| list.empty? }
heads, tails = Erlang::Nil, Erlang::Nil
reverse_each { |list| heads, tails = heads.cons(list.head), tails.cons(list.tail) }
return Erlang::Cons.ne... | [
"def",
"transpose",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"Erlang",
"::",
"Nil",
"if",
"empty?",
"return",
"Erlang",
"::",
"Nil",
"if",
"any?",
"{",
"|",
"list",
"|",
"list",
".",
"empty?",
"}",
"heads",
",",
"tails",
... | Gather the first element of each nested list into a new `List`, then the second
element of each nested list, then the third, and so on. In other words, if each
nested list is a "row", return a `List` of "columns" instead.
@return [List] | [
"Gather",
"the",
"first",
"element",
"of",
"each",
"nested",
"list",
"into",
"a",
"new",
"List",
"then",
"the",
"second",
"element",
"of",
"each",
"nested",
"list",
"then",
"the",
"third",
"and",
"so",
"on",
".",
"In",
"other",
"words",
"if",
"each",
"... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L490-L497 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.rotate | def rotate(count = 1)
raise Erlang::ImproperListError if improper?
raise TypeError, "expected Integer" if not count.is_a?(Integer)
return self if empty? || (count % size) == 0
count = (count >= 0) ? count % size : (size - (~count % size) - 1)
return drop(count).append(take(count))
end | ruby | def rotate(count = 1)
raise Erlang::ImproperListError if improper?
raise TypeError, "expected Integer" if not count.is_a?(Integer)
return self if empty? || (count % size) == 0
count = (count >= 0) ? count % size : (size - (~count % size) - 1)
return drop(count).append(take(count))
end | [
"def",
"rotate",
"(",
"count",
"=",
"1",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"raise",
"TypeError",
",",
"\"expected Integer\"",
"if",
"not",
"count",
".",
"is_a?",
"(",
"Integer",
")",
"return",
"self",
"if",
"empty?",
"||",... | Return a new `List` with the same elements, but rotated so that the one at
index `count` is the first element of the new list. If `count` is positive,
the elements will be shifted left, and those shifted past the lowest position
will be moved to the end. If `count` is negative, the elements will be shifted
right, a... | [
"Return",
"a",
"new",
"List",
"with",
"the",
"same",
"elements",
"but",
"rotated",
"so",
"that",
"the",
"one",
"at",
"index",
"count",
"is",
"the",
"first",
"element",
"of",
"the",
"new",
"list",
".",
"If",
"count",
"is",
"positive",
"the",
"elements",
... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L513-L519 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.sort | def sort(&comparator)
comparator = Erlang.method(:compare) unless block_given?
array = super(&comparator)
return List.from_enum(array)
end | ruby | def sort(&comparator)
comparator = Erlang.method(:compare) unless block_given?
array = super(&comparator)
return List.from_enum(array)
end | [
"def",
"sort",
"(",
"&",
"comparator",
")",
"comparator",
"=",
"Erlang",
".",
"method",
"(",
":compare",
")",
"unless",
"block_given?",
"array",
"=",
"super",
"(",
"&",
"comparator",
")",
"return",
"List",
".",
"from_enum",
"(",
"array",
")",
"end"
] | Return a new `List` with the same items, but sorted.
@overload sort
Compare elements with their natural sort key (`#<=>`).
@example
Erlang::List["Elephant", "Dog", "Lion"].sort
# => Erlang::List["Dog", "Elephant", "Lion"]
@overload sort
Uses the block as a comparator to determine sorted order.
... | [
"Return",
"a",
"new",
"List",
"with",
"the",
"same",
"items",
"but",
"sorted",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L613-L617 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.intersperse | def intersperse(sep)
raise Erlang::ImproperListError if improper?
return self if tail.empty?
sep = Erlang.from(sep)
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list.head)
... | ruby | def intersperse(sep)
raise Erlang::ImproperListError if improper?
return self if tail.empty?
sep = Erlang.from(sep)
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list.head)
... | [
"def",
"intersperse",
"(",
"sep",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"tail",
".",
"empty?",
"sep",
"=",
"Erlang",
".",
"from",
"(",
"sep",
")",
"out",
"=",
"tail",
"=",
"Erlang",
"::",
"Cons",
... | Return a new `List` with `sep` inserted between each of the existing elements.
@example
Erlang::List["one", "two", "three"].intersperse(" ")
# => Erlang::List["one", " ", "two", " ", "three"]
@return [List] | [
"Return",
"a",
"new",
"List",
"with",
"sep",
"inserted",
"between",
"each",
"of",
"the",
"existing",
"elements",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L645-L677 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.union | def union(other)
raise Erlang::ImproperListError if improper?
other = Erlang.from(other)
raise ArgumentError, "other must be of Erlang::List type" if not Erlang.is_list(other)
raise Erlang::ImproperListError if other.improper?
items = ::Set.new
return _uniq(items).append(other._uniq(... | ruby | def union(other)
raise Erlang::ImproperListError if improper?
other = Erlang.from(other)
raise ArgumentError, "other must be of Erlang::List type" if not Erlang.is_list(other)
raise Erlang::ImproperListError if other.improper?
items = ::Set.new
return _uniq(items).append(other._uniq(... | [
"def",
"union",
"(",
"other",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"other",
"=",
"Erlang",
".",
"from",
"(",
"other",
")",
"raise",
"ArgumentError",
",",
"\"other must be of Erlang::List type\"",
"if",
"not",
"Erlang",
".",
"is_l... | Return a `List` with all the elements from both this list and `other`,
with all duplicates removed.
@example
Erlang::List[1, 2].union(Erlang::List[2, 3]) # => Erlang::List[1, 2, 3]
@param other [List] The list to merge with
@return [List] | [
"Return",
"a",
"List",
"with",
"all",
"the",
"elements",
"from",
"both",
"this",
"list",
"and",
"other",
"with",
"all",
"duplicates",
"removed",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L750-L757 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.init | def init
raise Erlang::ImproperListError if improper?
return Erlang::Nil if tail.empty?
out = tail = Erlang::Cons.allocate
list = self
until list.tail.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list.head)
new_node.instance_variabl... | ruby | def init
raise Erlang::ImproperListError if improper?
return Erlang::Nil if tail.empty?
out = tail = Erlang::Cons.allocate
list = self
until list.tail.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list.head)
new_node.instance_variabl... | [
"def",
"init",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"Erlang",
"::",
"Nil",
"if",
"tail",
".",
"empty?",
"out",
"=",
"tail",
"=",
"Erlang",
"::",
"Cons",
".",
"allocate",
"list",
"=",
"self",
"until",
"list",
".",
"ta... | Return a `List` with all elements except the last one.
@example
Erlang::List["a", "b", "c"].init # => Erlang::List["a", "b"]
@return [List] | [
"Return",
"a",
"List",
"with",
"all",
"elements",
"except",
"the",
"last",
"one",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L766-L786 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.last | def last(allow_improper = false)
if allow_improper and improper?
list = self
list = list.tail while list.tail.kind_of?(Erlang::List)
return list.tail
else
raise Erlang::ImproperListError if improper?
list = self
list = list.tail until list.tail.empty?
... | ruby | def last(allow_improper = false)
if allow_improper and improper?
list = self
list = list.tail while list.tail.kind_of?(Erlang::List)
return list.tail
else
raise Erlang::ImproperListError if improper?
list = self
list = list.tail until list.tail.empty?
... | [
"def",
"last",
"(",
"allow_improper",
"=",
"false",
")",
"if",
"allow_improper",
"and",
"improper?",
"list",
"=",
"self",
"list",
"=",
"list",
".",
"tail",
"while",
"list",
".",
"tail",
".",
"kind_of?",
"(",
"Erlang",
"::",
"List",
")",
"return",
"list",... | Return the last item in this list.
@return [Object] | [
"Return",
"the",
"last",
"item",
"in",
"this",
"list",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L790-L801 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.tails | def tails
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list)
new_node.instance_variable_set(:@improper, fal... | ruby | def tails
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, list)
new_node.instance_variable_set(:@improper, fal... | [
"def",
"tails",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"empty?",
"out",
"=",
"tail",
"=",
"Erlang",
"::",
"Cons",
".",
"allocate",
"list",
"=",
"self",
"until",
"list",
".",
"empty?",
"new_node",
"=",
"Erla... | Return a `List` of all suffixes of this list.
@example
Erlang::List[1,2,3].tails
# => Erlang::List[
# Erlang::List[1, 2, 3],
# Erlang::List[2, 3],
# Erlang::List[3]]
@return [List] | [
"Return",
"a",
"List",
"of",
"all",
"suffixes",
"of",
"this",
"list",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L813-L828 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.inits | def inits
raise Erlang::ImproperListError if improper?
return self if empty?
prev = nil
return map do |head|
if prev.nil?
Erlang::List.from_enum(prev = [head])
else
Erlang::List.from_enum(prev.push(head))
end
end
end | ruby | def inits
raise Erlang::ImproperListError if improper?
return self if empty?
prev = nil
return map do |head|
if prev.nil?
Erlang::List.from_enum(prev = [head])
else
Erlang::List.from_enum(prev.push(head))
end
end
end | [
"def",
"inits",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"empty?",
"prev",
"=",
"nil",
"return",
"map",
"do",
"|",
"head",
"|",
"if",
"prev",
".",
"nil?",
"Erlang",
"::",
"List",
".",
"from_enum",
"(",
"pre... | Return a `List` of all prefixes of this list.
@example
Erlang::List[1,2,3].inits
# => Erlang::List[
# Erlang::List[1],
# Erlang::List[1, 2],
# Erlang::List[1, 2, 3]]
@return [List] | [
"Return",
"a",
"List",
"of",
"all",
"prefixes",
"of",
"this",
"list",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L840-L851 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.combination | def combination(n)
raise Erlang::ImproperListError if improper?
return Erlang::Cons.new(Erlang::Nil) if n == 0
return self if empty?
return tail.combination(n - 1).map { |list| list.cons(head) }.append(tail.combination(n))
end | ruby | def combination(n)
raise Erlang::ImproperListError if improper?
return Erlang::Cons.new(Erlang::Nil) if n == 0
return self if empty?
return tail.combination(n - 1).map { |list| list.cons(head) }.append(tail.combination(n))
end | [
"def",
"combination",
"(",
"n",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"Erlang",
"::",
"Cons",
".",
"new",
"(",
"Erlang",
"::",
"Nil",
")",
"if",
"n",
"==",
"0",
"return",
"self",
"if",
"empty?",
"return",
"tail",... | Return a `List` of all combinations of length `n` of items from this `List`.
@example
Erlang::List[1,2,3].combination(2)
# => Erlang::List[
# Erlang::List[1, 2],
# Erlang::List[1, 3],
# Erlang::List[2, 3]]
@return [List] | [
"Return",
"a",
"List",
"of",
"all",
"combinations",
"of",
"length",
"n",
"of",
"items",
"from",
"this",
"List",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L863-L868 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.chunk | def chunk(number)
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
first, list = list.split_at(number)
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, first)
... | ruby | def chunk(number)
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
first, list = list.split_at(number)
new_node = Erlang::Cons.allocate
new_node.instance_variable_set(:@head, first)
... | [
"def",
"chunk",
"(",
"number",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"empty?",
"out",
"=",
"tail",
"=",
"Erlang",
"::",
"Cons",
".",
"allocate",
"list",
"=",
"self",
"until",
"list",
".",
"empty?",
... | Split the items in this list in groups of `number`. Return a list of lists.
@example
("a".."o").to_list.chunk(5)
# => Erlang::List[
# Erlang::List["a", "b", "c", "d", "e"],
# Erlang::List["f", "g", "h", "i", "j"],
# Erlang::List["k", "l", "m", "n", "o"]]
@return [List] | [
"Split",
"the",
"items",
"in",
"this",
"list",
"in",
"groups",
"of",
"number",
".",
"Return",
"a",
"list",
"of",
"lists",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L880-L900 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.flatten | def flatten
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
if list.head.is_a?(Erlang::Cons)
list = list.head.append(list.tail)
elsif Erlang::Nil.equal?(list.head)
list =... | ruby | def flatten
raise Erlang::ImproperListError if improper?
return self if empty?
out = tail = Erlang::Cons.allocate
list = self
until list.empty?
if list.head.is_a?(Erlang::Cons)
list = list.head.append(list.tail)
elsif Erlang::Nil.equal?(list.head)
list =... | [
"def",
"flatten",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"self",
"if",
"empty?",
"out",
"=",
"tail",
"=",
"Erlang",
"::",
"Cons",
".",
"allocate",
"list",
"=",
"self",
"until",
"list",
".",
"empty?",
"if",
"list",
".",
... | Return a new `List` with all nested lists recursively "flattened out",
that is, their elements inserted into the new `List` in the place where
the nested list originally was.
@example
Erlang::List[Erlang::List[1, 2], Erlang::List[3, 4]].flatten
# => Erlang::List[1, 2, 3, 4]
@return [List] | [
"Return",
"a",
"new",
"List",
"with",
"all",
"nested",
"lists",
"recursively",
"flattened",
"out",
"that",
"is",
"their",
"elements",
"inserted",
"into",
"the",
"new",
"List",
"in",
"the",
"place",
"where",
"the",
"nested",
"list",
"originally",
"was",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L925-L950 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.slice | def slice(arg, length = (missing_length = true))
raise Erlang::ImproperListError if improper?
if missing_length
if arg.is_a?(Range)
from, to = arg.begin, arg.end
from += size if from < 0
return nil if from < 0
to += size if to < 0
to += 1 if !... | ruby | def slice(arg, length = (missing_length = true))
raise Erlang::ImproperListError if improper?
if missing_length
if arg.is_a?(Range)
from, to = arg.begin, arg.end
from += size if from < 0
return nil if from < 0
to += size if to < 0
to += 1 if !... | [
"def",
"slice",
"(",
"arg",
",",
"length",
"=",
"(",
"missing_length",
"=",
"true",
")",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"if",
"missing_length",
"if",
"arg",
".",
"is_a?",
"(",
"Range",
")",
"from",
",",
"to",
"=",
... | Return specific objects from the `List`. All overloads return `nil` if
the starting index is out of range.
@overload list.slice(index)
Returns a single object at the given `index`. If `index` is negative,
count backwards from the end.
@param index [Integer] The index to retrieve. May be negative.
@retur... | [
"Return",
"specific",
"objects",
"from",
"the",
"List",
".",
"All",
"overloads",
"return",
"nil",
"if",
"the",
"starting",
"index",
"is",
"out",
"of",
"range",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1027-L1060 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.indices | def indices(object = Erlang::Undefined, i = 0, &block)
raise Erlang::ImproperListError if improper?
object = Erlang.from(object) if object != Erlang::Undefined
return indices { |item| item == object } if not block_given?
return Erlang::Nil if empty?
out = tail = Erlang::Cons.allocate
... | ruby | def indices(object = Erlang::Undefined, i = 0, &block)
raise Erlang::ImproperListError if improper?
object = Erlang.from(object) if object != Erlang::Undefined
return indices { |item| item == object } if not block_given?
return Erlang::Nil if empty?
out = tail = Erlang::Cons.allocate
... | [
"def",
"indices",
"(",
"object",
"=",
"Erlang",
"::",
"Undefined",
",",
"i",
"=",
"0",
",",
"&",
"block",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"object",
"=",
"Erlang",
".",
"from",
"(",
"object",
")",
"if",
"object",
"!... | Return a `List` of indices of matching objects.
@overload indices(object)
Return a `List` of indices where `object` is found. Use `#==` for
testing equality.
@example
Erlang::List[1, 2, 3, 4].indices(2)
# => Erlang::List[1]
@overload indices
Pass each item successively to the block. Return a ... | [
"Return",
"a",
"List",
"of",
"indices",
"of",
"matching",
"objects",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1083-L1110 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.merge | def merge(&comparator)
raise Erlang::ImproperListError if improper?
return merge_by unless block_given?
sorted = reject(&:empty?).sort do |a, b|
yield(a.head, b.head)
end
return Erlang::Nil if sorted.empty?
return Erlang::Cons.new(sorted.head.head, sorted.tail.cons(sorted.hea... | ruby | def merge(&comparator)
raise Erlang::ImproperListError if improper?
return merge_by unless block_given?
sorted = reject(&:empty?).sort do |a, b|
yield(a.head, b.head)
end
return Erlang::Nil if sorted.empty?
return Erlang::Cons.new(sorted.head.head, sorted.tail.cons(sorted.hea... | [
"def",
"merge",
"(",
"&",
"comparator",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"merge_by",
"unless",
"block_given?",
"sorted",
"=",
"reject",
"(",
"&",
":empty?",
")",
".",
"sort",
"do",
"|",
"a",
",",
"b",
"|",
"... | Merge all the nested lists into a single list, using the given comparator
block to determine the order which items should be shifted out of the nested
lists and into the output list.
@example
list_1 = Erlang::List[1, -3, -5]
list_2 = Erlang::List[-2, 4, 6]
Erlang::List[list_1, list_2].merge { |a,b| a.abs <... | [
"Merge",
"all",
"the",
"nested",
"lists",
"into",
"a",
"single",
"list",
"using",
"the",
"given",
"comparator",
"block",
"to",
"determine",
"the",
"order",
"which",
"items",
"should",
"be",
"shifted",
"out",
"of",
"the",
"nested",
"lists",
"and",
"into",
"... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1127-L1135 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.insert | def insert(index, *items)
raise Erlang::ImproperListError if improper?
if index == 0
return Erlang::List.from_enum(items).append(self)
elsif index > 0
out = tail = Erlang::Cons.allocate
list = self
while index > 0
new_node = Erlang::Cons.allocate
new... | ruby | def insert(index, *items)
raise Erlang::ImproperListError if improper?
if index == 0
return Erlang::List.from_enum(items).append(self)
elsif index > 0
out = tail = Erlang::Cons.allocate
list = self
while index > 0
new_node = Erlang::Cons.allocate
new... | [
"def",
"insert",
"(",
"index",
",",
"*",
"items",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"if",
"index",
"==",
"0",
"return",
"Erlang",
"::",
"List",
".",
"from_enum",
"(",
"items",
")",
".",
"append",
"(",
"self",
")",
"e... | Return a new `List` with the given items inserted before the item at `index`.
@example
Erlang::List["A", "D", "E"].insert(1, "B", "C") # => Erlang::List["A", "B", "C", "D", "E"]
@param index [Integer] The index where the new items should go
@param items [Array] The items to add
@return [List] | [
"Return",
"a",
"new",
"List",
"with",
"the",
"given",
"items",
"inserted",
"before",
"the",
"item",
"at",
"index",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1176-L1203 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.delete_at | def delete_at(index)
raise Erlang::ImproperListError if improper?
if index == 0
tail
elsif index < 0
index += size if index < 0
return self if index < 0
delete_at(index)
else
out = tail = Erlang::Cons.allocate
list = self
while index > 0
... | ruby | def delete_at(index)
raise Erlang::ImproperListError if improper?
if index == 0
tail
elsif index < 0
index += size if index < 0
return self if index < 0
delete_at(index)
else
out = tail = Erlang::Cons.allocate
list = self
while index > 0
... | [
"def",
"delete_at",
"(",
"index",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"if",
"index",
"==",
"0",
"tail",
"elsif",
"index",
"<",
"0",
"index",
"+=",
"size",
"if",
"index",
"<",
"0",
"return",
"self",
"if",
"index",
"<",
... | Return a `List` containing the same items, minus the one at `index`.
If `index` is negative, it counts back from the end of the list.
@example
Erlang::List[1, 2, 3].delete_at(1) # => Erlang::List[1, 3]
Erlang::List[1, 2, 3].delete_at(-1) # => Erlang::List[1, 2]
@param index [Integer] The index of the item t... | [
"Return",
"a",
"List",
"containing",
"the",
"same",
"items",
"minus",
"the",
"one",
"at",
"index",
".",
"If",
"index",
"is",
"negative",
"it",
"counts",
"back",
"from",
"the",
"end",
"of",
"the",
"list",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1250-L1278 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.permutation | def permutation(length = size, &block)
raise Erlang::ImproperListError if improper?
return enum_for(:permutation, length) if not block_given?
if length == 0
yield Erlang::Nil
elsif length == 1
each { |obj| yield Erlang::Cons.new(obj, Erlang::Nil) }
elsif not empty?
... | ruby | def permutation(length = size, &block)
raise Erlang::ImproperListError if improper?
return enum_for(:permutation, length) if not block_given?
if length == 0
yield Erlang::Nil
elsif length == 1
each { |obj| yield Erlang::Cons.new(obj, Erlang::Nil) }
elsif not empty?
... | [
"def",
"permutation",
"(",
"length",
"=",
"size",
",",
"&",
"block",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"enum_for",
"(",
":permutation",
",",
"length",
")",
"if",
"not",
"block_given?",
"if",
"length",
"==",
"0",
... | Yields all permutations of length `n` of the items in the list, and then
returns `self`. If no length `n` is specified, permutations of the entire
list will be yielded.
There is no guarantee about which order the permutations will be yielded in.
If no block is given, an `Enumerator` is returned instead.
@exampl... | [
"Yields",
"all",
"permutations",
"of",
"length",
"n",
"of",
"the",
"items",
"in",
"the",
"list",
"and",
"then",
"returns",
"self",
".",
"If",
"no",
"length",
"n",
"is",
"specified",
"permutations",
"of",
"the",
"entire",
"list",
"will",
"be",
"yielded",
... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1400-L1420 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.partition | def partition(&block)
raise Erlang::ImproperListError if improper?
return enum_for(:partition) if not block_given?
left = left_tail = Erlang::Cons.allocate
right = right_tail = Erlang::Cons.allocate
list = self
while !list.empty?
if yield(list.head)
new_node = Erlan... | ruby | def partition(&block)
raise Erlang::ImproperListError if improper?
return enum_for(:partition) if not block_given?
left = left_tail = Erlang::Cons.allocate
right = right_tail = Erlang::Cons.allocate
list = self
while !list.empty?
if yield(list.head)
new_node = Erlan... | [
"def",
"partition",
"(",
"&",
"block",
")",
"raise",
"Erlang",
"::",
"ImproperListError",
"if",
"improper?",
"return",
"enum_for",
"(",
":partition",
")",
"if",
"not",
"block_given?",
"left",
"=",
"left_tail",
"=",
"Erlang",
"::",
"Cons",
".",
"allocate",
"r... | Return two `List`s, the first containing all the elements for which the
block evaluates to true, the second containing the rest.
@example
Erlang::List[1, 2, 3, 4, 5, 6].partition { |x| x.even? }
# => Erlang::Tuple[Erlang::List[2, 4, 6], Erlang::List[1, 3, 5]]
@return [Tuple]
@yield [item] Once for each item... | [
"Return",
"two",
"List",
"s",
"the",
"first",
"containing",
"all",
"the",
"elements",
"for",
"which",
"the",
"block",
"evaluates",
"to",
"true",
"the",
"second",
"containing",
"the",
"rest",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1458-L1494 | train |
potatosalad/ruby-erlang-terms | lib/erlang/list.rb | Erlang.List.inspect | def inspect
if improper?
result = 'Erlang::List['
list = to_proper_list
list.each_with_index { |obj, i| result << ', ' if i > 0; result << obj.inspect }
result << ']'
result << " + #{last(true).inspect}"
return result
else
result = '['
list = s... | ruby | def inspect
if improper?
result = 'Erlang::List['
list = to_proper_list
list.each_with_index { |obj, i| result << ', ' if i > 0; result << obj.inspect }
result << ']'
result << " + #{last(true).inspect}"
return result
else
result = '['
list = s... | [
"def",
"inspect",
"if",
"improper?",
"result",
"=",
"'Erlang::List['",
"list",
"=",
"to_proper_list",
"list",
".",
"each_with_index",
"{",
"|",
"obj",
",",
"i",
"|",
"result",
"<<",
"', '",
"if",
"i",
">",
"0",
";",
"result",
"<<",
"obj",
".",
"inspect",... | Return the contents of this `List` as a programmer-readable `String`. If all the
items in the list are serializable as Ruby literal strings, the returned string can
be passed to `eval` to reconstitute an equivalent `List`.
@return [::String] | [
"Return",
"the",
"contents",
"of",
"this",
"List",
"as",
"a",
"programmer",
"-",
"readable",
"String",
".",
"If",
"all",
"the",
"items",
"in",
"the",
"list",
"are",
"serializable",
"as",
"Ruby",
"literal",
"strings",
"the",
"returned",
"string",
"can",
"be... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/list.rb#L1647-L1662 | train |
potatosalad/ruby-erlang-terms | lib/erlang/binary.rb | Erlang.Binary.copy | def copy(n = 1)
raise ArgumentError, 'n must be a non-negative Integer' if not n.is_a?(::Integer) or n < 0
return self if n == 1
return Erlang::Binary[(@data * n)]
end | ruby | def copy(n = 1)
raise ArgumentError, 'n must be a non-negative Integer' if not n.is_a?(::Integer) or n < 0
return self if n == 1
return Erlang::Binary[(@data * n)]
end | [
"def",
"copy",
"(",
"n",
"=",
"1",
")",
"raise",
"ArgumentError",
",",
"'n must be a non-negative Integer'",
"if",
"not",
"n",
".",
"is_a?",
"(",
"::",
"Integer",
")",
"or",
"n",
"<",
"0",
"return",
"self",
"if",
"n",
"==",
"1",
"return",
"Erlang",
"::... | Returns a new `Binary` containing `n` copies of itself. `n` must be greater than or equal to 0.
@param n [Integer] The number of copies
@return [Binary]
@raise [ArgumentError] if `n` is less than 0 | [
"Returns",
"a",
"new",
"Binary",
"containing",
"n",
"copies",
"of",
"itself",
".",
"n",
"must",
"be",
"greater",
"than",
"or",
"equal",
"to",
"0",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/binary.rb#L225-L229 | train |
potatosalad/ruby-erlang-terms | lib/erlang/binary.rb | Erlang.Binary.each_bit | def each_bit
return enum_for(:each_bit) unless block_given?
index = 0
bitsize = self.bitsize
@data.each_byte do |byte|
loop do
break if index == bitsize
bit = (byte >> (7 - (index & 7))) & 1
yield bit
index += 1
break if (index & 7) == 0
... | ruby | def each_bit
return enum_for(:each_bit) unless block_given?
index = 0
bitsize = self.bitsize
@data.each_byte do |byte|
loop do
break if index == bitsize
bit = (byte >> (7 - (index & 7))) & 1
yield bit
index += 1
break if (index & 7) == 0
... | [
"def",
"each_bit",
"return",
"enum_for",
"(",
":each_bit",
")",
"unless",
"block_given?",
"index",
"=",
"0",
"bitsize",
"=",
"self",
".",
"bitsize",
"@data",
".",
"each_byte",
"do",
"|",
"byte",
"|",
"loop",
"do",
"break",
"if",
"index",
"==",
"bitsize",
... | Call the given block once for each bit in the `Binary`, passing each
bit from first to last successively to the block. If no block is given,
returns an `Enumerator`.
@return [self]
@yield [Integer] | [
"Call",
"the",
"given",
"block",
"once",
"for",
"each",
"bit",
"in",
"the",
"Binary",
"passing",
"each",
"bit",
"from",
"first",
"to",
"last",
"successively",
"to",
"the",
"block",
".",
"If",
"no",
"block",
"is",
"given",
"returns",
"an",
"Enumerator",
"... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/binary.rb#L245-L259 | train |
potatosalad/ruby-erlang-terms | lib/erlang/binary.rb | Erlang.Binary.part | def part(position, length)
raise ArgumentError, 'position must be an Integer' if not position.is_a?(::Integer)
raise ArgumentError, 'length must be a non-negative Integer' if not length.is_a?(::Integer) or length < 0
return Erlang::Binary[@data.byteslice(position, length)]
end | ruby | def part(position, length)
raise ArgumentError, 'position must be an Integer' if not position.is_a?(::Integer)
raise ArgumentError, 'length must be a non-negative Integer' if not length.is_a?(::Integer) or length < 0
return Erlang::Binary[@data.byteslice(position, length)]
end | [
"def",
"part",
"(",
"position",
",",
"length",
")",
"raise",
"ArgumentError",
",",
"'position must be an Integer'",
"if",
"not",
"position",
".",
"is_a?",
"(",
"::",
"Integer",
")",
"raise",
"ArgumentError",
",",
"'length must be a non-negative Integer'",
"if",
"not... | Returns the section of this `Binary` starting at `position` of `length`.
@param position [Integer] The starting position
@param length [Integer] The non-negative length
@return [Binary]
@raise [ArgumentError] if `position` is not an `Integer` or `length` is not a non-negative `Integer` | [
"Returns",
"the",
"section",
"of",
"this",
"Binary",
"starting",
"at",
"position",
"of",
"length",
"."
] | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/binary.rb#L336-L340 | train |
langalex/culerity | lib/culerity/remote_browser_proxy.rb | Culerity.RemoteBrowserProxy.wait_until | def wait_until time_to_wait=30, &block
time_limit = Time.now + time_to_wait
until block.call
if Time.now > time_limit
raise "wait_until timeout after #{time_to_wait} seconds"
end
sleep 0.1
end
true
end | ruby | def wait_until time_to_wait=30, &block
time_limit = Time.now + time_to_wait
until block.call
if Time.now > time_limit
raise "wait_until timeout after #{time_to_wait} seconds"
end
sleep 0.1
end
true
end | [
"def",
"wait_until",
"time_to_wait",
"=",
"30",
",",
"&",
"block",
"time_limit",
"=",
"Time",
".",
"now",
"+",
"time_to_wait",
"until",
"block",
".",
"call",
"if",
"Time",
".",
"now",
">",
"time_limit",
"raise",
"\"wait_until timeout after #{time_to_wait} seconds\... | Calls the block until it returns true or +time_to_wait+ is reached.
+time_to_wait+ is 30 seconds by default
Returns true upon success
Raises RuntimeError when +time_to_wait+ is reached. | [
"Calls",
"the",
"block",
"until",
"it",
"returns",
"true",
"or",
"+",
"time_to_wait",
"+",
"is",
"reached",
".",
"+",
"time_to_wait",
"+",
"is",
"30",
"seconds",
"by",
"default"
] | 8e330ce79e88d00a213ece7755a22f4e0ca4f042 | https://github.com/langalex/culerity/blob/8e330ce79e88d00a213ece7755a22f4e0ca4f042/lib/culerity/remote_browser_proxy.rb#L18-L27 | train |
langalex/culerity | lib/culerity/remote_browser_proxy.rb | Culerity.RemoteBrowserProxy.confirm | def confirm(bool, &block)
blk = "lambda { #{bool} }"
self.send_remote(:add_listener, :confirm) { blk }
block.call
self.send_remote(:remove_listener, :confirm, lambda {blk})
end | ruby | def confirm(bool, &block)
blk = "lambda { #{bool} }"
self.send_remote(:add_listener, :confirm) { blk }
block.call
self.send_remote(:remove_listener, :confirm, lambda {blk})
end | [
"def",
"confirm",
"(",
"bool",
",",
"&",
"block",
")",
"blk",
"=",
"\"lambda { #{bool} }\"",
"self",
".",
"send_remote",
"(",
":add_listener",
",",
":confirm",
")",
"{",
"blk",
"}",
"block",
".",
"call",
"self",
".",
"send_remote",
"(",
":remove_listener",
... | Specify whether to accept or reject all confirm js dialogs
for the code in the block that's run. | [
"Specify",
"whether",
"to",
"accept",
"or",
"reject",
"all",
"confirm",
"js",
"dialogs",
"for",
"the",
"code",
"in",
"the",
"block",
"that",
"s",
"run",
"."
] | 8e330ce79e88d00a213ece7755a22f4e0ca4f042 | https://github.com/langalex/culerity/blob/8e330ce79e88d00a213ece7755a22f4e0ca4f042/lib/culerity/remote_browser_proxy.rb#L52-L58 | train |
uasi/pixiv | lib/pixiv/page.rb | Pixiv.Page.bind | def bind(client)
if self.class.const_defined?(:WithClient)
mod = self.class.const_get(:WithClient)
else
mod = Page::WithClient
end
unless singleton_class.include?(mod)
extend(mod)
end
self.client = client
self
end | ruby | def bind(client)
if self.class.const_defined?(:WithClient)
mod = self.class.const_get(:WithClient)
else
mod = Page::WithClient
end
unless singleton_class.include?(mod)
extend(mod)
end
self.client = client
self
end | [
"def",
"bind",
"(",
"client",
")",
"if",
"self",
".",
"class",
".",
"const_defined?",
"(",
":WithClient",
")",
"mod",
"=",
"self",
".",
"class",
".",
"const_get",
"(",
":WithClient",
")",
"else",
"mod",
"=",
"Page",
"::",
"WithClient",
"end",
"unless",
... | Bind +self+ to +client+
@api private
@return self | [
"Bind",
"+",
"self",
"+",
"to",
"+",
"client",
"+"
] | 6750829692fa9c3f56605d3319616072756c9d7c | https://github.com/uasi/pixiv/blob/6750829692fa9c3f56605d3319616072756c9d7c/lib/pixiv/page.rb#L58-L69 | train |
uasi/pixiv | lib/pixiv/client.rb | Pixiv.Client.login | def login(pixiv_id, password)
doc = agent.get("https://accounts.pixiv.net/login?lang=ja&source=pc&view_type=page")
return if doc && doc.body =~ /logout/
form = doc.forms_with(action: '/login').first
puts doc.body and raise Error::LoginFailed, 'login form is not available' unless form
form.... | ruby | def login(pixiv_id, password)
doc = agent.get("https://accounts.pixiv.net/login?lang=ja&source=pc&view_type=page")
return if doc && doc.body =~ /logout/
form = doc.forms_with(action: '/login').first
puts doc.body and raise Error::LoginFailed, 'login form is not available' unless form
form.... | [
"def",
"login",
"(",
"pixiv_id",
",",
"password",
")",
"doc",
"=",
"agent",
".",
"get",
"(",
"\"https://accounts.pixiv.net/login?lang=ja&source=pc&view_type=page\"",
")",
"return",
"if",
"doc",
"&&",
"doc",
".",
"body",
"=~",
"/",
"/",
"form",
"=",
"doc",
".",... | A new instance of Client, logged in with the given credentials
@overload initialize(pixiv_id, password)
@param [String] pixiv_id
@param [String] password
@yield [agent] (optional) gives a chance to customize the +agent+ before logging in
@overload initialize(agent)
@param [Mechanize::HTTP::Agent] agent
@... | [
"A",
"new",
"instance",
"of",
"Client",
"logged",
"in",
"with",
"the",
"given",
"credentials"
] | 6750829692fa9c3f56605d3319616072756c9d7c | https://github.com/uasi/pixiv/blob/6750829692fa9c3f56605d3319616072756c9d7c/lib/pixiv/client.rb#L43-L53 | train |
uasi/pixiv | lib/pixiv/client.rb | Pixiv.Client.download_illust | def download_illust(illust, io_or_filename, size = :original)
size = {:s => :small, :m => :medium, :o => :original}[size] || size
url = illust.__send__("#{size}_image_url")
referer = case size
when :small then nil
when :medium then illust.url
when :origi... | ruby | def download_illust(illust, io_or_filename, size = :original)
size = {:s => :small, :m => :medium, :o => :original}[size] || size
url = illust.__send__("#{size}_image_url")
referer = case size
when :small then nil
when :medium then illust.url
when :origi... | [
"def",
"download_illust",
"(",
"illust",
",",
"io_or_filename",
",",
"size",
"=",
":original",
")",
"size",
"=",
"{",
":s",
"=>",
":small",
",",
":m",
"=>",
":medium",
",",
":o",
"=>",
":original",
"}",
"[",
"size",
"]",
"||",
"size",
"url",
"=",
"il... | Downloads the image to +io_or_filename+
@param [Pixiv::Illust] illust
@param [#write, String, Array<String, Symbol, #call>] io_or_filename io or filename or pattern for {#filename_from_pattern}
@param [Symbol] size image size (+:small+, +:medium+, or +:original+) | [
"Downloads",
"the",
"image",
"to",
"+",
"io_or_filename",
"+"
] | 6750829692fa9c3f56605d3319616072756c9d7c | https://github.com/uasi/pixiv/blob/6750829692fa9c3f56605d3319616072756c9d7c/lib/pixiv/client.rb#L141-L156 | train |
uasi/pixiv | lib/pixiv/client.rb | Pixiv.Client.download_manga | def download_manga(illust, pattern, &block)
action = DownloadActionRegistry.new(&block)
illust.original_image_urls.each_with_index do |url, n|
begin
action.before_each.call(url, n) if action.before_each
filename = filename_from_pattern(pattern, illust, url)
FileUtils.mk... | ruby | def download_manga(illust, pattern, &block)
action = DownloadActionRegistry.new(&block)
illust.original_image_urls.each_with_index do |url, n|
begin
action.before_each.call(url, n) if action.before_each
filename = filename_from_pattern(pattern, illust, url)
FileUtils.mk... | [
"def",
"download_manga",
"(",
"illust",
",",
"pattern",
",",
"&",
"block",
")",
"action",
"=",
"DownloadActionRegistry",
".",
"new",
"(",
"&",
"block",
")",
"illust",
".",
"original_image_urls",
".",
"each_with_index",
"do",
"|",
"url",
",",
"n",
"|",
"beg... | Downloads the images to +pattern+
@param [Pixiv::Illust] illust the manga to download
@param [Array<String, Symbol, #call>] pattern pattern for {#filename_from_pattern}
@note +illust#manga?+ must be +true+
@todo Document +&block+ | [
"Downloads",
"the",
"images",
"to",
"+",
"pattern",
"+"
] | 6750829692fa9c3f56605d3319616072756c9d7c | https://github.com/uasi/pixiv/blob/6750829692fa9c3f56605d3319616072756c9d7c/lib/pixiv/client.rb#L163-L176 | train |
uasi/pixiv | lib/pixiv/client.rb | Pixiv.Client.filename_from_pattern | def filename_from_pattern(pattern, illust, url)
pattern.map {|i|
if i == :image_name
name = File.basename(url)
if name =~ /\.(\w+)\?\d+$/
name += '.' + $1
end
name
elsif i.is_a?(Symbol) then illust.send(i)
elsif i.respond_to?(:call) then ... | ruby | def filename_from_pattern(pattern, illust, url)
pattern.map {|i|
if i == :image_name
name = File.basename(url)
if name =~ /\.(\w+)\?\d+$/
name += '.' + $1
end
name
elsif i.is_a?(Symbol) then illust.send(i)
elsif i.respond_to?(:call) then ... | [
"def",
"filename_from_pattern",
"(",
"pattern",
",",
"illust",
",",
"url",
")",
"pattern",
".",
"map",
"{",
"|",
"i",
"|",
"if",
"i",
"==",
":image_name",
"name",
"=",
"File",
".",
"basename",
"(",
"url",
")",
"if",
"name",
"=~",
"/",
"\\.",
"\\w",
... | Generate filename from +pattern+ in context of +illust+ and +url+
@api private
@param [Array<String, Symbol, #call>] pattern
@param [Pixiv::Illust] illust
@param [String] url
@return [String] filename
The +pattern+ is an array of string, symbol, or object that responds to +#call+.
Each component of the +patter... | [
"Generate",
"filename",
"from",
"+",
"pattern",
"+",
"in",
"context",
"of",
"+",
"illust",
"+",
"and",
"+",
"url",
"+"
] | 6750829692fa9c3f56605d3319616072756c9d7c | https://github.com/uasi/pixiv/blob/6750829692fa9c3f56605d3319616072756c9d7c/lib/pixiv/client.rb#L194-L207 | train |
lantins/dns-zone | lib/dns/zone.rb | DNS.Zone.soa | def soa
# return the first SOA we find in the records array.
rr = @records.find { |rr| rr.type == "SOA" }
return rr if rr
# otherwise create a new SOA
rr = DNS::Zone::RR::SOA.new
rr.serial = Time.now.utc.strftime("%Y%m%d01")
rr.refresh_ttl = '3h'
rr.retry_ttl = '15m'
... | ruby | def soa
# return the first SOA we find in the records array.
rr = @records.find { |rr| rr.type == "SOA" }
return rr if rr
# otherwise create a new SOA
rr = DNS::Zone::RR::SOA.new
rr.serial = Time.now.utc.strftime("%Y%m%d01")
rr.refresh_ttl = '3h'
rr.retry_ttl = '15m'
... | [
"def",
"soa",
"rr",
"=",
"@records",
".",
"find",
"{",
"|",
"rr",
"|",
"rr",
".",
"type",
"==",
"\"SOA\"",
"}",
"return",
"rr",
"if",
"rr",
"rr",
"=",
"DNS",
"::",
"Zone",
"::",
"RR",
"::",
"SOA",
".",
"new",
"rr",
".",
"serial",
"=",
"Time",
... | Create an empty instance of a DNS zone that you can drive programmatically.
@api public
Helper method to access the zones SOA RR.
@api public | [
"Create",
"an",
"empty",
"instance",
"of",
"a",
"DNS",
"zone",
"that",
"you",
"can",
"drive",
"programmatically",
"."
] | f60cbfd7ec72217288be6c6ece9a83c22350cb58 | https://github.com/lantins/dns-zone/blob/f60cbfd7ec72217288be6c6ece9a83c22350cb58/lib/dns/zone.rb#L36-L50 | train |
lantins/dns-zone | lib/dns/zone.rb | DNS.Zone.dump_pretty | def dump_pretty
content = []
last_type = "SOA"
sorted_records.each do |rr|
content << '' if last_type != rr.type
content << rr.dump
last_type = rr.type
end
content.join("\n") << "\n"
end | ruby | def dump_pretty
content = []
last_type = "SOA"
sorted_records.each do |rr|
content << '' if last_type != rr.type
content << rr.dump
last_type = rr.type
end
content.join("\n") << "\n"
end | [
"def",
"dump_pretty",
"content",
"=",
"[",
"]",
"last_type",
"=",
"\"SOA\"",
"sorted_records",
".",
"each",
"do",
"|",
"rr",
"|",
"content",
"<<",
"''",
"if",
"last_type",
"!=",
"rr",
".",
"type",
"content",
"<<",
"rr",
".",
"dump",
"last_type",
"=",
"... | Generates pretty output of the zone and its records.
@api public | [
"Generates",
"pretty",
"output",
"of",
"the",
"zone",
"and",
"its",
"records",
"."
] | f60cbfd7ec72217288be6c6ece9a83c22350cb58 | https://github.com/lantins/dns-zone/blob/f60cbfd7ec72217288be6c6ece9a83c22350cb58/lib/dns/zone.rb#L68-L79 | train |
lantins/dns-zone | lib/dns/zone.rb | DNS.Zone.sorted_records | def sorted_records
# pull out RRs we want to stick near the top
top_rrs = {}
top = %w{SOA NS MX SPF TXT}
top.each { |t| top_rrs[t] = @records.select { |rr| rr.type == t } }
remaining = @records.reject { |rr| top.include?(rr.type) }
# sort remaining RRs by type, alphabeticly
r... | ruby | def sorted_records
# pull out RRs we want to stick near the top
top_rrs = {}
top = %w{SOA NS MX SPF TXT}
top.each { |t| top_rrs[t] = @records.select { |rr| rr.type == t } }
remaining = @records.reject { |rr| top.include?(rr.type) }
# sort remaining RRs by type, alphabeticly
r... | [
"def",
"sorted_records",
"top_rrs",
"=",
"{",
"}",
"top",
"=",
"%w{",
"SOA",
"NS",
"MX",
"SPF",
"TXT",
"}",
"top",
".",
"each",
"{",
"|",
"t",
"|",
"top_rrs",
"[",
"t",
"]",
"=",
"@records",
".",
"select",
"{",
"|",
"rr",
"|",
"rr",
".",
"type"... | Records sorted with more important types being at the top.
@api private | [
"Records",
"sorted",
"with",
"more",
"important",
"types",
"being",
"at",
"the",
"top",
"."
] | f60cbfd7ec72217288be6c6ece9a83c22350cb58 | https://github.com/lantins/dns-zone/blob/f60cbfd7ec72217288be6c6ece9a83c22350cb58/lib/dns/zone.rb#L191-L203 | train |
potatosalad/ruby-erlang-terms | lib/erlang/associable.rb | Erlang.Associable.update_in | def update_in(*key_path, &block)
if key_path.empty?
raise ArgumentError, "must have at least one key in path"
end
key = key_path[0]
if key_path.size == 1
new_value = block.call(fetch(key, nil))
else
value = fetch(key, EmptyMap)
new_value = value.update_in(*k... | ruby | def update_in(*key_path, &block)
if key_path.empty?
raise ArgumentError, "must have at least one key in path"
end
key = key_path[0]
if key_path.size == 1
new_value = block.call(fetch(key, nil))
else
value = fetch(key, EmptyMap)
new_value = value.update_in(*k... | [
"def",
"update_in",
"(",
"*",
"key_path",
",",
"&",
"block",
")",
"if",
"key_path",
".",
"empty?",
"raise",
"ArgumentError",
",",
"\"must have at least one key in path\"",
"end",
"key",
"=",
"key_path",
"[",
"0",
"]",
"if",
"key_path",
".",
"size",
"==",
"1"... | Return a new container with a deeply nested value modified to the result
of the given code block. When traversing the nested containers
non-existing keys are created with empty `Hash` values.
The code block receives the existing value of the deeply nested key/index
(or `nil` if it doesn't exist). This is useful f... | [
"Return",
"a",
"new",
"container",
"with",
"a",
"deeply",
"nested",
"value",
"modified",
"to",
"the",
"result",
"of",
"the",
"given",
"code",
"block",
".",
"When",
"traversing",
"the",
"nested",
"containers",
"non",
"-",
"existing",
"keys",
"are",
"created",... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/associable.rb#L63-L75 | train |
potatosalad/ruby-erlang-terms | lib/erlang/associable.rb | Erlang.Associable.dig | def dig(key, *rest)
value = get(key)
if rest.empty? || value.nil?
return value
elsif value.respond_to?(:dig)
return value.dig(*rest)
end
end | ruby | def dig(key, *rest)
value = get(key)
if rest.empty? || value.nil?
return value
elsif value.respond_to?(:dig)
return value.dig(*rest)
end
end | [
"def",
"dig",
"(",
"key",
",",
"*",
"rest",
")",
"value",
"=",
"get",
"(",
"key",
")",
"if",
"rest",
".",
"empty?",
"||",
"value",
".",
"nil?",
"return",
"value",
"elsif",
"value",
".",
"respond_to?",
"(",
":dig",
")",
"return",
"value",
".",
"dig"... | Return the value of successively indexing into a collection.
If any of the keys is not present in the collection, return `nil`.
keys that the Erlang type doesn't understand, raises an argument error
@example
m = Erlang::Map[:a => 9, :b => Erlang::Tuple['a', 'b'], :e => nil]
m.dig(:b, 0) # => "a"
m.dig(:... | [
"Return",
"the",
"value",
"of",
"successively",
"indexing",
"into",
"a",
"collection",
".",
"If",
"any",
"of",
"the",
"keys",
"is",
"not",
"present",
"in",
"the",
"collection",
"return",
"nil",
".",
"keys",
"that",
"the",
"Erlang",
"type",
"doesn",
"t",
... | a3eaa3d976610466a5f5da177109a1248dac020d | https://github.com/potatosalad/ruby-erlang-terms/blob/a3eaa3d976610466a5f5da177109a1248dac020d/lib/erlang/associable.rb#L89-L96 | train |
ustasb/pandata | lib/pandata/scraper.rb | Pandata.Scraper.download_all_data | def download_all_data(url)
next_data_indices = {}
while next_data_indices
html = Downloader.read_page(url)
# Sometimes Pandora returns the same next_data_indices as the previous page.
# If we don't check for this, an infinite loop occurs.
# This problem occurs with tconrad.... | ruby | def download_all_data(url)
next_data_indices = {}
while next_data_indices
html = Downloader.read_page(url)
# Sometimes Pandora returns the same next_data_indices as the previous page.
# If we don't check for this, an infinite loop occurs.
# This problem occurs with tconrad.... | [
"def",
"download_all_data",
"(",
"url",
")",
"next_data_indices",
"=",
"{",
"}",
"while",
"next_data_indices",
"html",
"=",
"Downloader",
".",
"read_page",
"(",
"url",
")",
"prev_next_data_indices",
"=",
"next_data_indices",
"next_data_indices",
"=",
"@parser",
".",... | Downloads all data given a starting URL. Some Pandora feeds only return
5 - 10 items per page but contain a link to the next set of data. Threads
cannot be used because page A be must visited to know how to obtain page B.
@param url [String] | [
"Downloads",
"all",
"data",
"given",
"a",
"starting",
"URL",
".",
"Some",
"Pandora",
"feeds",
"only",
"return",
"5",
"-",
"10",
"items",
"per",
"page",
"but",
"contain",
"a",
"link",
"to",
"the",
"next",
"set",
"of",
"data",
".",
"Threads",
"cannot",
"... | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/scraper.rb#L119-L134 | train |
ustasb/pandata | lib/pandata/scraper.rb | Pandata.Scraper.get_url | def get_url(data_name, next_data_indices = {})
if next_data_indices.empty?
next_data_indices = { nextStartIndex: 0, nextLikeStartIndex: 0, nextThumbStartIndex: 0 }
else
next_data_indices = next_data_indices.dup
end
next_data_indices[:webname] = @webname
next_data_indices[:... | ruby | def get_url(data_name, next_data_indices = {})
if next_data_indices.empty?
next_data_indices = { nextStartIndex: 0, nextLikeStartIndex: 0, nextThumbStartIndex: 0 }
else
next_data_indices = next_data_indices.dup
end
next_data_indices[:webname] = @webname
next_data_indices[:... | [
"def",
"get_url",
"(",
"data_name",
",",
"next_data_indices",
"=",
"{",
"}",
")",
"if",
"next_data_indices",
".",
"empty?",
"next_data_indices",
"=",
"{",
"nextStartIndex",
":",
"0",
",",
"nextLikeStartIndex",
":",
"0",
",",
"nextThumbStartIndex",
":",
"0",
"}... | Grabs a URL from DATA_FEED_URLS and formats it appropriately.
@param data_name [Symbol]
@param next_data_indices [Symbol] query parameters to get the next set of data | [
"Grabs",
"a",
"URL",
"from",
"DATA_FEED_URLS",
"and",
"formats",
"it",
"appropriately",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/scraper.rb#L139-L150 | train |
dennisreimann/masq | app/models/masq/account.rb | Masq.Account.yubikey_authenticated? | def yubikey_authenticated?(otp)
if yubico_identity? && Account.verify_yubico_otp(otp)
(Account.extract_yubico_identity_from_otp(otp) == yubico_identity)
else
false
end
end | ruby | def yubikey_authenticated?(otp)
if yubico_identity? && Account.verify_yubico_otp(otp)
(Account.extract_yubico_identity_from_otp(otp) == yubico_identity)
else
false
end
end | [
"def",
"yubikey_authenticated?",
"(",
"otp",
")",
"if",
"yubico_identity?",
"&&",
"Account",
".",
"verify_yubico_otp",
"(",
"otp",
")",
"(",
"Account",
".",
"extract_yubico_identity_from_otp",
"(",
"otp",
")",
"==",
"yubico_identity",
")",
"else",
"false",
"end",
... | Is the Yubico OTP valid and belongs to this account? | [
"Is",
"the",
"Yubico",
"OTP",
"valid",
"and",
"belongs",
"to",
"this",
"account?"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/models/masq/account.rb#L127-L133 | train |
qoobaa/vcard | lib/vcard/dirinfo.rb | Vcard.DirectoryInfo.[] | def [](name)
enum_by_name(name).each { |f| return f.value if f.value != ""}
enum_by_name(name).each { |f| return f.value }
nil
end | ruby | def [](name)
enum_by_name(name).each { |f| return f.value if f.value != ""}
enum_by_name(name).each { |f| return f.value }
nil
end | [
"def",
"[]",
"(",
"name",
")",
"enum_by_name",
"(",
"name",
")",
".",
"each",
"{",
"|",
"f",
"|",
"return",
"f",
".",
"value",
"if",
"f",
".",
"value",
"!=",
"\"\"",
"}",
"enum_by_name",
"(",
"name",
")",
".",
"each",
"{",
"|",
"f",
"|",
"retur... | The value of the first field named +name+, or nil if no
match is found. | [
"The",
"value",
"of",
"the",
"first",
"field",
"named",
"+",
"name",
"+",
"or",
"nil",
"if",
"no",
"match",
"is",
"found",
"."
] | 0cab080676df262555e3adadc9a82fedc128d337 | https://github.com/qoobaa/vcard/blob/0cab080676df262555e3adadc9a82fedc128d337/lib/vcard/dirinfo.rb#L113-L117 | train |
qoobaa/vcard | lib/vcard/dirinfo.rb | Vcard.DirectoryInfo.push_unique | def push_unique(field)
push(field) unless @fields.detect { |f| f.name? field.name }
self
end | ruby | def push_unique(field)
push(field) unless @fields.detect { |f| f.name? field.name }
self
end | [
"def",
"push_unique",
"(",
"field",
")",
"push",
"(",
"field",
")",
"unless",
"@fields",
".",
"detect",
"{",
"|",
"f",
"|",
"f",
".",
"name?",
"field",
".",
"name",
"}",
"self",
"end"
] | Push +field+ onto the fields, unless there is already a field
with this name. | [
"Push",
"+",
"field",
"+",
"onto",
"the",
"fields",
"unless",
"there",
"is",
"already",
"a",
"field",
"with",
"this",
"name",
"."
] | 0cab080676df262555e3adadc9a82fedc128d337 | https://github.com/qoobaa/vcard/blob/0cab080676df262555e3adadc9a82fedc128d337/lib/vcard/dirinfo.rb#L212-L215 | train |
qoobaa/vcard | lib/vcard/dirinfo.rb | Vcard.DirectoryInfo.delete | def delete(field)
case
when field.name?("BEGIN"), field.name?("END")
raise ArgumentError, "Cannot delete BEGIN or END fields."
else
@fields.delete field
end
self
end | ruby | def delete(field)
case
when field.name?("BEGIN"), field.name?("END")
raise ArgumentError, "Cannot delete BEGIN or END fields."
else
@fields.delete field
end
self
end | [
"def",
"delete",
"(",
"field",
")",
"case",
"when",
"field",
".",
"name?",
"(",
"\"BEGIN\"",
")",
",",
"field",
".",
"name?",
"(",
"\"END\"",
")",
"raise",
"ArgumentError",
",",
"\"Cannot delete BEGIN or END fields.\"",
"else",
"@fields",
".",
"delete",
"field... | Delete +field+.
Warning: You can't delete BEGIN: or END: fields, but other
profile-specific fields can be deleted, including mandatory ones. For
vCards in particular, in order to avoid destroying them, I suggest
creating a new Vcard, and copying over all the fields that you still
want, rather than using #delete. ... | [
"Delete",
"+",
"field",
"+",
"."
] | 0cab080676df262555e3adadc9a82fedc128d337 | https://github.com/qoobaa/vcard/blob/0cab080676df262555e3adadc9a82fedc128d337/lib/vcard/dirinfo.rb#L233-L242 | train |
tomharris/random_data | lib/random_data/numbers.rb | RandomData.Numbers.number | def number(n)
n.is_a?(Range) ? n.to_a.rand : rand(n)
end | ruby | def number(n)
n.is_a?(Range) ? n.to_a.rand : rand(n)
end | [
"def",
"number",
"(",
"n",
")",
"n",
".",
"is_a?",
"(",
"Range",
")",
"?",
"n",
".",
"to_a",
".",
"rand",
":",
"rand",
"(",
"n",
")",
"end"
] | n can be an Integer or a Range. If it is an Integer, it just returns a random
number greater than or equal to 0 and less than n. If it is a Range, it
returns a random number within the range
Examples
>> Random.number(5)
=> 4
>> Random.number(5)
=> 2
>> Random.number(5)
=> 1 | [
"n",
"can",
"be",
"an",
"Integer",
"or",
"a",
"Range",
".",
"If",
"it",
"is",
"an",
"Integer",
"it",
"just",
"returns",
"a",
"random",
"number",
"greater",
"than",
"or",
"equal",
"to",
"0",
"and",
"less",
"than",
"n",
".",
"If",
"it",
"is",
"a",
... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/numbers.rb#L14-L16 | train |
rmosolgo/css_modules | lib/css_modules/rewrite.rb | CSSModules.Rewrite.rewrite_css | def rewrite_css(css_module_code)
# Parse incoming CSS into an AST
css_root = Sass::SCSS::CssParser.new(css_module_code, "(CSSModules)", 1).parse
Sass::Tree::Visitors::SetOptions.visit(css_root, {})
ModuleVisitor.visit(css_root)
css_root.render
end | ruby | def rewrite_css(css_module_code)
# Parse incoming CSS into an AST
css_root = Sass::SCSS::CssParser.new(css_module_code, "(CSSModules)", 1).parse
Sass::Tree::Visitors::SetOptions.visit(css_root, {})
ModuleVisitor.visit(css_root)
css_root.render
end | [
"def",
"rewrite_css",
"(",
"css_module_code",
")",
"css_root",
"=",
"Sass",
"::",
"SCSS",
"::",
"CssParser",
".",
"new",
"(",
"css_module_code",
",",
"\"(CSSModules)\"",
",",
"1",
")",
".",
"parse",
"Sass",
"::",
"Tree",
"::",
"Visitors",
"::",
"SetOptions",... | Take css module code as input, and rewrite it as
browser-friendly CSS code. Apply opaque transformations
so that selectors can only be accessed programatically,
not by class name literals. | [
"Take",
"css",
"module",
"code",
"as",
"input",
"and",
"rewrite",
"it",
"as",
"browser",
"-",
"friendly",
"CSS",
"code",
".",
"Apply",
"opaque",
"transformations",
"so",
"that",
"selectors",
"can",
"only",
"be",
"accessed",
"programatically",
"not",
"by",
"c... | c1a80f6b7b76193c7dda616877a75eec6bbe600d | https://github.com/rmosolgo/css_modules/blob/c1a80f6b7b76193c7dda616877a75eec6bbe600d/lib/css_modules/rewrite.rb#L15-L23 | train |
tomharris/random_data | lib/random_data/grammar.rb | RandomData.Grammar.grammatical_construct | def grammatical_construct(grammar, what=nil)
output = ""
if what.nil?
case grammar
when Hash
a_key = grammar.keys.sort_by{rand}[0]
output += grammatical_construct(grammar, a_key)
when Array
grammar.each do |item|
output += grammatical_constru... | ruby | def grammatical_construct(grammar, what=nil)
output = ""
if what.nil?
case grammar
when Hash
a_key = grammar.keys.sort_by{rand}[0]
output += grammatical_construct(grammar, a_key)
when Array
grammar.each do |item|
output += grammatical_constru... | [
"def",
"grammatical_construct",
"(",
"grammar",
",",
"what",
"=",
"nil",
")",
"output",
"=",
"\"\"",
"if",
"what",
".",
"nil?",
"case",
"grammar",
"when",
"Hash",
"a_key",
"=",
"grammar",
".",
"keys",
".",
"sort_by",
"{",
"rand",
"}",
"[",
"0",
"]",
... | Returns simple sentences based on a supplied grammar, which must be a hash, the
keys of which are symbols. The values are either an array of successive values or a grammar
(i.e, hash with symbols as keys, and hashes or arrays as values. The arrays contain symbols
referencing the keys in the present grammar, or str... | [
"Returns",
"simple",
"sentences",
"based",
"on",
"a",
"supplied",
"grammar",
"which",
"must",
"be",
"a",
"hash",
"the",
"keys",
"of",
"which",
"are",
"symbols",
".",
"The",
"values",
"are",
"either",
"an",
"array",
"of",
"successive",
"values",
"or",
"a",
... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/grammar.rb#L17-L58 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/location.rb | GoogleStaticMapsHelper.Location.endpoints_for_circle_with_radius | def endpoints_for_circle_with_radius(radius, steps = 30)
raise ArgumentError, "Number of points has to be in range of 1..360!" unless (1..360).include? steps
points = []
steps.times do |i|
points << endpoint(radius, i * 360 / steps)
end
points << points.first
points
en... | ruby | def endpoints_for_circle_with_radius(radius, steps = 30)
raise ArgumentError, "Number of points has to be in range of 1..360!" unless (1..360).include? steps
points = []
steps.times do |i|
points << endpoint(radius, i * 360 / steps)
end
points << points.first
points
en... | [
"def",
"endpoints_for_circle_with_radius",
"(",
"radius",
",",
"steps",
"=",
"30",
")",
"raise",
"ArgumentError",
",",
"\"Number of points has to be in range of 1..360!\"",
"unless",
"(",
"1",
"..",
"360",
")",
".",
"include?",
"steps",
"points",
"=",
"[",
"]",
"s... | Returns ends poionts which will make up a circle around current location and have given radius | [
"Returns",
"ends",
"poionts",
"which",
"will",
"make",
"up",
"a",
"circle",
"around",
"current",
"location",
"and",
"have",
"given",
"radius"
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/location.rb#L81-L91 | train |
tomharris/random_data | lib/random_data/names.rb | RandomData.Names.companyname | def companyname
num = rand(5)
if num == 0
num = 1
end
final = num.times.collect { @@lastnames.rand.capitalize }
if final.count == 1
"#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}"
else
incorporation_type = rand(17) % 2 == 0 ? @@incorpo... | ruby | def companyname
num = rand(5)
if num == 0
num = 1
end
final = num.times.collect { @@lastnames.rand.capitalize }
if final.count == 1
"#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}"
else
incorporation_type = rand(17) % 2 == 0 ? @@incorpo... | [
"def",
"companyname",
"num",
"=",
"rand",
"(",
"5",
")",
"if",
"num",
"==",
"0",
"num",
"=",
"1",
"end",
"final",
"=",
"num",
".",
"times",
".",
"collect",
"{",
"@@lastnames",
".",
"rand",
".",
"capitalize",
"}",
"if",
"final",
".",
"count",
"==",
... | Returns a random company name
>> Random.company_name
"Harris & Thomas" | [
"Returns",
"a",
"random",
"company",
"name"
] | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/names.rb#L26-L42 | train |
jhass/open_graph_reader | lib/open_graph_reader/builder.rb | OpenGraphReader.Builder.base | def base
base = Base.new
type = @parser.graph.fetch("og:type", "website").downcase
validate_type type
@parser.graph.each do |property|
build_property base, property
end
synthesize_required_properties base
drop_empty_children base
validate base
base
... | ruby | def base
base = Base.new
type = @parser.graph.fetch("og:type", "website").downcase
validate_type type
@parser.graph.each do |property|
build_property base, property
end
synthesize_required_properties base
drop_empty_children base
validate base
base
... | [
"def",
"base",
"base",
"=",
"Base",
".",
"new",
"type",
"=",
"@parser",
".",
"graph",
".",
"fetch",
"(",
"\"og:type\"",
",",
"\"website\"",
")",
".",
"downcase",
"validate_type",
"type",
"@parser",
".",
"graph",
".",
"each",
"do",
"|",
"property",
"|",
... | Create a new builder.
@param [Parser] parser
@see Parser#graph
@see Parser#additional_namespaces
Build and return the base.
@return [Base] | [
"Create",
"a",
"new",
"builder",
"."
] | 5488354b7dd75b5411a881d734aa7176546e7cb4 | https://github.com/jhass/open_graph_reader/blob/5488354b7dd75b5411a881d734aa7176546e7cb4/lib/open_graph_reader/builder.rb#L24-L40 | train |
dennisreimann/masq | app/helpers/masq/application_helper.rb | Masq.ApplicationHelper.nav | def nav(name, url, pages = nil, active = false)
content_tag :li, link_to(name, url), :class => (active || (pages && active_page?(pages)) ? 'act' : nil)
end | ruby | def nav(name, url, pages = nil, active = false)
content_tag :li, link_to(name, url), :class => (active || (pages && active_page?(pages)) ? 'act' : nil)
end | [
"def",
"nav",
"(",
"name",
",",
"url",
",",
"pages",
"=",
"nil",
",",
"active",
"=",
"false",
")",
"content_tag",
":li",
",",
"link_to",
"(",
"name",
",",
"url",
")",
",",
":class",
"=>",
"(",
"active",
"||",
"(",
"pages",
"&&",
"active_page?",
"("... | Renders a navigation element and marks it as active where
appropriate. See active_page? for details | [
"Renders",
"a",
"navigation",
"element",
"and",
"marks",
"it",
"as",
"active",
"where",
"appropriate",
".",
"See",
"active_page?",
"for",
"details"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/helpers/masq/application_helper.rb#L45-L47 | train |
dennisreimann/masq | app/helpers/masq/application_helper.rb | Masq.ApplicationHelper.active_page? | def active_page?(pages = {})
is_active = pages.include?(params[:controller])
is_active = pages[params[:controller]].include?(params[:action]) if is_active && !pages[params[:controller]].empty?
is_active
end | ruby | def active_page?(pages = {})
is_active = pages.include?(params[:controller])
is_active = pages[params[:controller]].include?(params[:action]) if is_active && !pages[params[:controller]].empty?
is_active
end | [
"def",
"active_page?",
"(",
"pages",
"=",
"{",
"}",
")",
"is_active",
"=",
"pages",
".",
"include?",
"(",
"params",
"[",
":controller",
"]",
")",
"is_active",
"=",
"pages",
"[",
"params",
"[",
":controller",
"]",
"]",
".",
"include?",
"(",
"params",
"[... | Takes a hash with pages and tells whether the current page is among them.
The keys must be controller names and their value must be an array of
action names. If the array is empty, every action is supposed to be valid. | [
"Takes",
"a",
"hash",
"with",
"pages",
"and",
"tells",
"whether",
"the",
"current",
"page",
"is",
"among",
"them",
".",
"The",
"keys",
"must",
"be",
"controller",
"names",
"and",
"their",
"value",
"must",
"be",
"an",
"array",
"of",
"action",
"names",
"."... | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/helpers/masq/application_helper.rb#L52-L56 | train |
ustasb/pandata | lib/pandata/parser.rb | Pandata.Parser.get_webnames_from_search | def get_webnames_from_search(html)
user_links = Nokogiri::HTML(html).css('.user_name a')
webnames = []
user_links.each do |link|
webnames << link['webname']
end
webnames
end | ruby | def get_webnames_from_search(html)
user_links = Nokogiri::HTML(html).css('.user_name a')
webnames = []
user_links.each do |link|
webnames << link['webname']
end
webnames
end | [
"def",
"get_webnames_from_search",
"(",
"html",
")",
"user_links",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
".",
"css",
"(",
"'.user_name a'",
")",
"webnames",
"=",
"[",
"]",
"user_links",
".",
"each",
"do",
"|",
"link",
"|",
"webnames",
"<<",
"l... | Get the webnames from a user ID search.
@param html [String]
@return [Array] array of webnames | [
"Get",
"the",
"webnames",
"from",
"a",
"user",
"ID",
"search",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/parser.rb#L11-L20 | train |
ustasb/pandata | lib/pandata/parser.rb | Pandata.Parser.get_next_data_indices | def get_next_data_indices(html)
# .js-more-link is found on mobile pages.
show_more = Nokogiri::HTML(html).css('.show_more, .js-more-link')[0]
if show_more
next_indices = {}
data_attributes = ['nextStartIndex', 'nextLikeStartIndex', 'nextThumbStartIndex']
data_attributes.each ... | ruby | def get_next_data_indices(html)
# .js-more-link is found on mobile pages.
show_more = Nokogiri::HTML(html).css('.show_more, .js-more-link')[0]
if show_more
next_indices = {}
data_attributes = ['nextStartIndex', 'nextLikeStartIndex', 'nextThumbStartIndex']
data_attributes.each ... | [
"def",
"get_next_data_indices",
"(",
"html",
")",
"show_more",
"=",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
".",
"css",
"(",
"'.show_more, .js-more-link'",
")",
"[",
"0",
"]",
"if",
"show_more",
"next_indices",
"=",
"{",
"}",
"data_attributes",
"=",
"[",... | Get the query parameters necessary to get the next page of data from Pandora.
@param html [String]
@return [Hash, False] | [
"Get",
"the",
"query",
"parameters",
"necessary",
"to",
"get",
"the",
"next",
"page",
"of",
"data",
"from",
"Pandora",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/parser.rb#L25-L41 | train |
ustasb/pandata | lib/pandata/parser.rb | Pandata.Parser.infobox_each_link | def infobox_each_link(html)
Nokogiri::HTML(html).css('.infobox').each do |infobox|
infobox_body = infobox.css('.infobox-body')
title_link = infobox_body.css('h3 a').text.strip
subtitle_link = infobox_body.css('p a').first
subtitle_link = subtitle_link.text.strip if subtitle_link
... | ruby | def infobox_each_link(html)
Nokogiri::HTML(html).css('.infobox').each do |infobox|
infobox_body = infobox.css('.infobox-body')
title_link = infobox_body.css('h3 a').text.strip
subtitle_link = infobox_body.css('p a').first
subtitle_link = subtitle_link.text.strip if subtitle_link
... | [
"def",
"infobox_each_link",
"(",
"html",
")",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
".",
"css",
"(",
"'.infobox'",
")",
".",
"each",
"do",
"|",
"infobox",
"|",
"infobox_body",
"=",
"infobox",
".",
"css",
"(",
"'.infobox-body'",
")",
"title_link",
"... | Loops over each .infobox container and yields the title and subtitle.
@param html [String] | [
"Loops",
"over",
"each",
".",
"infobox",
"container",
"and",
"yields",
"the",
"title",
"and",
"subtitle",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/parser.rb#L96-L106 | train |
ustasb/pandata | lib/pandata/parser.rb | Pandata.Parser.doublelink_each_link | def doublelink_each_link(html)
Nokogiri::HTML(html).css('.double-link').each do |doublelink|
title_link = doublelink.css('.media__bd__header').text.strip
subtitle_link = doublelink.css('.media__bd__subheader').text.strip
yield(title_link, subtitle_link)
end
end | ruby | def doublelink_each_link(html)
Nokogiri::HTML(html).css('.double-link').each do |doublelink|
title_link = doublelink.css('.media__bd__header').text.strip
subtitle_link = doublelink.css('.media__bd__subheader').text.strip
yield(title_link, subtitle_link)
end
end | [
"def",
"doublelink_each_link",
"(",
"html",
")",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
".",
"css",
"(",
"'.double-link'",
")",
".",
"each",
"do",
"|",
"doublelink",
"|",
"title_link",
"=",
"doublelink",
".",
"css",
"(",
"'.media__bd__header'",
")",
"... | Loops over each .double-link container and yields the title and subtitle.
Encountered on mobile pages.
@param html [String] | [
"Loops",
"over",
"each",
".",
"double",
"-",
"link",
"container",
"and",
"yields",
"the",
"title",
"and",
"subtitle",
".",
"Encountered",
"on",
"mobile",
"pages",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/parser.rb#L111-L118 | train |
ustasb/pandata | lib/pandata/parser.rb | Pandata.Parser.get_followx_users | def get_followx_users(html)
users = []
Nokogiri::HTML(html).css('.follow_section').each do |section|
listener_name = section.css('.listener_name').first
webname = listener_name['webname']
# Remove any 'spans with a space' that sometimes appear with special characters.
liste... | ruby | def get_followx_users(html)
users = []
Nokogiri::HTML(html).css('.follow_section').each do |section|
listener_name = section.css('.listener_name').first
webname = listener_name['webname']
# Remove any 'spans with a space' that sometimes appear with special characters.
liste... | [
"def",
"get_followx_users",
"(",
"html",
")",
"users",
"=",
"[",
"]",
"Nokogiri",
"::",
"HTML",
"(",
"html",
")",
".",
"css",
"(",
"'.follow_section'",
")",
".",
"each",
"do",
"|",
"section",
"|",
"listener_name",
"=",
"section",
".",
"css",
"(",
"'.li... | Loops over each .follow_section container.
@param html [String]
@return [Hash] with keys :name, :webname and :href | [
"Loops",
"over",
"each",
".",
"follow_section",
"container",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/parser.rb#L132-L149 | train |
piotrmurach/tty-platform | lib/tty/platform.rb | TTY.Platform.detect_system_properties | def detect_system_properties(arch)
parts = (arch || architecture).split('-', 2)
if parts.length == 1
@cpu, system = nil, parts.shift
else
@cpu, system = *parts
end
@os, @version = *find_os_and_version(system)
[@cpu, @os, @version]
end | ruby | def detect_system_properties(arch)
parts = (arch || architecture).split('-', 2)
if parts.length == 1
@cpu, system = nil, parts.shift
else
@cpu, system = *parts
end
@os, @version = *find_os_and_version(system)
[@cpu, @os, @version]
end | [
"def",
"detect_system_properties",
"(",
"arch",
")",
"parts",
"=",
"(",
"arch",
"||",
"architecture",
")",
".",
"split",
"(",
"'-'",
",",
"2",
")",
"if",
"parts",
".",
"length",
"==",
"1",
"@cpu",
",",
"system",
"=",
"nil",
",",
"parts",
".",
"shift"... | Infer system properties from architecture information
@return [Array[String, String String]]
@api private | [
"Infer",
"system",
"properties",
"from",
"architecture",
"information"
] | ef35579edc941e79b9bbe1ce3952b961088e2210 | https://github.com/piotrmurach/tty-platform/blob/ef35579edc941e79b9bbe1ce3952b961088e2210/lib/tty/platform.rb#L104-L114 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.decide | def decide
@site = current_account.sites.find_or_initialize_by_url(checkid_request.trust_root)
@site.persona = current_account.personas.find(params[:persona_id] || :first) if sreg_request || ax_store_request || ax_fetch_request
end | ruby | def decide
@site = current_account.sites.find_or_initialize_by_url(checkid_request.trust_root)
@site.persona = current_account.personas.find(params[:persona_id] || :first) if sreg_request || ax_store_request || ax_fetch_request
end | [
"def",
"decide",
"@site",
"=",
"current_account",
".",
"sites",
".",
"find_or_initialize_by_url",
"(",
"checkid_request",
".",
"trust_root",
")",
"@site",
".",
"persona",
"=",
"current_account",
".",
"personas",
".",
"find",
"(",
"params",
"[",
":persona_id",
"]... | Displays the decision page on that the user can confirm the request and
choose which data should be transfered to the relying party. | [
"Displays",
"the",
"decision",
"page",
"on",
"that",
"the",
"user",
"can",
"confirm",
"the",
"request",
"and",
"choose",
"which",
"data",
"should",
"be",
"transfered",
"to",
"the",
"relying",
"party",
"."
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L64-L67 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.complete | def complete
if params[:cancel]
cancel
else
resp = checkid_request.answer(true, nil, identifier(current_account))
if params[:always]
@site = current_account.sites.find_or_create_by_persona_id_and_url(params[:site][:persona_id], params[:site][:url])
@site.update_at... | ruby | def complete
if params[:cancel]
cancel
else
resp = checkid_request.answer(true, nil, identifier(current_account))
if params[:always]
@site = current_account.sites.find_or_create_by_persona_id_and_url(params[:site][:persona_id], params[:site][:url])
@site.update_at... | [
"def",
"complete",
"if",
"params",
"[",
":cancel",
"]",
"cancel",
"else",
"resp",
"=",
"checkid_request",
".",
"answer",
"(",
"true",
",",
"nil",
",",
"identifier",
"(",
"current_account",
")",
")",
"if",
"params",
"[",
":always",
"]",
"@site",
"=",
"cur... | This action is called by submitting the decision form, the information entered by
the user is used to answer the request. If the user decides to always trust the
relying party, a new site according to the release policies the will be created. | [
"This",
"action",
"is",
"called",
"by",
"submitting",
"the",
"decision",
"form",
"the",
"information",
"entered",
"by",
"the",
"user",
"is",
"used",
"to",
"answer",
"the",
"request",
".",
"If",
"the",
"user",
"decides",
"to",
"always",
"trust",
"the",
"rel... | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L72-L107 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.handle_checkid_request | def handle_checkid_request
if allow_verification?
save_checkid_request
redirect_to proceed_path
elsif openid_request.immediate
render_response(openid_request.answer(false))
else
reset_session
request = save_checkid_request
session[:return_to] = proceed_p... | ruby | def handle_checkid_request
if allow_verification?
save_checkid_request
redirect_to proceed_path
elsif openid_request.immediate
render_response(openid_request.answer(false))
else
reset_session
request = save_checkid_request
session[:return_to] = proceed_p... | [
"def",
"handle_checkid_request",
"if",
"allow_verification?",
"save_checkid_request",
"redirect_to",
"proceed_path",
"elsif",
"openid_request",
".",
"immediate",
"render_response",
"(",
"openid_request",
".",
"answer",
"(",
"false",
")",
")",
"else",
"reset_session",
"req... | Decides how to process an incoming checkid request. If the user is
already logged in he will be forwarded to the proceed action. If
the user is not logged in and the request is immediate, the request
cannot be answered successfully. In case the user is not logged in,
the request will be stored and the user is asked... | [
"Decides",
"how",
"to",
"process",
"an",
"incoming",
"checkid",
"request",
".",
"If",
"the",
"user",
"is",
"already",
"logged",
"in",
"he",
"will",
"be",
"forwarded",
"to",
"the",
"proceed",
"action",
".",
"If",
"the",
"user",
"is",
"not",
"logged",
"in"... | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L121-L133 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.save_checkid_request | def save_checkid_request
clear_checkid_request
request = OpenIdRequest.create!(:parameters => openid_params)
session[:request_token] = request.token
request
end | ruby | def save_checkid_request
clear_checkid_request
request = OpenIdRequest.create!(:parameters => openid_params)
session[:request_token] = request.token
request
end | [
"def",
"save_checkid_request",
"clear_checkid_request",
"request",
"=",
"OpenIdRequest",
".",
"create!",
"(",
":parameters",
"=>",
"openid_params",
")",
"session",
"[",
":request_token",
"]",
"=",
"request",
".",
"token",
"request",
"end"
] | Stores the current OpenID request.
Returns the OpenIdRequest | [
"Stores",
"the",
"current",
"OpenID",
"request",
".",
"Returns",
"the",
"OpenIdRequest"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L137-L143 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.ensure_valid_checkid_request | def ensure_valid_checkid_request
self.openid_request = checkid_request
if !openid_request.is_a?(OpenID::Server::CheckIDRequest)
redirect_to root_path, :alert => t(:identity_verification_request_invalid)
elsif !allow_verification?
flash[:notice] = logged_in? && !pape_requirements_met?(a... | ruby | def ensure_valid_checkid_request
self.openid_request = checkid_request
if !openid_request.is_a?(OpenID::Server::CheckIDRequest)
redirect_to root_path, :alert => t(:identity_verification_request_invalid)
elsif !allow_verification?
flash[:notice] = logged_in? && !pape_requirements_met?(a... | [
"def",
"ensure_valid_checkid_request",
"self",
".",
"openid_request",
"=",
"checkid_request",
"if",
"!",
"openid_request",
".",
"is_a?",
"(",
"OpenID",
"::",
"Server",
"::",
"CheckIDRequest",
")",
"redirect_to",
"root_path",
",",
":alert",
"=>",
"t",
"(",
":identi... | Use this as before_filter for every CheckID request based action.
Loads the current openid request and cancels if none can be found.
The user has to log in, if he has not verified his ownership of
the identifier, yet. | [
"Use",
"this",
"as",
"before_filter",
"for",
"every",
"CheckID",
"request",
"based",
"action",
".",
"Loads",
"the",
"current",
"openid",
"request",
"and",
"cancels",
"if",
"none",
"can",
"be",
"found",
".",
"The",
"user",
"has",
"to",
"log",
"in",
"if",
... | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L157-L168 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.transform_ax_data | def transform_ax_data(parameters)
data = {}
parameters.each_pair do |key, details|
if details['value']
data["type.#{key}"] = details['type']
data["value.#{key}"] = details['value']
end
end
data
end | ruby | def transform_ax_data(parameters)
data = {}
parameters.each_pair do |key, details|
if details['value']
data["type.#{key}"] = details['type']
data["value.#{key}"] = details['value']
end
end
data
end | [
"def",
"transform_ax_data",
"(",
"parameters",
")",
"data",
"=",
"{",
"}",
"parameters",
".",
"each_pair",
"do",
"|",
"key",
",",
"details",
"|",
"if",
"details",
"[",
"'value'",
"]",
"data",
"[",
"\"type.#{key}\"",
"]",
"=",
"details",
"[",
"'type'",
"]... | Transforms the parameters from the form to valid AX response values | [
"Transforms",
"the",
"parameters",
"from",
"the",
"form",
"to",
"valid",
"AX",
"response",
"values"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L190-L199 | train |
dennisreimann/masq | app/controllers/masq/server_controller.rb | Masq.ServerController.render_openid_error | def render_openid_error(exception)
error = case exception
when OpenID::Server::MalformedTrustRoot then "Malformed trust root '#{exception.to_s}'"
else exception.to_s
end
render :text => h("Invalid OpenID request: #{error}"), :status => 500
end | ruby | def render_openid_error(exception)
error = case exception
when OpenID::Server::MalformedTrustRoot then "Malformed trust root '#{exception.to_s}'"
else exception.to_s
end
render :text => h("Invalid OpenID request: #{error}"), :status => 500
end | [
"def",
"render_openid_error",
"(",
"exception",
")",
"error",
"=",
"case",
"exception",
"when",
"OpenID",
"::",
"Server",
"::",
"MalformedTrustRoot",
"then",
"\"Malformed trust root '#{exception.to_s}'\"",
"else",
"exception",
".",
"to_s",
"end",
"render",
":text",
"=... | Renders the exception message as text output | [
"Renders",
"the",
"exception",
"message",
"as",
"text",
"output"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/controllers/masq/server_controller.rb#L202-L208 | train |
mceachen/micro_magick | lib/micro_magick/image.rb | MicroMagick.Image.add_input_option | def add_input_option(option_name, *args)
(@input_options ||= []).push(option_name)
args.each { |ea| @input_options.push(Shellwords.escape(ea.to_s)) }
# Support call chaining:
self
end | ruby | def add_input_option(option_name, *args)
(@input_options ||= []).push(option_name)
args.each { |ea| @input_options.push(Shellwords.escape(ea.to_s)) }
# Support call chaining:
self
end | [
"def",
"add_input_option",
"(",
"option_name",
",",
"*",
"args",
")",
"(",
"@input_options",
"||=",
"[",
"]",
")",
".",
"push",
"(",
"option_name",
")",
"args",
".",
"each",
"{",
"|",
"ea",
"|",
"@input_options",
".",
"push",
"(",
"Shellwords",
".",
"e... | If you need to add an option that affects processing of input files,
you can use this method. | [
"If",
"you",
"need",
"to",
"add",
"an",
"option",
"that",
"affects",
"processing",
"of",
"input",
"files",
"you",
"can",
"use",
"this",
"method",
"."
] | c4b9259826f16295a561c83e6e084660f4f9229e | https://github.com/mceachen/micro_magick/blob/c4b9259826f16295a561c83e6e084660f4f9229e/lib/micro_magick/image.rb#L17-L23 | train |
mceachen/micro_magick | lib/micro_magick/image.rb | MicroMagick.Image.square_crop | def square_crop(gravity = 'Center')
gravity(gravity) unless gravity.nil?
d = [width, height].min
crop("#{d}x#{d}+0+0!")
end | ruby | def square_crop(gravity = 'Center')
gravity(gravity) unless gravity.nil?
d = [width, height].min
crop("#{d}x#{d}+0+0!")
end | [
"def",
"square_crop",
"(",
"gravity",
"=",
"'Center'",
")",
"gravity",
"(",
"gravity",
")",
"unless",
"gravity",
".",
"nil?",
"d",
"=",
"[",
"width",
",",
"height",
"]",
".",
"min",
"crop",
"(",
"\"#{d}x#{d}+0+0!\"",
")",
"end"
] | Crop to a square, using the specified gravity. | [
"Crop",
"to",
"a",
"square",
"using",
"the",
"specified",
"gravity",
"."
] | c4b9259826f16295a561c83e6e084660f4f9229e | https://github.com/mceachen/micro_magick/blob/c4b9259826f16295a561c83e6e084660f4f9229e/lib/micro_magick/image.rb#L55-L59 | train |
jhass/open_graph_reader | lib/open_graph_reader/base.rb | OpenGraphReader.Base.method_missing | def method_missing(method, *args, &block)
name = method.to_s
if respond_to_missing? name
@bases[name]
else
super(method, *args, &block)
end
end | ruby | def method_missing(method, *args, &block)
name = method.to_s
if respond_to_missing? name
@bases[name]
else
super(method, *args, &block)
end
end | [
"def",
"method_missing",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"name",
"=",
"method",
".",
"to_s",
"if",
"respond_to_missing?",
"name",
"@bases",
"[",
"name",
"]",
"else",
"super",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
... | Makes the found root objects available.
@return [Object] | [
"Makes",
"the",
"found",
"root",
"objects",
"available",
"."
] | 5488354b7dd75b5411a881d734aa7176546e7cb4 | https://github.com/jhass/open_graph_reader/blob/5488354b7dd75b5411a881d734aa7176546e7cb4/lib/open_graph_reader/base.rb#L61-L68 | train |
tomharris/random_data | lib/random_data/locations.rb | RandomData.Locations.uk_post_code | def uk_post_code
post_towns = %w(BM CB CV LE LI LS KT MK NE OX PL YO)
# Can't remember any othes at the moment
number_1 = rand(100).to_s
number_2 = rand(100).to_s
# Easier way to do this?
letters = ("AA".."ZZ").to_a.rand
return "#{post_towns.rand}#{number_1} #{number_2}#{le... | ruby | def uk_post_code
post_towns = %w(BM CB CV LE LI LS KT MK NE OX PL YO)
# Can't remember any othes at the moment
number_1 = rand(100).to_s
number_2 = rand(100).to_s
# Easier way to do this?
letters = ("AA".."ZZ").to_a.rand
return "#{post_towns.rand}#{number_1} #{number_2}#{le... | [
"def",
"uk_post_code",
"post_towns",
"=",
"%w(",
"BM",
"CB",
"CV",
"LE",
"LI",
"LS",
"KT",
"MK",
"NE",
"OX",
"PL",
"YO",
")",
"number_1",
"=",
"rand",
"(",
"100",
")",
".",
"to_s",
"number_2",
"=",
"rand",
"(",
"100",
")",
".",
"to_s",
"letters",
... | Returns a string providing something in the general form of a UK post code. Like the zip codes, this might
not actually be valid. Doesn't cover London whose codes are like "SE1". | [
"Returns",
"a",
"string",
"providing",
"something",
"in",
"the",
"general",
"form",
"of",
"a",
"UK",
"post",
"code",
".",
"Like",
"the",
"zip",
"codes",
"this",
"might",
"not",
"actually",
"be",
"valid",
".",
"Doesn",
"t",
"cover",
"London",
"whose",
"co... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/locations.rb#L56-L65 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/map.rb | GoogleStaticMapsHelper.Map.url | def url
raise BuildDataMissing, "We have to have markers, paths or center and zoom set when url is called!" unless can_build?
out = "#{API_URL}?"
params = []
(REQUIRED_OPTIONS + OPTIONAL_OPTIONS).each do |key|
value = send(key)
params << "#{key}=#{URI.escape(value.to_s)}"... | ruby | def url
raise BuildDataMissing, "We have to have markers, paths or center and zoom set when url is called!" unless can_build?
out = "#{API_URL}?"
params = []
(REQUIRED_OPTIONS + OPTIONAL_OPTIONS).each do |key|
value = send(key)
params << "#{key}=#{URI.escape(value.to_s)}"... | [
"def",
"url",
"raise",
"BuildDataMissing",
",",
"\"We have to have markers, paths or center and zoom set when url is called!\"",
"unless",
"can_build?",
"out",
"=",
"\"#{API_URL}?\"",
"params",
"=",
"[",
"]",
"(",
"REQUIRED_OPTIONS",
"+",
"OPTIONAL_OPTIONS",
")",
".",
"each... | Creates a new Map object
<tt>:options</tt>:: The options available are the same as described in
Google's API documentation[http://code.google.com/apis/maps/documentation/staticmaps/#Usage].
In short, valid options are:
<tt>:size</tt>:: The si... | [
"Creates",
"a",
"new",
"Map",
"object"
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/map.rb#L50-L74 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/map.rb | GoogleStaticMapsHelper.Map.grouped_markers | def grouped_markers
markers.inject(Hash.new {|hash, key| hash[key] = []}) do |groups, marker|
groups[marker.options_to_url_params] << marker
groups
end
end | ruby | def grouped_markers
markers.inject(Hash.new {|hash, key| hash[key] = []}) do |groups, marker|
groups[marker.options_to_url_params] << marker
groups
end
end | [
"def",
"grouped_markers",
"markers",
".",
"inject",
"(",
"Hash",
".",
"new",
"{",
"|",
"hash",
",",
"key",
"|",
"hash",
"[",
"key",
"]",
"=",
"[",
"]",
"}",
")",
"do",
"|",
"groups",
",",
"marker",
"|",
"groups",
"[",
"marker",
".",
"options_to_url... | Returns the markers grouped by it's label, color and size.
This is handy when building the URL because the API wants us to
group together equal markers and just list the position of the markers thereafter in the URL. | [
"Returns",
"the",
"markers",
"grouped",
"by",
"it",
"s",
"label",
"color",
"and",
"size",
"."
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/map.rb#L89-L94 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/map.rb | GoogleStaticMapsHelper.Map.size= | def size=(size)
unless size.nil?
case size
when String
width, height = size.split('x')
when Array
width, height = size
when Hash
width = size[:width]
height = size[:height]
else
raise "Don't know how to set size from #{size.... | ruby | def size=(size)
unless size.nil?
case size
when String
width, height = size.split('x')
when Array
width, height = size
when Hash
width = size[:width]
height = size[:height]
else
raise "Don't know how to set size from #{size.... | [
"def",
"size",
"=",
"(",
"size",
")",
"unless",
"size",
".",
"nil?",
"case",
"size",
"when",
"String",
"width",
",",
"height",
"=",
"size",
".",
"split",
"(",
"'x'",
")",
"when",
"Array",
"width",
",",
"height",
"=",
"size",
"when",
"Hash",
"width",
... | Sets the size of the map
<tt>size</tt>:: Can be a "wxh", [w,h] or {:width => x, :height => y} | [
"Sets",
"the",
"size",
"of",
"the",
"map"
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/map.rb#L144-L161 | train |
tomharris/random_data | lib/random_data/text.rb | RandomData.Text.alphanumeric | def alphanumeric(size=16)
s = ""
size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
s
end | ruby | def alphanumeric(size=16)
s = ""
size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
s
end | [
"def",
"alphanumeric",
"(",
"size",
"=",
"16",
")",
"s",
"=",
"\"\"",
"size",
".",
"times",
"{",
"s",
"<<",
"(",
"i",
"=",
"Kernel",
".",
"rand",
"(",
"62",
")",
";",
"i",
"+=",
"(",
"(",
"i",
"<",
"10",
")",
"?",
"48",
":",
"(",
"(",
"i"... | Methods to create random strings and paragraphs.
Returns a string of random upper- and lowercase alphanumeric characters. Accepts a size parameters, defaults to 16 characters.
>> Random.alphanumeric
"Ke2jdknPYAI8uCXj"
>> Random.alphanumeric(5)
"7sj7i" | [
"Methods",
"to",
"create",
"random",
"strings",
"and",
"paragraphs",
".",
"Returns",
"a",
"string",
"of",
"random",
"upper",
"-",
"and",
"lowercase",
"alphanumeric",
"characters",
".",
"Accepts",
"a",
"size",
"parameters",
"defaults",
"to",
"16",
"characters",
... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/text.rb#L17-L21 | train |
tomharris/random_data | lib/random_data/markov.rb | RandomData.MarkovGenerator.insert | def insert(result)
# puts "insert called with #{result}"
tabindex = Marshal.dump(@state)
if @table[tabindex].has_key?(result)
@table[tabindex][result] += 1
else
@table[tabindex][result] = 1
end
# puts "table #{@table.inspect}"
next_state(result)
end | ruby | def insert(result)
# puts "insert called with #{result}"
tabindex = Marshal.dump(@state)
if @table[tabindex].has_key?(result)
@table[tabindex][result] += 1
else
@table[tabindex][result] = 1
end
# puts "table #{@table.inspect}"
next_state(result)
end | [
"def",
"insert",
"(",
"result",
")",
"tabindex",
"=",
"Marshal",
".",
"dump",
"(",
"@state",
")",
"if",
"@table",
"[",
"tabindex",
"]",
".",
"has_key?",
"(",
"result",
")",
"@table",
"[",
"tabindex",
"]",
"[",
"result",
"]",
"+=",
"1",
"else",
"@tabl... | given the next token of input add it to the
table | [
"given",
"the",
"next",
"token",
"of",
"input",
"add",
"it",
"to",
"the",
"table"
] | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/markov.rb#L16-L26 | train |
dennisreimann/masq | app/helpers/masq/personas_helper.rb | Masq.PersonasHelper.countries_for_select | def countries_for_select
::I18nData.countries.map{|pair| pair.reverse}.sort{|x,y| x.first <=> y.first}
end | ruby | def countries_for_select
::I18nData.countries.map{|pair| pair.reverse}.sort{|x,y| x.first <=> y.first}
end | [
"def",
"countries_for_select",
"::",
"I18nData",
".",
"countries",
".",
"map",
"{",
"|",
"pair",
"|",
"pair",
".",
"reverse",
"}",
".",
"sort",
"{",
"|",
"x",
",",
"y",
"|",
"x",
".",
"first",
"<=>",
"y",
".",
"first",
"}",
"end"
] | get list of codes and names sorted by country name | [
"get",
"list",
"of",
"codes",
"and",
"names",
"sorted",
"by",
"country",
"name"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/helpers/masq/personas_helper.rb#L6-L8 | train |
dennisreimann/masq | app/helpers/masq/personas_helper.rb | Masq.PersonasHelper.languages_for_select | def languages_for_select
::I18nData.languages.map{|pair| pair.reverse}.sort{|x,y| x.first <=> y.first}
end | ruby | def languages_for_select
::I18nData.languages.map{|pair| pair.reverse}.sort{|x,y| x.first <=> y.first}
end | [
"def",
"languages_for_select",
"::",
"I18nData",
".",
"languages",
".",
"map",
"{",
"|",
"pair",
"|",
"pair",
".",
"reverse",
"}",
".",
"sort",
"{",
"|",
"x",
",",
"y",
"|",
"x",
".",
"first",
"<=>",
"y",
".",
"first",
"}",
"end"
] | get list of codes and names sorted by language name | [
"get",
"list",
"of",
"codes",
"and",
"names",
"sorted",
"by",
"language",
"name"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/helpers/masq/personas_helper.rb#L11-L13 | train |
qoobaa/vcard | lib/vcard/vcard.rb | Vcard.Vcard.lines | def lines(name=nil) #:yield: Line
# FIXME - this would be much easier if #lines was #each, and there was a
# different #lines that returned an Enumerator that used #each
unless block_given?
map do |f|
if( !name || f.name?(name) )
f2l(f)
else
nil
... | ruby | def lines(name=nil) #:yield: Line
# FIXME - this would be much easier if #lines was #each, and there was a
# different #lines that returned an Enumerator that used #each
unless block_given?
map do |f|
if( !name || f.name?(name) )
f2l(f)
else
nil
... | [
"def",
"lines",
"(",
"name",
"=",
"nil",
")",
"unless",
"block_given?",
"map",
"do",
"|",
"f",
"|",
"if",
"(",
"!",
"name",
"||",
"f",
".",
"name?",
"(",
"name",
")",
")",
"f2l",
"(",
"f",
")",
"else",
"nil",
"end",
"end",
".",
"compact",
"else... | With no block, returns an Array of Line. If +name+ is specified, the
Array will only contain the +Line+s with that +name+. The Array may be
empty.
If a block is given, each Line will be yielded instead of being returned
in an Array. | [
"With",
"no",
"block",
"returns",
"an",
"Array",
"of",
"Line",
".",
"If",
"+",
"name",
"+",
"is",
"specified",
"the",
"Array",
"will",
"only",
"contain",
"the",
"+",
"Line",
"+",
"s",
"with",
"that",
"+",
"name",
"+",
".",
"The",
"Array",
"may",
"b... | 0cab080676df262555e3adadc9a82fedc128d337 | https://github.com/qoobaa/vcard/blob/0cab080676df262555e3adadc9a82fedc128d337/lib/vcard/vcard.rb#L578-L600 | train |
qoobaa/vcard | lib/vcard/vcard.rb | Vcard.Vcard.delete_if | def delete_if #:nodoc: :yield: line
# Do in two steps to not mess up progress through the enumerator.
rm = []
each do |f|
line = f2l(f)
if line && yield(line)
rm << f
# Hack - because we treat N and FN as one field
if f.name? "N"
rm << field(... | ruby | def delete_if #:nodoc: :yield: line
# Do in two steps to not mess up progress through the enumerator.
rm = []
each do |f|
line = f2l(f)
if line && yield(line)
rm << f
# Hack - because we treat N and FN as one field
if f.name? "N"
rm << field(... | [
"def",
"delete_if",
"rm",
"=",
"[",
"]",
"each",
"do",
"|",
"f",
"|",
"line",
"=",
"f2l",
"(",
"f",
")",
"if",
"line",
"&&",
"yield",
"(",
"line",
")",
"rm",
"<<",
"f",
"if",
"f",
".",
"name?",
"\"N\"",
"rm",
"<<",
"field",
"(",
"\"FN\"",
")"... | Delete +line+ if block yields true. | [
"Delete",
"+",
"line",
"+",
"if",
"block",
"yields",
"true",
"."
] | 0cab080676df262555e3adadc9a82fedc128d337 | https://github.com/qoobaa/vcard/blob/0cab080676df262555e3adadc9a82fedc128d337/lib/vcard/vcard.rb#L966-L987 | train |
ma2gedev/breadcrumble | lib/breadcrumble/action_controller.rb | Breadcrumble.ActionController.add_breadcrumb_to | def add_breadcrumb_to(name, url, trail_index)
breadcrumb_trails
@breadcrumb_trails[trail_index] ||= []
@breadcrumb_trails[trail_index] << {
name: case name
when Proc then name.call(self)
else name
end,
url: case url
when Proc the... | ruby | def add_breadcrumb_to(name, url, trail_index)
breadcrumb_trails
@breadcrumb_trails[trail_index] ||= []
@breadcrumb_trails[trail_index] << {
name: case name
when Proc then name.call(self)
else name
end,
url: case url
when Proc the... | [
"def",
"add_breadcrumb_to",
"(",
"name",
",",
"url",
",",
"trail_index",
")",
"breadcrumb_trails",
"@breadcrumb_trails",
"[",
"trail_index",
"]",
"||=",
"[",
"]",
"@breadcrumb_trails",
"[",
"trail_index",
"]",
"<<",
"{",
"name",
":",
"case",
"name",
"when",
"P... | Add a breadcrumb to breadcrumb trail.
@param trail_index index of breadcrumb trail
@example
add_breadcrumb_to("level 1", "level 1 url", 0) | [
"Add",
"a",
"breadcrumb",
"to",
"breadcrumb",
"trail",
"."
] | 6a274b9b881d74aa69a8c3cf248fa73bacfd1d46 | https://github.com/ma2gedev/breadcrumble/blob/6a274b9b881d74aa69a8c3cf248fa73bacfd1d46/lib/breadcrumble/action_controller.rb#L57-L70 | train |
dennisreimann/masq | lib/masq/authenticated_system.rb | Masq.AuthenticatedSystem.current_account= | def current_account=(new_account)
if self.auth_type_used != :basic
session[:account_id] = (new_account.nil? || new_account.is_a?(Symbol)) ? nil : new_account.id
end
@current_account = new_account || :false
end | ruby | def current_account=(new_account)
if self.auth_type_used != :basic
session[:account_id] = (new_account.nil? || new_account.is_a?(Symbol)) ? nil : new_account.id
end
@current_account = new_account || :false
end | [
"def",
"current_account",
"=",
"(",
"new_account",
")",
"if",
"self",
".",
"auth_type_used",
"!=",
":basic",
"session",
"[",
":account_id",
"]",
"=",
"(",
"new_account",
".",
"nil?",
"||",
"new_account",
".",
"is_a?",
"(",
"Symbol",
")",
")",
"?",
"nil",
... | Store the given account id in the session. | [
"Store",
"the",
"given",
"account",
"id",
"in",
"the",
"session",
"."
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/lib/masq/authenticated_system.rb#L17-L22 | train |
dennisreimann/masq | lib/masq/authenticated_system.rb | Masq.AuthenticatedSystem.access_denied | def access_denied
respond_to do |format|
format.html do
store_location
redirect_to login_path
end
format.any do
request_http_basic_authentication 'Web Password'
end
end
end | ruby | def access_denied
respond_to do |format|
format.html do
store_location
redirect_to login_path
end
format.any do
request_http_basic_authentication 'Web Password'
end
end
end | [
"def",
"access_denied",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"do",
"store_location",
"redirect_to",
"login_path",
"end",
"format",
".",
"any",
"do",
"request_http_basic_authentication",
"'Web Password'",
"end",
"end",
"end"
] | Redirect as appropriate when an access request fails.
The default action is to redirect to the login screen.
Override this method in your controllers if you want to have special
behavior in case the account is not authorized
to access the requested action. For example, a popup window might
simply close itself. | [
"Redirect",
"as",
"appropriate",
"when",
"an",
"access",
"request",
"fails",
"."
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/lib/masq/authenticated_system.rb#L66-L76 | train |
jhass/open_graph_reader | lib/open_graph_reader/object.rb | OpenGraphReader.Object.[]= | def []= name, value
if property?(name)
public_send "#{name}=", value
elsif OpenGraphReader.config.strict
raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}"
end
end | ruby | def []= name, value
if property?(name)
public_send "#{name}=", value
elsif OpenGraphReader.config.strict
raise UndefinedPropertyError, "Undefined property #{name} on #{inspect}"
end
end | [
"def",
"[]=",
"name",
",",
"value",
"if",
"property?",
"(",
"name",
")",
"public_send",
"\"#{name}=\"",
",",
"value",
"elsif",
"OpenGraphReader",
".",
"config",
".",
"strict",
"raise",
"UndefinedPropertyError",
",",
"\"Undefined property #{name} on #{inspect}\"",
"end... | Set the property to the given value.
@api private
@param [#to_s] name
@param [String, Object] value
@raise [UndefinedPropertyError] If the requested property is undefined. | [
"Set",
"the",
"property",
"to",
"the",
"given",
"value",
"."
] | 5488354b7dd75b5411a881d734aa7176546e7cb4 | https://github.com/jhass/open_graph_reader/blob/5488354b7dd75b5411a881d734aa7176546e7cb4/lib/open_graph_reader/object.rb#L81-L87 | train |
tomharris/random_data | lib/random_data/dates.rb | RandomData.Dates.date | def date(dayrange=10)
if dayrange.is_a?(Range)
offset = rand(dayrange.max-dayrange.min) + dayrange.min
else
offset = rand(dayrange*2) - dayrange
end
Date.today + offset
end | ruby | def date(dayrange=10)
if dayrange.is_a?(Range)
offset = rand(dayrange.max-dayrange.min) + dayrange.min
else
offset = rand(dayrange*2) - dayrange
end
Date.today + offset
end | [
"def",
"date",
"(",
"dayrange",
"=",
"10",
")",
"if",
"dayrange",
".",
"is_a?",
"(",
"Range",
")",
"offset",
"=",
"rand",
"(",
"dayrange",
".",
"max",
"-",
"dayrange",
".",
"min",
")",
"+",
"dayrange",
".",
"min",
"else",
"offset",
"=",
"rand",
"("... | Returns a date within a specified range of days. If dayrange is an Integer, then the date
returned will be plus or minus half what you specify. The default is ten days, so by default
you will get a date within plus or minus five days of today.
If dayrange is a Range, then you will get a date the falls between tha... | [
"Returns",
"a",
"date",
"within",
"a",
"specified",
"range",
"of",
"days",
".",
"If",
"dayrange",
"is",
"an",
"Integer",
"then",
"the",
"date",
"returned",
"will",
"be",
"plus",
"or",
"minus",
"half",
"what",
"you",
"specify",
".",
"The",
"default",
"is"... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/dates.rb#L21-L28 | train |
tomharris/random_data | lib/random_data/dates.rb | RandomData.Dates.date_between | def date_between(range)
min_date = range.min.is_a?(Date) ? range.min : Date.parse(range.min)
max_date = range.max.is_a?(Date) ? range.max : Date.parse(range.max)
diff = (max_date - min_date).to_i
min_date + rand(diff)
end | ruby | def date_between(range)
min_date = range.min.is_a?(Date) ? range.min : Date.parse(range.min)
max_date = range.max.is_a?(Date) ? range.max : Date.parse(range.max)
diff = (max_date - min_date).to_i
min_date + rand(diff)
end | [
"def",
"date_between",
"(",
"range",
")",
"min_date",
"=",
"range",
".",
"min",
".",
"is_a?",
"(",
"Date",
")",
"?",
"range",
".",
"min",
":",
"Date",
".",
"parse",
"(",
"range",
".",
"min",
")",
"max_date",
"=",
"range",
".",
"max",
".",
"is_a?",
... | Returns a date within the specified Range. The Range can be Date or String objects.
Example:
min = Date.parse('1966-11-15')
max = Date.parse('1990-01-01')
Random.date(min..max) # => a Date between 11/15/1996 and 1/1/1990
Random.date('1966-11-15'..'1990-01-01') # => a Date between 11/15/1996 and 1/1/1990 | [
"Returns",
"a",
"date",
"within",
"the",
"specified",
"Range",
".",
"The",
"Range",
"can",
"be",
"Date",
"or",
"String",
"objects",
"."
] | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/dates.rb#L38-L44 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/path.rb | GoogleStaticMapsHelper.Path.url_params | def url_params # :nodoc:
raise BuildDataMissing, "Need at least 2 points to create a path!" unless can_build?
out = 'path='
path_params = OPTIONAL_OPTIONS.inject([]) do |path_params, attribute|
value = send(attribute)
path_params << "#{attribute}:#{URI.escape(value.to_s)}" unless... | ruby | def url_params # :nodoc:
raise BuildDataMissing, "Need at least 2 points to create a path!" unless can_build?
out = 'path='
path_params = OPTIONAL_OPTIONS.inject([]) do |path_params, attribute|
value = send(attribute)
path_params << "#{attribute}:#{URI.escape(value.to_s)}" unless... | [
"def",
"url_params",
"raise",
"BuildDataMissing",
",",
"\"Need at least 2 points to create a path!\"",
"unless",
"can_build?",
"out",
"=",
"'path='",
"path_params",
"=",
"OPTIONAL_OPTIONS",
".",
"inject",
"(",
"[",
"]",
")",
"do",
"|",
"path_params",
",",
"attribute",... | Creates a new Path which you can push points on to to make up lines or polygons
The following options are available, for more information see the
Google API documentation[http://code.google.com/apis/maps/documentation/staticmaps/#Paths].
<tt>:weight</tt>:: The weight is the thickness of the line, defaults to 5
... | [
"Creates",
"a",
"new",
"Path",
"which",
"you",
"can",
"push",
"points",
"on",
"to",
"to",
"make",
"up",
"lines",
"or",
"polygons"
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/path.rb#L42-L57 | train |
thhermansen/google_static_maps_helper | lib/google_static_maps_helper/path.rb | GoogleStaticMapsHelper.Path.points= | def points=(array)
raise ArgumentError unless array.is_a? Array
@points = []
array.each {|point| self << point}
end | ruby | def points=(array)
raise ArgumentError unless array.is_a? Array
@points = []
array.each {|point| self << point}
end | [
"def",
"points",
"=",
"(",
"array",
")",
"raise",
"ArgumentError",
"unless",
"array",
".",
"is_a?",
"Array",
"@points",
"=",
"[",
"]",
"array",
".",
"each",
"{",
"|",
"point",
"|",
"self",
"<<",
"point",
"}",
"end"
] | Sets the points of this Path.
*WARNING* Using this method will clear out any points which might be set. | [
"Sets",
"the",
"points",
"of",
"this",
"Path",
"."
] | 31d2af983e17be736566bfac686b56c57385d64d | https://github.com/thhermansen/google_static_maps_helper/blob/31d2af983e17be736566bfac686b56c57385d64d/lib/google_static_maps_helper/path.rb#L65-L69 | train |
dennisreimann/masq | lib/masq/openid_server_system.rb | Masq.OpenidServerSystem.add_pape | def add_pape(resp, policies = [], nist_auth_level = 0, auth_time = nil)
if papereq = OpenID::PAPE::Request.from_openid_request(openid_request)
paperesp = OpenID::PAPE::Response.new
policies.each { |p| paperesp.add_policy_uri(p) }
paperesp.nist_auth_level = nist_auth_level
paperesp.... | ruby | def add_pape(resp, policies = [], nist_auth_level = 0, auth_time = nil)
if papereq = OpenID::PAPE::Request.from_openid_request(openid_request)
paperesp = OpenID::PAPE::Response.new
policies.each { |p| paperesp.add_policy_uri(p) }
paperesp.nist_auth_level = nist_auth_level
paperesp.... | [
"def",
"add_pape",
"(",
"resp",
",",
"policies",
"=",
"[",
"]",
",",
"nist_auth_level",
"=",
"0",
",",
"auth_time",
"=",
"nil",
")",
"if",
"papereq",
"=",
"OpenID",
"::",
"PAPE",
"::",
"Request",
".",
"from_openid_request",
"(",
"openid_request",
")",
"p... | Adds PAPE information for your server to an OpenID response. | [
"Adds",
"PAPE",
"information",
"for",
"your",
"server",
"to",
"an",
"OpenID",
"response",
"."
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/lib/masq/openid_server_system.rb#L74-L83 | train |
dennisreimann/masq | lib/masq/openid_server_system.rb | Masq.OpenidServerSystem.render_openid_response | def render_openid_response(resp)
signed_response = openid_server.signatory.sign(resp) if resp.needs_signing
web_response = openid_server.encode_response(resp)
case web_response.code
when OpenID::Server::HTTP_OK then render(:text => web_response.body, :status => 200)
when OpenID::Server::HT... | ruby | def render_openid_response(resp)
signed_response = openid_server.signatory.sign(resp) if resp.needs_signing
web_response = openid_server.encode_response(resp)
case web_response.code
when OpenID::Server::HTTP_OK then render(:text => web_response.body, :status => 200)
when OpenID::Server::HT... | [
"def",
"render_openid_response",
"(",
"resp",
")",
"signed_response",
"=",
"openid_server",
".",
"signatory",
".",
"sign",
"(",
"resp",
")",
"if",
"resp",
".",
"needs_signing",
"web_response",
"=",
"openid_server",
".",
"encode_response",
"(",
"resp",
")",
"case... | Renders the final response output | [
"Renders",
"the",
"final",
"response",
"output"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/lib/masq/openid_server_system.rb#L92-L100 | train |
dennisreimann/masq | app/models/masq/persona.rb | Masq.Persona.property | def property(type)
prop = Persona.mappings.detect { |i| i[1].include?(type) }
prop ? self.send(prop[0]).to_s : nil
end | ruby | def property(type)
prop = Persona.mappings.detect { |i| i[1].include?(type) }
prop ? self.send(prop[0]).to_s : nil
end | [
"def",
"property",
"(",
"type",
")",
"prop",
"=",
"Persona",
".",
"mappings",
".",
"detect",
"{",
"|",
"i",
"|",
"i",
"[",
"1",
"]",
".",
"include?",
"(",
"type",
")",
"}",
"prop",
"?",
"self",
".",
"send",
"(",
"prop",
"[",
"0",
"]",
")",
".... | Returns the personas attribute for the given SReg name or AX Type URI | [
"Returns",
"the",
"personas",
"attribute",
"for",
"the",
"given",
"SReg",
"name",
"or",
"AX",
"Type",
"URI"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/models/masq/persona.rb#L26-L29 | train |
ustasb/pandata | lib/pandata/cli.rb | Pandata.CLI.format_data | def format_data(data, json = false)
if json
JSON.generate(data)
else
data.map do |category, cat_data|
# Capitalize each word in the category symbol.
# e.g. :liked_tracks becomes 'Liked Tracks'
title = category.to_s.split('_').map(&:capitalize).join(' ')
... | ruby | def format_data(data, json = false)
if json
JSON.generate(data)
else
data.map do |category, cat_data|
# Capitalize each word in the category symbol.
# e.g. :liked_tracks becomes 'Liked Tracks'
title = category.to_s.split('_').map(&:capitalize).join(' ')
... | [
"def",
"format_data",
"(",
"data",
",",
"json",
"=",
"false",
")",
"if",
"json",
"JSON",
".",
"generate",
"(",
"data",
")",
"else",
"data",
".",
"map",
"do",
"|",
"category",
",",
"cat_data",
"|",
"title",
"=",
"category",
".",
"to_s",
".",
"split",
... | Formats data as a string list or JSON.
@param data [Hash]
@param json [Boolean]
@return [String] | [
"Formats",
"data",
"as",
"a",
"string",
"list",
"or",
"JSON",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/cli.rb#L75-L102 | train |
ustasb/pandata | lib/pandata/cli.rb | Pandata.CLI.download_data | def download_data
scraper_data = {}
@data_to_get.each do |data_category|
if /liked_(.*)/ =~ data_category
argument = $1.to_sym # :tracks, :artists, :stations or :albums
scraper_data[data_category] = @scraper.public_send(:likes, argument)
else
scraper_data[data... | ruby | def download_data
scraper_data = {}
@data_to_get.each do |data_category|
if /liked_(.*)/ =~ data_category
argument = $1.to_sym # :tracks, :artists, :stations or :albums
scraper_data[data_category] = @scraper.public_send(:likes, argument)
else
scraper_data[data... | [
"def",
"download_data",
"scraper_data",
"=",
"{",
"}",
"@data_to_get",
".",
"each",
"do",
"|",
"data_category",
"|",
"if",
"/",
"/",
"=~",
"data_category",
"argument",
"=",
"$1",
".",
"to_sym",
"scraper_data",
"[",
"data_category",
"]",
"=",
"@scraper",
".",... | Downloads the user's desired data.
@return [Hash] | [
"Downloads",
"the",
"user",
"s",
"desired",
"data",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/cli.rb#L106-L119 | train |
ustasb/pandata | lib/pandata/cli.rb | Pandata.CLI.scraper_for | def scraper_for(user_id)
scraper = Pandata::Scraper.get(user_id)
if scraper.kind_of?(Array)
log "No exact match for '#{user_id}'."
unless scraper.empty?
log "\nWebname results for '#{user_id}':\n#{formatter.list(scraper)}"
end
raise PandataError, "Could not creat... | ruby | def scraper_for(user_id)
scraper = Pandata::Scraper.get(user_id)
if scraper.kind_of?(Array)
log "No exact match for '#{user_id}'."
unless scraper.empty?
log "\nWebname results for '#{user_id}':\n#{formatter.list(scraper)}"
end
raise PandataError, "Could not creat... | [
"def",
"scraper_for",
"(",
"user_id",
")",
"scraper",
"=",
"Pandata",
"::",
"Scraper",
".",
"get",
"(",
"user_id",
")",
"if",
"scraper",
".",
"kind_of?",
"(",
"Array",
")",
"log",
"\"No exact match for '#{user_id}'.\"",
"unless",
"scraper",
".",
"empty?",
"log... | Returns a scraper for the user's id.
@param user_id [String] webname or email
@return [Pandata::Scraper] | [
"Returns",
"a",
"scraper",
"for",
"the",
"user",
"s",
"id",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/cli.rb#L124-L138 | train |
dennisreimann/masq | app/models/masq/site.rb | Masq.Site.ax_fetch= | def ax_fetch=(props)
props.each_pair do |property, details|
release_policies.build(:property => property, :type_identifier => details['type']) if details['value']
end
end | ruby | def ax_fetch=(props)
props.each_pair do |property, details|
release_policies.build(:property => property, :type_identifier => details['type']) if details['value']
end
end | [
"def",
"ax_fetch",
"=",
"(",
"props",
")",
"props",
".",
"each_pair",
"do",
"|",
"property",
",",
"details",
"|",
"release_policies",
".",
"build",
"(",
":property",
"=>",
"property",
",",
":type_identifier",
"=>",
"details",
"[",
"'type'",
"]",
")",
"if",... | Generates a release policy for each property that has a value.
This setter is used in the server controllers complete action
to set the attributes recieved from the decision form. | [
"Generates",
"a",
"release",
"policy",
"for",
"each",
"property",
"that",
"has",
"a",
"value",
".",
"This",
"setter",
"is",
"used",
"in",
"the",
"server",
"controllers",
"complete",
"action",
"to",
"set",
"the",
"attributes",
"recieved",
"from",
"the",
"deci... | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/models/masq/site.rb#L29-L33 | train |
dennisreimann/masq | app/models/masq/site.rb | Masq.Site.sreg_properties | def sreg_properties
props = {}
release_policies.each do |rp|
is_sreg = (rp.property == rp.type_identifier)
props[rp.property] = persona.property(rp.property) if is_sreg
end
props
end | ruby | def sreg_properties
props = {}
release_policies.each do |rp|
is_sreg = (rp.property == rp.type_identifier)
props[rp.property] = persona.property(rp.property) if is_sreg
end
props
end | [
"def",
"sreg_properties",
"props",
"=",
"{",
"}",
"release_policies",
".",
"each",
"do",
"|",
"rp",
"|",
"is_sreg",
"=",
"(",
"rp",
".",
"property",
"==",
"rp",
".",
"type_identifier",
")",
"props",
"[",
"rp",
".",
"property",
"]",
"=",
"persona",
".",... | Returns a hash with all released SReg properties. SReg properties
have a type_identifier matching their property name | [
"Returns",
"a",
"hash",
"with",
"all",
"released",
"SReg",
"properties",
".",
"SReg",
"properties",
"have",
"a",
"type_identifier",
"matching",
"their",
"property",
"name"
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/models/masq/site.rb#L46-L53 | train |
dennisreimann/masq | app/models/masq/site.rb | Masq.Site.ax_properties | def ax_properties
props = {}
release_policies.each do |rp|
if rp.type_identifier.match("://")
props["type.#{rp.property}"] = rp.type_identifier
props["value.#{rp.property}"] = persona.property(rp.type_identifier )
end
end
props
end | ruby | def ax_properties
props = {}
release_policies.each do |rp|
if rp.type_identifier.match("://")
props["type.#{rp.property}"] = rp.type_identifier
props["value.#{rp.property}"] = persona.property(rp.type_identifier )
end
end
props
end | [
"def",
"ax_properties",
"props",
"=",
"{",
"}",
"release_policies",
".",
"each",
"do",
"|",
"rp",
"|",
"if",
"rp",
".",
"type_identifier",
".",
"match",
"(",
"\"://\"",
")",
"props",
"[",
"\"type.#{rp.property}\"",
"]",
"=",
"rp",
".",
"type_identifier",
"... | Returns a hash with all released AX properties.
AX properties have an URL as type_identifier. | [
"Returns",
"a",
"hash",
"with",
"all",
"released",
"AX",
"properties",
".",
"AX",
"properties",
"have",
"an",
"URL",
"as",
"type_identifier",
"."
] | bc6b6d84fe06811b9de19e7863c53c6bfad201fe | https://github.com/dennisreimann/masq/blob/bc6b6d84fe06811b9de19e7863c53c6bfad201fe/app/models/masq/site.rb#L57-L66 | train |
ustasb/pandata | lib/pandata/data_formatter.rb | Pandata.DataFormatter.custom_sort | def custom_sort(enumerable)
sorted_array = enumerable.sort_by do |key, _|
key.sub(/^the\s*/i, '').downcase
end
# sort_by() returns an array when called on hashes.
if enumerable.kind_of?(Hash)
# Rebuild the hash.
sorted_hash = {}
sorted_array.each { |item| sorted_... | ruby | def custom_sort(enumerable)
sorted_array = enumerable.sort_by do |key, _|
key.sub(/^the\s*/i, '').downcase
end
# sort_by() returns an array when called on hashes.
if enumerable.kind_of?(Hash)
# Rebuild the hash.
sorted_hash = {}
sorted_array.each { |item| sorted_... | [
"def",
"custom_sort",
"(",
"enumerable",
")",
"sorted_array",
"=",
"enumerable",
".",
"sort_by",
"do",
"|",
"key",
",",
"_",
"|",
"key",
".",
"sub",
"(",
"/",
"\\s",
"/i",
",",
"''",
")",
".",
"downcase",
"end",
"if",
"enumerable",
".",
"kind_of?",
"... | Sorts alphabetically ignoring the initial 'The' when sorting strings.
Also case-insensitive to prevent lowercase names from being sorted last.
@param enumerable [Array, Hash]
@return [Array, Hash] | [
"Sorts",
"alphabetically",
"ignoring",
"the",
"initial",
"The",
"when",
"sorting",
"strings",
".",
"Also",
"case",
"-",
"insensitive",
"to",
"prevent",
"lowercase",
"names",
"from",
"being",
"sorted",
"last",
"."
] | c75f83813171bc6149eca53ff310dedca1a7a1cb | https://github.com/ustasb/pandata/blob/c75f83813171bc6149eca53ff310dedca1a7a1cb/lib/pandata/data_formatter.rb#L53-L67 | train |
tomharris/random_data | lib/random_data/array_randomizer.rb | RandomData.ArrayRandomizer.roulette | def roulette(k=1)
wheel = []
weight = 0
# Create the cumulative array.
self.each do |x|
raise "Illegal negative weight #{x}" if x < 0
wheel.push(weight += x)
end
# print "wheel is #{wheel.inspect}\n";
# print "weight is #{weight.inspect}\n";
raise "Array h... | ruby | def roulette(k=1)
wheel = []
weight = 0
# Create the cumulative array.
self.each do |x|
raise "Illegal negative weight #{x}" if x < 0
wheel.push(weight += x)
end
# print "wheel is #{wheel.inspect}\n";
# print "weight is #{weight.inspect}\n";
raise "Array h... | [
"def",
"roulette",
"(",
"k",
"=",
"1",
")",
"wheel",
"=",
"[",
"]",
"weight",
"=",
"0",
"self",
".",
"each",
"do",
"|",
"x",
"|",
"raise",
"\"Illegal negative weight #{x}\"",
"if",
"x",
"<",
"0",
"wheel",
".",
"push",
"(",
"weight",
"+=",
"x",
")",... | Takes an array of non-negative weights
and returns the index selected by a
roulette wheel weighted according to those
weights.
If a block is given then k is used to determine
how many times the block is called. In this
case nil is returned. | [
"Takes",
"an",
"array",
"of",
"non",
"-",
"negative",
"weights",
"and",
"returns",
"the",
"index",
"selected",
"by",
"a",
"roulette",
"wheel",
"weighted",
"according",
"to",
"those",
"weights",
".",
"If",
"a",
"block",
"is",
"given",
"then",
"k",
"is",
"... | 641271ea66e7837b2c4a9efa034d9ac75b4f487d | https://github.com/tomharris/random_data/blob/641271ea66e7837b2c4a9efa034d9ac75b4f487d/lib/random_data/array_randomizer.rb#L22-L57 | train |
jhass/open_graph_reader | lib/open_graph_reader/fetcher.rb | OpenGraphReader.Fetcher.body | def body
fetch_body unless fetched?
raise NoOpenGraphDataError, "No response body received for #{@uri}" if fetch_failed?
raise NoOpenGraphDataError, "Did not receive a HTML site at #{@uri}" unless html?
@get_response.body
end | ruby | def body
fetch_body unless fetched?
raise NoOpenGraphDataError, "No response body received for #{@uri}" if fetch_failed?
raise NoOpenGraphDataError, "Did not receive a HTML site at #{@uri}" unless html?
@get_response.body
end | [
"def",
"body",
"fetch_body",
"unless",
"fetched?",
"raise",
"NoOpenGraphDataError",
",",
"\"No response body received for #{@uri}\"",
"if",
"fetch_failed?",
"raise",
"NoOpenGraphDataError",
",",
"\"Did not receive a HTML site at #{@uri}\"",
"unless",
"html?",
"@get_response",
"."... | Retrieve the body
@todo Custom error class
@raise [ArgumentError] The received content does not seems to be HTML.
@return [String] | [
"Retrieve",
"the",
"body"
] | 5488354b7dd75b5411a881d734aa7176546e7cb4 | https://github.com/jhass/open_graph_reader/blob/5488354b7dd75b5411a881d734aa7176546e7cb4/lib/open_graph_reader/fetcher.rb#L70-L75 | train |
jhass/open_graph_reader | lib/open_graph_reader/fetcher.rb | OpenGraphReader.Fetcher.html? | def html?
fetch_headers unless fetched_headers?
response = @get_response || @head_response
return false if fetch_failed?
return false unless response
return false unless response.success?
return false unless response["content-type"]
response["content-type"].include? "text/html"... | ruby | def html?
fetch_headers unless fetched_headers?
response = @get_response || @head_response
return false if fetch_failed?
return false unless response
return false unless response.success?
return false unless response["content-type"]
response["content-type"].include? "text/html"... | [
"def",
"html?",
"fetch_headers",
"unless",
"fetched_headers?",
"response",
"=",
"@get_response",
"||",
"@head_response",
"return",
"false",
"if",
"fetch_failed?",
"return",
"false",
"unless",
"response",
"return",
"false",
"unless",
"response",
".",
"success?",
"retur... | Whether the target URI seems to return HTML
@return [Bool] | [
"Whether",
"the",
"target",
"URI",
"seems",
"to",
"return",
"HTML"
] | 5488354b7dd75b5411a881d734aa7176546e7cb4 | https://github.com/jhass/open_graph_reader/blob/5488354b7dd75b5411a881d734aa7176546e7cb4/lib/open_graph_reader/fetcher.rb#L80-L88 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.