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
sequence | docstring
stringlengths 8
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.position_object | def position_object(col_start, row_start, x1, y1, width, height) #:nodoc:
# col_start; # Col containing upper left corner of object
# x1; # Distance to left side of object
# row_start; # Row containing top left corner of object
# y1; # Distance to top of object
# col_end; # Col containing lower right corner of object
# x2; # Distance to right side of object
# row_end; # Row containing bottom right corner of object
# y2; # Distance to bottom of object
# width; # Width of image frame
# height; # Height of image frame
# Adjust start column for offsets that are greater than the col width
x1, col_start = adjust_col_position(x1, col_start)
# Adjust start row for offsets that are greater than the row height
y1, row_start = adjust_row_position(y1, row_start)
# Initialise end cell to the same as the start cell
col_end = col_start
row_end = row_start
width += x1
height += y1
# Subtract the underlying cell widths to find the end cell of the image
width, col_end = adjust_col_position(width, col_end)
# Subtract the underlying cell heights to find the end cell of the image
height, row_end = adjust_row_position(height, row_end)
# Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
# with zero eight or width.
#
return if size_col(col_start) == 0
return if size_col(col_end) == 0
return if size_row(row_start) == 0
return if size_row(row_end) == 0
# Convert the pixel values to the percentage value expected by Excel
x1 = 1024.0 * x1 / size_col(col_start)
y1 = 256.0 * y1 / size_row(row_start)
x2 = 1024.0 * width / size_col(col_end)
y2 = 256.0 * height / size_row(row_end)
# Simulate ceil() without calling POSIX::ceil().
x1 = (x1 +0.5).to_i
y1 = (y1 +0.5).to_i
x2 = (x2 +0.5).to_i
y2 = (y2 +0.5).to_i
[
col_start, x1,
row_start, y1,
col_end, x2,
row_end, y2
]
end | ruby | def position_object(col_start, row_start, x1, y1, width, height) #:nodoc:
# col_start; # Col containing upper left corner of object
# x1; # Distance to left side of object
# row_start; # Row containing top left corner of object
# y1; # Distance to top of object
# col_end; # Col containing lower right corner of object
# x2; # Distance to right side of object
# row_end; # Row containing bottom right corner of object
# y2; # Distance to bottom of object
# width; # Width of image frame
# height; # Height of image frame
# Adjust start column for offsets that are greater than the col width
x1, col_start = adjust_col_position(x1, col_start)
# Adjust start row for offsets that are greater than the row height
y1, row_start = adjust_row_position(y1, row_start)
# Initialise end cell to the same as the start cell
col_end = col_start
row_end = row_start
width += x1
height += y1
# Subtract the underlying cell widths to find the end cell of the image
width, col_end = adjust_col_position(width, col_end)
# Subtract the underlying cell heights to find the end cell of the image
height, row_end = adjust_row_position(height, row_end)
# Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
# with zero eight or width.
#
return if size_col(col_start) == 0
return if size_col(col_end) == 0
return if size_row(row_start) == 0
return if size_row(row_end) == 0
# Convert the pixel values to the percentage value expected by Excel
x1 = 1024.0 * x1 / size_col(col_start)
y1 = 256.0 * y1 / size_row(row_start)
x2 = 1024.0 * width / size_col(col_end)
y2 = 256.0 * height / size_row(row_end)
# Simulate ceil() without calling POSIX::ceil().
x1 = (x1 +0.5).to_i
y1 = (y1 +0.5).to_i
x2 = (x2 +0.5).to_i
y2 = (y2 +0.5).to_i
[
col_start, x1,
row_start, y1,
col_end, x2,
row_end, y2
]
end | [
"def",
"position_object",
"(",
"col_start",
",",
"row_start",
",",
"x1",
",",
"y1",
",",
"width",
",",
"height",
")",
"#:nodoc:",
"# col_start; # Col containing upper left corner of object",
"# x1; # Distance to left side of object",
"# row_start; # Row containing top left corner of object",
"# y1; # Distance to top of object",
"# col_end; # Col containing lower right corner of object",
"# x2; # Distance to right side of object",
"# row_end; # Row containing bottom right corner of object",
"# y2; # Distance to bottom of object",
"# width; # Width of image frame",
"# height; # Height of image frame",
"# Adjust start column for offsets that are greater than the col width",
"x1",
",",
"col_start",
"=",
"adjust_col_position",
"(",
"x1",
",",
"col_start",
")",
"# Adjust start row for offsets that are greater than the row height",
"y1",
",",
"row_start",
"=",
"adjust_row_position",
"(",
"y1",
",",
"row_start",
")",
"# Initialise end cell to the same as the start cell",
"col_end",
"=",
"col_start",
"row_end",
"=",
"row_start",
"width",
"+=",
"x1",
"height",
"+=",
"y1",
"# Subtract the underlying cell widths to find the end cell of the image",
"width",
",",
"col_end",
"=",
"adjust_col_position",
"(",
"width",
",",
"col_end",
")",
"# Subtract the underlying cell heights to find the end cell of the image",
"height",
",",
"row_end",
"=",
"adjust_row_position",
"(",
"height",
",",
"row_end",
")",
"# Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell",
"# with zero eight or width.",
"#",
"return",
"if",
"size_col",
"(",
"col_start",
")",
"==",
"0",
"return",
"if",
"size_col",
"(",
"col_end",
")",
"==",
"0",
"return",
"if",
"size_row",
"(",
"row_start",
")",
"==",
"0",
"return",
"if",
"size_row",
"(",
"row_end",
")",
"==",
"0",
"# Convert the pixel values to the percentage value expected by Excel",
"x1",
"=",
"1024.0",
"*",
"x1",
"/",
"size_col",
"(",
"col_start",
")",
"y1",
"=",
"256.0",
"*",
"y1",
"/",
"size_row",
"(",
"row_start",
")",
"x2",
"=",
"1024.0",
"*",
"width",
"/",
"size_col",
"(",
"col_end",
")",
"y2",
"=",
"256.0",
"*",
"height",
"/",
"size_row",
"(",
"row_end",
")",
"# Simulate ceil() without calling POSIX::ceil().",
"x1",
"=",
"(",
"x1",
"+",
"0.5",
")",
".",
"to_i",
"y1",
"=",
"(",
"y1",
"+",
"0.5",
")",
".",
"to_i",
"x2",
"=",
"(",
"x2",
"+",
"0.5",
")",
".",
"to_i",
"y2",
"=",
"(",
"y2",
"+",
"0.5",
")",
".",
"to_i",
"[",
"col_start",
",",
"x1",
",",
"row_start",
",",
"y1",
",",
"col_end",
",",
"x2",
",",
"row_end",
",",
"y2",
"]",
"end"
] | Calculate the vertices that define the position of a graphical object within
the worksheet.
+------------+------------+
| A | B |
+-----+------------+------------+
| |(x1,y1) | |
| 1 |(A1)._______|______ |
| | | | |
| | | | |
+-----+----| BITMAP |-----+
| | | | |
| 2 | |______________. |
| | | (B2)|
| | | (x2,y2)|
+---- +------------+------------+
Example of a bitmap that covers some of the area from cell A1 to cell B2.
Based on the width and height of the bitmap we need to calculate 8 vars:
$col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2.
The width and height of the cells are also variable and have to be taken into
account.
The values of $col_start and $row_start are passed in from the calling
function. The values of $col_end and $row_end are calculated by subtracting
the width and height of the bitmap from the width and height of the
underlying cells.
The vertices are expressed as a percentage of the underlying cell width as
follows (rhs values are in pixels):
x1 = X / W *1024
y1 = Y / H *256
x2 = (X-1) / W *1024
y2 = (Y-1) / H *256
Where: X is distance from the left side of the underlying cell
Y is distance from the top of the underlying cell
W is the width of the cell
H is the height of the cell
Note: the SDK incorrectly states that the height should be expressed as a
percentage of 1024. | [
"Calculate",
"the",
"vertices",
"that",
"define",
"the",
"position",
"of",
"a",
"graphical",
"object",
"within",
"the",
"worksheet",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4410-L4471 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_sp_container | def store_mso_sp_container(length) #:nodoc:
type = 0xF004
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_sp_container(length) #:nodoc:
type = 0xF004
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_sp_container",
"(",
"length",
")",
"#:nodoc:",
"type",
"=",
"0xF004",
"version",
"=",
"15",
"instance",
"=",
"0",
"data",
"=",
"''",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher SpContainer record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"SpContainer",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4489-L4496 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_sp | def store_mso_sp(instance, spid, options) #:nodoc:
type = 0xF00A
version = 2
data = ''
length = 8
data = [spid, options].pack('VV')
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_sp(instance, spid, options) #:nodoc:
type = 0xF00A
version = 2
data = ''
length = 8
data = [spid, options].pack('VV')
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_sp",
"(",
"instance",
",",
"spid",
",",
"options",
")",
"#:nodoc:",
"type",
"=",
"0xF00A",
"version",
"=",
"2",
"data",
"=",
"''",
"length",
"=",
"8",
"data",
"=",
"[",
"spid",
",",
"options",
"]",
".",
"pack",
"(",
"'VV'",
")",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher Sp record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"Sp",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4501-L4509 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_client_data | def store_mso_client_data #:nodoc:
type = 0xF011
version = 0
instance = 0
data = ''
length = 0
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_client_data #:nodoc:
type = 0xF011
version = 0
instance = 0
data = ''
length = 0
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_client_data",
"#:nodoc:",
"type",
"=",
"0xF011",
"version",
"=",
"0",
"instance",
"=",
"0",
"data",
"=",
"''",
"length",
"=",
"0",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher ClientData record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"ClientData",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4561-L4569 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.boundsheet | def boundsheet #:nodoc:
hidden = self.hidden? ? 1 : 0
encoding = self.is_name_utf16be? ? 1 : 0
record = 0x0085 # Record identifier
length = 0x08 + @name.bytesize # Number of bytes to follow
cch = @name.bytesize # Length of sheet name
# Character length is num of chars not num of bytes
cch /= 2 if is_name_utf16be?
# Change the UTF-16 name from BE to LE
sheetname = is_name_utf16be? ? @name.unpack('v*').pack('n*') : @name
grbit = @type | hidden
header = [record, length].pack("vv")
data = [@offset, grbit, cch, encoding].pack("VvCC")
header + data + sheetname
end | ruby | def boundsheet #:nodoc:
hidden = self.hidden? ? 1 : 0
encoding = self.is_name_utf16be? ? 1 : 0
record = 0x0085 # Record identifier
length = 0x08 + @name.bytesize # Number of bytes to follow
cch = @name.bytesize # Length of sheet name
# Character length is num of chars not num of bytes
cch /= 2 if is_name_utf16be?
# Change the UTF-16 name from BE to LE
sheetname = is_name_utf16be? ? @name.unpack('v*').pack('n*') : @name
grbit = @type | hidden
header = [record, length].pack("vv")
data = [@offset, grbit, cch, encoding].pack("VvCC")
header + data + sheetname
end | [
"def",
"boundsheet",
"#:nodoc:",
"hidden",
"=",
"self",
".",
"hidden?",
"?",
"1",
":",
"0",
"encoding",
"=",
"self",
".",
"is_name_utf16be?",
"?",
"1",
":",
"0",
"record",
"=",
"0x0085",
"# Record identifier",
"length",
"=",
"0x08",
"+",
"@name",
".",
"bytesize",
"# Number of bytes to follow",
"cch",
"=",
"@name",
".",
"bytesize",
"# Length of sheet name",
"# Character length is num of chars not num of bytes",
"cch",
"/=",
"2",
"if",
"is_name_utf16be?",
"# Change the UTF-16 name from BE to LE",
"sheetname",
"=",
"is_name_utf16be?",
"?",
"@name",
".",
"unpack",
"(",
"'v*'",
")",
".",
"pack",
"(",
"'n*'",
")",
":",
"@name",
"grbit",
"=",
"@type",
"|",
"hidden",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"@offset",
",",
"grbit",
",",
"cch",
",",
"encoding",
"]",
".",
"pack",
"(",
"\"VvCC\"",
")",
"header",
"+",
"data",
"+",
"sheetname",
"end"
] | Excel BIFF BOUNDSHEET record.
sheetname # Worksheet name
offset # Location of worksheet BOF
type # Worksheet type
hidden # Worksheet hidden flag
encoding # Sheet name encoding | [
"Excel",
"BIFF",
"BOUNDSHEET",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4584-L4605 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.parse_filter_expression | def parse_filter_expression(expression, tokens) #:nodoc:
# The number of tokens will be either 3 (for 1 expression)
# or 7 (for 2 expressions).
#
if (tokens.size == 7)
conditional = tokens[3]
if conditional =~ /^(and|&&)$/
conditional = 0
elsif conditional =~ /^(or|\|\|)$/
conditional = 1
else
raise "Token '#{conditional}' is not a valid conditional " +
"in filter expression '#{expression}'"
end
expression_1 = parse_filter_tokens(expression, tokens[0..2])
expression_2 = parse_filter_tokens(expression, tokens[4..6])
[expression_1, conditional, expression_2].flatten
else
parse_filter_tokens(expression, tokens)
end
end | ruby | def parse_filter_expression(expression, tokens) #:nodoc:
# The number of tokens will be either 3 (for 1 expression)
# or 7 (for 2 expressions).
#
if (tokens.size == 7)
conditional = tokens[3]
if conditional =~ /^(and|&&)$/
conditional = 0
elsif conditional =~ /^(or|\|\|)$/
conditional = 1
else
raise "Token '#{conditional}' is not a valid conditional " +
"in filter expression '#{expression}'"
end
expression_1 = parse_filter_tokens(expression, tokens[0..2])
expression_2 = parse_filter_tokens(expression, tokens[4..6])
[expression_1, conditional, expression_2].flatten
else
parse_filter_tokens(expression, tokens)
end
end | [
"def",
"parse_filter_expression",
"(",
"expression",
",",
"tokens",
")",
"#:nodoc:",
"# The number of tokens will be either 3 (for 1 expression)",
"# or 7 (for 2 expressions).",
"#",
"if",
"(",
"tokens",
".",
"size",
"==",
"7",
")",
"conditional",
"=",
"tokens",
"[",
"3",
"]",
"if",
"conditional",
"=~",
"/",
"/",
"conditional",
"=",
"0",
"elsif",
"conditional",
"=~",
"/",
"\\|",
"\\|",
"/",
"conditional",
"=",
"1",
"else",
"raise",
"\"Token '#{conditional}' is not a valid conditional \"",
"+",
"\"in filter expression '#{expression}'\"",
"end",
"expression_1",
"=",
"parse_filter_tokens",
"(",
"expression",
",",
"tokens",
"[",
"0",
"..",
"2",
"]",
")",
"expression_2",
"=",
"parse_filter_tokens",
"(",
"expression",
",",
"tokens",
"[",
"4",
"..",
"6",
"]",
")",
"[",
"expression_1",
",",
"conditional",
",",
"expression_2",
"]",
".",
"flatten",
"else",
"parse_filter_tokens",
"(",
"expression",
",",
"tokens",
")",
"end",
"end"
] | Converts the tokens of a possibly conditional expression into 1 or 2
sub expressions for further parsing.
Examples:
('x', '==', 2000) -> exp1
('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2 | [
"Converts",
"the",
"tokens",
"of",
"a",
"possibly",
"conditional",
"expression",
"into",
"1",
"or",
"2",
"sub",
"expressions",
"for",
"further",
"parsing",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4775-L4795 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.xf_record_index | def xf_record_index(row, col, xf=nil) #:nodoc:
if xf.respond_to?(:xf_index)
xf.xf_index
elsif @row_formats.has_key?(row)
@row_formats[row].xf_index
elsif @col_formats.has_key?(col)
@col_formats[col].xf_index
else
0x0F
end
end | ruby | def xf_record_index(row, col, xf=nil) #:nodoc:
if xf.respond_to?(:xf_index)
xf.xf_index
elsif @row_formats.has_key?(row)
@row_formats[row].xf_index
elsif @col_formats.has_key?(col)
@col_formats[col].xf_index
else
0x0F
end
end | [
"def",
"xf_record_index",
"(",
"row",
",",
"col",
",",
"xf",
"=",
"nil",
")",
"#:nodoc:",
"if",
"xf",
".",
"respond_to?",
"(",
":xf_index",
")",
"xf",
".",
"xf_index",
"elsif",
"@row_formats",
".",
"has_key?",
"(",
"row",
")",
"@row_formats",
"[",
"row",
"]",
".",
"xf_index",
"elsif",
"@col_formats",
".",
"has_key?",
"(",
"col",
")",
"@col_formats",
"[",
"col",
"]",
".",
"xf_index",
"else",
"0x0F",
"end",
"end"
] | Returns an index to the XF record in the workbook.
Note: this is a function, not a method. | [
"Returns",
"an",
"index",
"to",
"the",
"XF",
"record",
"in",
"the",
"workbook",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L4918-L4928 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.encode_password | def encode_password(password)
i = 0
chars = password.split(//)
count = chars.size
chars.collect! do |char|
i += 1
char = char.ord << i
low_15 = char & 0x7fff
high_15 = char & 0x7fff << 15
high_15 = high_15 >> 15
char = low_15 | high_15
end
encoded_password = 0x0000
chars.each { |c| encoded_password ^= c }
encoded_password ^= count
encoded_password ^= 0xCE4B
end | ruby | def encode_password(password)
i = 0
chars = password.split(//)
count = chars.size
chars.collect! do |char|
i += 1
char = char.ord << i
low_15 = char & 0x7fff
high_15 = char & 0x7fff << 15
high_15 = high_15 >> 15
char = low_15 | high_15
end
encoded_password = 0x0000
chars.each { |c| encoded_password ^= c }
encoded_password ^= count
encoded_password ^= 0xCE4B
end | [
"def",
"encode_password",
"(",
"password",
")",
"i",
"=",
"0",
"chars",
"=",
"password",
".",
"split",
"(",
"/",
"/",
")",
"count",
"=",
"chars",
".",
"size",
"chars",
".",
"collect!",
"do",
"|",
"char",
"|",
"i",
"+=",
"1",
"char",
"=",
"char",
".",
"ord",
"<<",
"i",
"low_15",
"=",
"char",
"&",
"0x7fff",
"high_15",
"=",
"char",
"&",
"0x7fff",
"<<",
"15",
"high_15",
"=",
"high_15",
">>",
"15",
"char",
"=",
"low_15",
"|",
"high_15",
"end",
"encoded_password",
"=",
"0x0000",
"chars",
".",
"each",
"{",
"|",
"c",
"|",
"encoded_password",
"^=",
"c",
"}",
"encoded_password",
"^=",
"count",
"encoded_password",
"^=",
"0xCE4B",
"end"
] | Based on the algorithm provided by Daniel Rentz of OpenOffice. | [
"Based",
"on",
"the",
"algorithm",
"provided",
"by",
"Daniel",
"Rentz",
"of",
"OpenOffice",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5005-L5023 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.get_formula_string | def get_formula_string(string) #:nodoc:
ruby_19 { string = convert_to_ascii_if_ascii(string) }
record = 0x0207 # Record identifier
length = 0x00 # Bytes to follow
# string # Formula string.
strlen = string.bytesize # Length of the formula string (chars).
encoding = 0 # String encoding.
# Handle utf8 strings.
if is_utf8?(string)
string = utf8_to_16be(string)
encoding = 1
end
length = 0x03 + string.bytesize # Length of the record data
header = [record, length].pack("vv")
data = [strlen, encoding].pack("vC")
header + data + string
end | ruby | def get_formula_string(string) #:nodoc:
ruby_19 { string = convert_to_ascii_if_ascii(string) }
record = 0x0207 # Record identifier
length = 0x00 # Bytes to follow
# string # Formula string.
strlen = string.bytesize # Length of the formula string (chars).
encoding = 0 # String encoding.
# Handle utf8 strings.
if is_utf8?(string)
string = utf8_to_16be(string)
encoding = 1
end
length = 0x03 + string.bytesize # Length of the record data
header = [record, length].pack("vv")
data = [strlen, encoding].pack("vC")
header + data + string
end | [
"def",
"get_formula_string",
"(",
"string",
")",
"#:nodoc:",
"ruby_19",
"{",
"string",
"=",
"convert_to_ascii_if_ascii",
"(",
"string",
")",
"}",
"record",
"=",
"0x0207",
"# Record identifier",
"length",
"=",
"0x00",
"# Bytes to follow",
"# string # Formula string.",
"strlen",
"=",
"string",
".",
"bytesize",
"# Length of the formula string (chars).",
"encoding",
"=",
"0",
"# String encoding.",
"# Handle utf8 strings.",
"if",
"is_utf8?",
"(",
"string",
")",
"string",
"=",
"utf8_to_16be",
"(",
"string",
")",
"encoding",
"=",
"1",
"end",
"length",
"=",
"0x03",
"+",
"string",
".",
"bytesize",
"# Length of the record data",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"strlen",
",",
"encoding",
"]",
".",
"pack",
"(",
"\"vC\"",
")",
"header",
"+",
"data",
"+",
"string",
"end"
] | Pack the string value when a formula evaluates to a string. The value cannot
be calculated by the module and thus must be supplied by the user. | [
"Pack",
"the",
"string",
"value",
"when",
"a",
"formula",
"evaluates",
"to",
"a",
"string",
".",
"The",
"value",
"cannot",
"be",
"calculated",
"by",
"the",
"module",
"and",
"thus",
"must",
"be",
"supplied",
"by",
"the",
"user",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5077-L5098 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_dimensions | def store_dimensions #:nodoc:
record = 0x0200 # Record identifier
length = 0x000E # Number of bytes to follow
reserved = 0x0000 # Reserved by Excel
@dimension.increment_row_max
@dimension.increment_col_max
header = [record, length].pack("vv")
fields = [@dimension.row_min, @dimension.row_max, @dimension.col_min, @dimension.col_max, reserved]
data = fields.pack("VVvvv")
prepend(header, data)
end | ruby | def store_dimensions #:nodoc:
record = 0x0200 # Record identifier
length = 0x000E # Number of bytes to follow
reserved = 0x0000 # Reserved by Excel
@dimension.increment_row_max
@dimension.increment_col_max
header = [record, length].pack("vv")
fields = [@dimension.row_min, @dimension.row_max, @dimension.col_min, @dimension.col_max, reserved]
data = fields.pack("VVvvv")
prepend(header, data)
end | [
"def",
"store_dimensions",
"#:nodoc:",
"record",
"=",
"0x0200",
"# Record identifier",
"length",
"=",
"0x000E",
"# Number of bytes to follow",
"reserved",
"=",
"0x0000",
"# Reserved by Excel",
"@dimension",
".",
"increment_row_max",
"@dimension",
".",
"increment_col_max",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"fields",
"=",
"[",
"@dimension",
".",
"row_min",
",",
"@dimension",
".",
"row_max",
",",
"@dimension",
".",
"col_min",
",",
"@dimension",
".",
"col_max",
",",
"reserved",
"]",
"data",
"=",
"fields",
".",
"pack",
"(",
"\"VVvvv\"",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Writes Excel DIMENSIONS to define the area in which there is cell data.
Notes:
Excel stores the max row/col as row/col +1.
Max and min values of 0 are used to indicate that no cell data.
We set the undef member data to 0 since it is used by store_table().
Inserting images or charts doesn't change the DIMENSION data. | [
"Writes",
"Excel",
"DIMENSIONS",
"to",
"define",
"the",
"area",
"in",
"which",
"there",
"is",
"cell",
"data",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5508-L5521 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_window2 | def store_window2 #:nodoc:
record = 0x023E # Record identifier
length = 0x0012 # Number of bytes to follow
grbit = 0x00B6 # Option flags
rwTop = @first_row # Top visible row
colLeft = @first_col # Leftmost visible column
rgbHdr = 0x00000040 # Row/col heading, grid color
wScaleSLV = 0x0000 # Zoom in page break preview
wScaleNormal = 0x0000 # Zoom in normal view
reserved = 0x00000000
# The options flags that comprise $grbit
fDspFmla = @display_formulas # 0 - bit
fDspGrid = @screen_gridlines # 1
fDspRwCol = @display_headers # 2
fFrozen = frozen? ? 1 : 0 # 3
fDspZeros = display_zeros? ? 1 : 0 # 4
fDefaultHdr = 1 # 5
fArabic = @display_arabic || 0 # 6
fDspGuts = @outline.visible? ? 1 : 0 # 7
fFrozenNoSplit = @frozen_no_split # 0 - bit
fSelected = selected? ? 1 : 0 # 1
fPaged = active? ? 1 : 0 # 2
fBreakPreview = 0 # 3
grbit = fDspFmla
grbit |= fDspGrid << 1
grbit |= fDspRwCol << 2
grbit |= fFrozen << 3
grbit |= fDspZeros << 4
grbit |= fDefaultHdr << 5
grbit |= fArabic << 6
grbit |= fDspGuts << 7
grbit |= fFrozenNoSplit << 8
grbit |= fSelected << 9
grbit |= fPaged << 10
grbit |= fBreakPreview << 11
header = [record, length].pack("vv")
data =[grbit, rwTop, colLeft, rgbHdr, wScaleSLV, wScaleNormal, reserved].pack("vvvVvvV")
append(header, data)
end | ruby | def store_window2 #:nodoc:
record = 0x023E # Record identifier
length = 0x0012 # Number of bytes to follow
grbit = 0x00B6 # Option flags
rwTop = @first_row # Top visible row
colLeft = @first_col # Leftmost visible column
rgbHdr = 0x00000040 # Row/col heading, grid color
wScaleSLV = 0x0000 # Zoom in page break preview
wScaleNormal = 0x0000 # Zoom in normal view
reserved = 0x00000000
# The options flags that comprise $grbit
fDspFmla = @display_formulas # 0 - bit
fDspGrid = @screen_gridlines # 1
fDspRwCol = @display_headers # 2
fFrozen = frozen? ? 1 : 0 # 3
fDspZeros = display_zeros? ? 1 : 0 # 4
fDefaultHdr = 1 # 5
fArabic = @display_arabic || 0 # 6
fDspGuts = @outline.visible? ? 1 : 0 # 7
fFrozenNoSplit = @frozen_no_split # 0 - bit
fSelected = selected? ? 1 : 0 # 1
fPaged = active? ? 1 : 0 # 2
fBreakPreview = 0 # 3
grbit = fDspFmla
grbit |= fDspGrid << 1
grbit |= fDspRwCol << 2
grbit |= fFrozen << 3
grbit |= fDspZeros << 4
grbit |= fDefaultHdr << 5
grbit |= fArabic << 6
grbit |= fDspGuts << 7
grbit |= fFrozenNoSplit << 8
grbit |= fSelected << 9
grbit |= fPaged << 10
grbit |= fBreakPreview << 11
header = [record, length].pack("vv")
data =[grbit, rwTop, colLeft, rgbHdr, wScaleSLV, wScaleNormal, reserved].pack("vvvVvvV")
append(header, data)
end | [
"def",
"store_window2",
"#:nodoc:",
"record",
"=",
"0x023E",
"# Record identifier",
"length",
"=",
"0x0012",
"# Number of bytes to follow",
"grbit",
"=",
"0x00B6",
"# Option flags",
"rwTop",
"=",
"@first_row",
"# Top visible row",
"colLeft",
"=",
"@first_col",
"# Leftmost visible column",
"rgbHdr",
"=",
"0x00000040",
"# Row/col heading, grid color",
"wScaleSLV",
"=",
"0x0000",
"# Zoom in page break preview",
"wScaleNormal",
"=",
"0x0000",
"# Zoom in normal view",
"reserved",
"=",
"0x00000000",
"# The options flags that comprise $grbit",
"fDspFmla",
"=",
"@display_formulas",
"# 0 - bit",
"fDspGrid",
"=",
"@screen_gridlines",
"# 1",
"fDspRwCol",
"=",
"@display_headers",
"# 2",
"fFrozen",
"=",
"frozen?",
"?",
"1",
":",
"0",
"# 3",
"fDspZeros",
"=",
"display_zeros?",
"?",
"1",
":",
"0",
"# 4",
"fDefaultHdr",
"=",
"1",
"# 5",
"fArabic",
"=",
"@display_arabic",
"||",
"0",
"# 6",
"fDspGuts",
"=",
"@outline",
".",
"visible?",
"?",
"1",
":",
"0",
"# 7",
"fFrozenNoSplit",
"=",
"@frozen_no_split",
"# 0 - bit",
"fSelected",
"=",
"selected?",
"?",
"1",
":",
"0",
"# 1",
"fPaged",
"=",
"active?",
"?",
"1",
":",
"0",
"# 2",
"fBreakPreview",
"=",
"0",
"# 3",
"grbit",
"=",
"fDspFmla",
"grbit",
"|=",
"fDspGrid",
"<<",
"1",
"grbit",
"|=",
"fDspRwCol",
"<<",
"2",
"grbit",
"|=",
"fFrozen",
"<<",
"3",
"grbit",
"|=",
"fDspZeros",
"<<",
"4",
"grbit",
"|=",
"fDefaultHdr",
"<<",
"5",
"grbit",
"|=",
"fArabic",
"<<",
"6",
"grbit",
"|=",
"fDspGuts",
"<<",
"7",
"grbit",
"|=",
"fFrozenNoSplit",
"<<",
"8",
"grbit",
"|=",
"fSelected",
"<<",
"9",
"grbit",
"|=",
"fPaged",
"<<",
"10",
"grbit",
"|=",
"fBreakPreview",
"<<",
"11",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"grbit",
",",
"rwTop",
",",
"colLeft",
",",
"rgbHdr",
",",
"wScaleSLV",
",",
"wScaleNormal",
",",
"reserved",
"]",
".",
"pack",
"(",
"\"vvvVvvV\"",
")",
"append",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record Window2. | [
"Write",
"BIFF",
"record",
"Window2",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5526-L5571 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_tab_color | def store_tab_color #:nodoc:
color = @tab_color
return if color == 0
record = 0x0862 # Record identifier
length = 0x0014 # Number of bytes to follow
zero = 0x0000
unknown = 0x0014
store_simple(record, length, record, zero, zero, zero, zero,
zero, unknown, zero, color, zero)
end | ruby | def store_tab_color #:nodoc:
color = @tab_color
return if color == 0
record = 0x0862 # Record identifier
length = 0x0014 # Number of bytes to follow
zero = 0x0000
unknown = 0x0014
store_simple(record, length, record, zero, zero, zero, zero,
zero, unknown, zero, color, zero)
end | [
"def",
"store_tab_color",
"#:nodoc:",
"color",
"=",
"@tab_color",
"return",
"if",
"color",
"==",
"0",
"record",
"=",
"0x0862",
"# Record identifier",
"length",
"=",
"0x0014",
"# Number of bytes to follow",
"zero",
"=",
"0x0000",
"unknown",
"=",
"0x0014",
"store_simple",
"(",
"record",
",",
"length",
",",
"record",
",",
"zero",
",",
"zero",
",",
"zero",
",",
"zero",
",",
"zero",
",",
"unknown",
",",
"zero",
",",
"color",
",",
"zero",
")",
"end"
] | Write the Tab Color BIFF record. | [
"Write",
"the",
"Tab",
"Color",
"BIFF",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5585-L5598 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_defrow | def store_defrow #:nodoc:
record = 0x0225 # Record identifier
length = 0x0004 # Number of bytes to follow
grbit = 0x0000 # Options.
height = 0x00FF # Default row height
header = [record, length].pack("vv")
data = [grbit, height].pack("vv")
prepend(header, data)
end | ruby | def store_defrow #:nodoc:
record = 0x0225 # Record identifier
length = 0x0004 # Number of bytes to follow
grbit = 0x0000 # Options.
height = 0x00FF # Default row height
header = [record, length].pack("vv")
data = [grbit, height].pack("vv")
prepend(header, data)
end | [
"def",
"store_defrow",
"#:nodoc:",
"record",
"=",
"0x0225",
"# Record identifier",
"length",
"=",
"0x0004",
"# Number of bytes to follow",
"grbit",
"=",
"0x0000",
"# Options.",
"height",
"=",
"0x00FF",
"# Default row height",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"grbit",
",",
"height",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record DEFROWHEIGHT. | [
"Write",
"BIFF",
"record",
"DEFROWHEIGHT",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5603-L5614 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_defcol | def store_defcol #:nodoc:
record = 0x0055 # Record identifier
length = 0x0002 # Number of bytes to follow
colwidth = 0x0008 # Default column width
header = [record, length].pack("vv")
data = [colwidth].pack("v")
prepend(header, data)
end | ruby | def store_defcol #:nodoc:
record = 0x0055 # Record identifier
length = 0x0002 # Number of bytes to follow
colwidth = 0x0008 # Default column width
header = [record, length].pack("vv")
data = [colwidth].pack("v")
prepend(header, data)
end | [
"def",
"store_defcol",
"#:nodoc:",
"record",
"=",
"0x0055",
"# Record identifier",
"length",
"=",
"0x0002",
"# Number of bytes to follow",
"colwidth",
"=",
"0x0008",
"# Default column width",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"colwidth",
"]",
".",
"pack",
"(",
"\"v\"",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record DEFCOLWIDTH. | [
"Write",
"BIFF",
"record",
"DEFCOLWIDTH",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5619-L5628 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_autofilterinfo | def store_autofilterinfo #:nodoc:
# Only write the record if the worksheet contains an autofilter.
return '' if @filter_area.count == 0
record = 0x009D # Record identifier
length = 0x0002 # Number of bytes to follow
num_filters = @filter_area.count
header = [record, length].pack('vv')
data = [num_filters].pack('v')
prepend(header, data)
end | ruby | def store_autofilterinfo #:nodoc:
# Only write the record if the worksheet contains an autofilter.
return '' if @filter_area.count == 0
record = 0x009D # Record identifier
length = 0x0002 # Number of bytes to follow
num_filters = @filter_area.count
header = [record, length].pack('vv')
data = [num_filters].pack('v')
prepend(header, data)
end | [
"def",
"store_autofilterinfo",
"#:nodoc:",
"# Only write the record if the worksheet contains an autofilter.",
"return",
"''",
"if",
"@filter_area",
".",
"count",
"==",
"0",
"record",
"=",
"0x009D",
"# Record identifier",
"length",
"=",
"0x0002",
"# Number of bytes to follow",
"num_filters",
"=",
"@filter_area",
".",
"count",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"'vv'",
")",
"data",
"=",
"[",
"num_filters",
"]",
".",
"pack",
"(",
"'v'",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record AUTOFILTERINFO. | [
"Write",
"BIFF",
"record",
"AUTOFILTERINFO",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5653-L5665 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_selection | def store_selection(first_row=0, first_col=0, last_row = nil, last_col =nil) #:nodoc:
record = 0x001D # Record identifier
length = 0x000F # Number of bytes to follow
pane_position = @active_pane # Pane position
row_active = first_row # Active row
col_active = first_col # Active column
irefAct = 0 # Active cell ref
cref = 1 # Number of refs
row_first = first_row # First row in reference
col_first = first_col # First col in reference
row_last = last_row || row_first # Last row in reference
col_last = last_col || col_first # Last col in reference
# Swap last row/col for first row/col as necessary
row_first, row_last = row_last, row_first if row_first > row_last
col_first, col_last = col_last, col_first if col_first > col_last
header = [record, length].pack('vv')
data = [pane_position, row_active, col_active, irefAct, cref,
row_first, row_last, col_first, col_last].pack('CvvvvvvCC')
append(header, data)
end | ruby | def store_selection(first_row=0, first_col=0, last_row = nil, last_col =nil) #:nodoc:
record = 0x001D # Record identifier
length = 0x000F # Number of bytes to follow
pane_position = @active_pane # Pane position
row_active = first_row # Active row
col_active = first_col # Active column
irefAct = 0 # Active cell ref
cref = 1 # Number of refs
row_first = first_row # First row in reference
col_first = first_col # First col in reference
row_last = last_row || row_first # Last row in reference
col_last = last_col || col_first # Last col in reference
# Swap last row/col for first row/col as necessary
row_first, row_last = row_last, row_first if row_first > row_last
col_first, col_last = col_last, col_first if col_first > col_last
header = [record, length].pack('vv')
data = [pane_position, row_active, col_active, irefAct, cref,
row_first, row_last, col_first, col_last].pack('CvvvvvvCC')
append(header, data)
end | [
"def",
"store_selection",
"(",
"first_row",
"=",
"0",
",",
"first_col",
"=",
"0",
",",
"last_row",
"=",
"nil",
",",
"last_col",
"=",
"nil",
")",
"#:nodoc:",
"record",
"=",
"0x001D",
"# Record identifier",
"length",
"=",
"0x000F",
"# Number of bytes to follow",
"pane_position",
"=",
"@active_pane",
"# Pane position",
"row_active",
"=",
"first_row",
"# Active row",
"col_active",
"=",
"first_col",
"# Active column",
"irefAct",
"=",
"0",
"# Active cell ref",
"cref",
"=",
"1",
"# Number of refs",
"row_first",
"=",
"first_row",
"# First row in reference",
"col_first",
"=",
"first_col",
"# First col in reference",
"row_last",
"=",
"last_row",
"||",
"row_first",
"# Last row in reference",
"col_last",
"=",
"last_col",
"||",
"col_first",
"# Last col in reference",
"# Swap last row/col for first row/col as necessary",
"row_first",
",",
"row_last",
"=",
"row_last",
",",
"row_first",
"if",
"row_first",
">",
"row_last",
"col_first",
",",
"col_last",
"=",
"col_last",
",",
"col_first",
"if",
"col_first",
">",
"col_last",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"'vv'",
")",
"data",
"=",
"[",
"pane_position",
",",
"row_active",
",",
"col_active",
",",
"irefAct",
",",
"cref",
",",
"row_first",
",",
"row_last",
",",
"col_first",
",",
"col_last",
"]",
".",
"pack",
"(",
"'CvvvvvvCC'",
")",
"append",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record SELECTION. | [
"Write",
"BIFF",
"record",
"SELECTION",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5670-L5694 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_externcount | def store_externcount(count) #:nodoc:
record = 0x0016 # Record identifier
length = 0x0002 # Number of bytes to follow
cxals = count # Number of external references
header = [record, length].pack('vv')
data = [cxals].pack('v')
prepend(header, data)
end | ruby | def store_externcount(count) #:nodoc:
record = 0x0016 # Record identifier
length = 0x0002 # Number of bytes to follow
cxals = count # Number of external references
header = [record, length].pack('vv')
data = [cxals].pack('v')
prepend(header, data)
end | [
"def",
"store_externcount",
"(",
"count",
")",
"#:nodoc:",
"record",
"=",
"0x0016",
"# Record identifier",
"length",
"=",
"0x0002",
"# Number of bytes to follow",
"cxals",
"=",
"count",
"# Number of external references",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"'vv'",
")",
"data",
"=",
"[",
"cxals",
"]",
".",
"pack",
"(",
"'v'",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write BIFF record EXTERNCOUNT to indicate the number of external sheet
references in a worksheet.
Excel only stores references to external sheets that are used in formulas.
For simplicity we store references to all the sheets in the workbook
regardless of whether they are used or not. This reduces the overall
complexity and eliminates the need for a two way dialogue between the formula
parser the worksheet objects. | [
"Write",
"BIFF",
"record",
"EXTERNCOUNT",
"to",
"indicate",
"the",
"number",
"of",
"external",
"sheet",
"references",
"in",
"a",
"worksheet",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5706-L5716 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_setup | def store_setup #:nodoc:
record = 0x00A1 # Record identifier
length = 0x0022 # Number of bytes to follow
iPaperSize = @paper_size # Paper size
iScale = @print_scale # Print scaling factor
iPageStart = @page_start # Starting page number
iFitWidth = @fit_width # Fit to number of pages wide
iFitHeight = @fit_height # Fit to number of pages high
grbit = 0x00 # Option flags
iRes = 0x0258 # Print resolution
iVRes = 0x0258 # Vertical print resolution
numHdr = @margin_header # Header Margin
numFtr = @margin_footer # Footer Margin
iCopies = 0x01 # Number of copies
fLeftToRight = @page_order # Print over then down
fLandscape = @orientation # Page orientation
fNoPls = 0x0 # Setup not read from printer
fNoColor = @black_white # Print black and white
fDraft = @draft_quality # Print draft quality
fNotes = @print_comments# Print notes
fNoOrient = 0x0 # Orientation not set
fUsePage = @custom_start # Use custom starting page
grbit = fLeftToRight
grbit |= fLandscape << 1
grbit |= fNoPls << 2
grbit |= fNoColor << 3
grbit |= fDraft << 4
grbit |= fNotes << 5
grbit |= fNoOrient << 6
grbit |= fUsePage << 7
numHdr = [numHdr].pack('d')
numFtr = [numFtr].pack('d')
if @byte_order
numHdr.reverse!
numFtr.reverse!
end
header = [record, length].pack('vv')
data1 = [iPaperSize, iScale, iPageStart,
iFitWidth, iFitHeight, grbit, iRes, iVRes].pack("vvvvvvvv")
data2 = numHdr + numFtr
data3 = [iCopies].pack('v')
prepend(header, data1, data2, data3)
end | ruby | def store_setup #:nodoc:
record = 0x00A1 # Record identifier
length = 0x0022 # Number of bytes to follow
iPaperSize = @paper_size # Paper size
iScale = @print_scale # Print scaling factor
iPageStart = @page_start # Starting page number
iFitWidth = @fit_width # Fit to number of pages wide
iFitHeight = @fit_height # Fit to number of pages high
grbit = 0x00 # Option flags
iRes = 0x0258 # Print resolution
iVRes = 0x0258 # Vertical print resolution
numHdr = @margin_header # Header Margin
numFtr = @margin_footer # Footer Margin
iCopies = 0x01 # Number of copies
fLeftToRight = @page_order # Print over then down
fLandscape = @orientation # Page orientation
fNoPls = 0x0 # Setup not read from printer
fNoColor = @black_white # Print black and white
fDraft = @draft_quality # Print draft quality
fNotes = @print_comments# Print notes
fNoOrient = 0x0 # Orientation not set
fUsePage = @custom_start # Use custom starting page
grbit = fLeftToRight
grbit |= fLandscape << 1
grbit |= fNoPls << 2
grbit |= fNoColor << 3
grbit |= fDraft << 4
grbit |= fNotes << 5
grbit |= fNoOrient << 6
grbit |= fUsePage << 7
numHdr = [numHdr].pack('d')
numFtr = [numFtr].pack('d')
if @byte_order
numHdr.reverse!
numFtr.reverse!
end
header = [record, length].pack('vv')
data1 = [iPaperSize, iScale, iPageStart,
iFitWidth, iFitHeight, grbit, iRes, iVRes].pack("vvvvvvvv")
data2 = numHdr + numFtr
data3 = [iCopies].pack('v')
prepend(header, data1, data2, data3)
end | [
"def",
"store_setup",
"#:nodoc:",
"record",
"=",
"0x00A1",
"# Record identifier",
"length",
"=",
"0x0022",
"# Number of bytes to follow",
"iPaperSize",
"=",
"@paper_size",
"# Paper size",
"iScale",
"=",
"@print_scale",
"# Print scaling factor",
"iPageStart",
"=",
"@page_start",
"# Starting page number",
"iFitWidth",
"=",
"@fit_width",
"# Fit to number of pages wide",
"iFitHeight",
"=",
"@fit_height",
"# Fit to number of pages high",
"grbit",
"=",
"0x00",
"# Option flags",
"iRes",
"=",
"0x0258",
"# Print resolution",
"iVRes",
"=",
"0x0258",
"# Vertical print resolution",
"numHdr",
"=",
"@margin_header",
"# Header Margin",
"numFtr",
"=",
"@margin_footer",
"# Footer Margin",
"iCopies",
"=",
"0x01",
"# Number of copies",
"fLeftToRight",
"=",
"@page_order",
"# Print over then down",
"fLandscape",
"=",
"@orientation",
"# Page orientation",
"fNoPls",
"=",
"0x0",
"# Setup not read from printer",
"fNoColor",
"=",
"@black_white",
"# Print black and white",
"fDraft",
"=",
"@draft_quality",
"# Print draft quality",
"fNotes",
"=",
"@print_comments",
"# Print notes",
"fNoOrient",
"=",
"0x0",
"# Orientation not set",
"fUsePage",
"=",
"@custom_start",
"# Use custom starting page",
"grbit",
"=",
"fLeftToRight",
"grbit",
"|=",
"fLandscape",
"<<",
"1",
"grbit",
"|=",
"fNoPls",
"<<",
"2",
"grbit",
"|=",
"fNoColor",
"<<",
"3",
"grbit",
"|=",
"fDraft",
"<<",
"4",
"grbit",
"|=",
"fNotes",
"<<",
"5",
"grbit",
"|=",
"fNoOrient",
"<<",
"6",
"grbit",
"|=",
"fUsePage",
"<<",
"7",
"numHdr",
"=",
"[",
"numHdr",
"]",
".",
"pack",
"(",
"'d'",
")",
"numFtr",
"=",
"[",
"numFtr",
"]",
".",
"pack",
"(",
"'d'",
")",
"if",
"@byte_order",
"numHdr",
".",
"reverse!",
"numFtr",
".",
"reverse!",
"end",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"'vv'",
")",
"data1",
"=",
"[",
"iPaperSize",
",",
"iScale",
",",
"iPageStart",
",",
"iFitWidth",
",",
"iFitHeight",
",",
"grbit",
",",
"iRes",
",",
"iVRes",
"]",
".",
"pack",
"(",
"\"vvvvvvvv\"",
")",
"data2",
"=",
"numHdr",
"+",
"numFtr",
"data3",
"=",
"[",
"iCopies",
"]",
".",
"pack",
"(",
"'v'",
")",
"prepend",
"(",
"header",
",",
"data1",
",",
"data2",
",",
"data3",
")",
"end"
] | Store the page setup SETUP BIFF record. | [
"Store",
"the",
"page",
"setup",
"SETUP",
"BIFF",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L5807-L5859 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_gridset | def store_gridset #:nodoc:
record = 0x0082 # Record identifier
length = 0x0002 # Bytes to follow
fGridSet = @print_gridlines == 0 ? 1 : 0 # Boolean flag
header = [record, length].pack("vv")
data = [fGridSet].pack("v")
prepend(header, data)
end | ruby | def store_gridset #:nodoc:
record = 0x0082 # Record identifier
length = 0x0002 # Bytes to follow
fGridSet = @print_gridlines == 0 ? 1 : 0 # Boolean flag
header = [record, length].pack("vv")
data = [fGridSet].pack("v")
prepend(header, data)
end | [
"def",
"store_gridset",
"#:nodoc:",
"record",
"=",
"0x0082",
"# Record identifier",
"length",
"=",
"0x0002",
"# Bytes to follow",
"fGridSet",
"=",
"@print_gridlines",
"==",
"0",
"?",
"1",
":",
"0",
"# Boolean flag",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"fGridSet",
"]",
".",
"pack",
"(",
"\"v\"",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write the GRIDSET BIFF record. Must be used in conjunction with the
PRINTGRIDLINES record. | [
"Write",
"the",
"GRIDSET",
"BIFF",
"record",
".",
"Must",
"be",
"used",
"in",
"conjunction",
"with",
"the",
"PRINTGRIDLINES",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6032-L6042 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_wsbool | def store_wsbool #:nodoc:
record = 0x0081 # Record identifier
length = 0x0002 # Bytes to follow
grbit = 0x0000 # Option flags
# Set the option flags
grbit |= 0x0001 # Auto page breaks visible
grbit |= 0x0020 if @outline.style != 0 # Auto outline styles
grbit |= 0x0040 if @outline.below != 0 # Outline summary below
grbit |= 0x0080 if @outline.right != 0 # Outline summary right
grbit |= 0x0100 if @fit_page != 0 # Page setup fit to page
grbit |= 0x0400 if @outline.visible? # Outline symbols displayed
header = [record, length].pack("vv")
data = [grbit].pack('v')
prepend(header, data)
end | ruby | def store_wsbool #:nodoc:
record = 0x0081 # Record identifier
length = 0x0002 # Bytes to follow
grbit = 0x0000 # Option flags
# Set the option flags
grbit |= 0x0001 # Auto page breaks visible
grbit |= 0x0020 if @outline.style != 0 # Auto outline styles
grbit |= 0x0040 if @outline.below != 0 # Outline summary below
grbit |= 0x0080 if @outline.right != 0 # Outline summary right
grbit |= 0x0100 if @fit_page != 0 # Page setup fit to page
grbit |= 0x0400 if @outline.visible? # Outline symbols displayed
header = [record, length].pack("vv")
data = [grbit].pack('v')
prepend(header, data)
end | [
"def",
"store_wsbool",
"#:nodoc:",
"record",
"=",
"0x0081",
"# Record identifier",
"length",
"=",
"0x0002",
"# Bytes to follow",
"grbit",
"=",
"0x0000",
"# Option flags",
"# Set the option flags",
"grbit",
"|=",
"0x0001",
"# Auto page breaks visible",
"grbit",
"|=",
"0x0020",
"if",
"@outline",
".",
"style",
"!=",
"0",
"# Auto outline styles",
"grbit",
"|=",
"0x0040",
"if",
"@outline",
".",
"below",
"!=",
"0",
"# Outline summary below",
"grbit",
"|=",
"0x0080",
"if",
"@outline",
".",
"right",
"!=",
"0",
"# Outline summary right",
"grbit",
"|=",
"0x0100",
"if",
"@fit_page",
"!=",
"0",
"# Page setup fit to page",
"grbit",
"|=",
"0x0400",
"if",
"@outline",
".",
"visible?",
"# Outline symbols displayed",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"grbit",
"]",
".",
"pack",
"(",
"'v'",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write the WSBOOL BIFF record, mainly for fit-to-page. Used in conjunction
with the SETUP record. | [
"Write",
"the",
"WSBOOL",
"BIFF",
"record",
"mainly",
"for",
"fit",
"-",
"to",
"-",
"page",
".",
"Used",
"in",
"conjunction",
"with",
"the",
"SETUP",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6083-L6101 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_password | def store_password #:nodoc:
# Exit unless sheet protection and password have been specified
return unless protect? && @password
record = 0x0013 # Record identifier
length = 0x0002 # Bytes to follow
wPassword = @password # Encoded password
header = [record, length].pack("vv")
data = [wPassword].pack("v")
prepend(header, data)
end | ruby | def store_password #:nodoc:
# Exit unless sheet protection and password have been specified
return unless protect? && @password
record = 0x0013 # Record identifier
length = 0x0002 # Bytes to follow
wPassword = @password # Encoded password
header = [record, length].pack("vv")
data = [wPassword].pack("v")
prepend(header, data)
end | [
"def",
"store_password",
"#:nodoc:",
"# Exit unless sheet protection and password have been specified",
"return",
"unless",
"protect?",
"&&",
"@password",
"record",
"=",
"0x0013",
"# Record identifier",
"length",
"=",
"0x0002",
"# Bytes to follow",
"wPassword",
"=",
"@password",
"# Encoded password",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"wPassword",
"]",
".",
"pack",
"(",
"\"v\"",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Write the worksheet PASSWORD record. | [
"Write",
"the",
"worksheet",
"PASSWORD",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6175-L6188 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_table | def store_table #:nodoc:
return unless compatibility?
# Offset from the DBCELL record back to the first ROW of the 32 row block.
row_offset = 0
# Track rows that have cell data or modified by set_row().
written_rows = []
# Write the ROW records with updated max/min col fields.
#
(0 .. @dimension.row_max-1).each do |row|
# Skip unless there is cell data in row or the row has been modified.
next unless @table[row] or @row_data[row]
# Store the rows with data.
written_rows.push(row)
# Increase the row offset by the length of a ROW record;
row_offset += 20
# The max/min cols in the ROW records are the same as in DIMENSIONS.
col_min = @dimension.col_min
col_max = @dimension.col_max
# Write a user specified ROW record (modified by set_row()).
if @row_data[row]
# Rewrite the min and max cols for user defined row record.
packed_row = @row_data[row]
packed_row[6..9] = [col_min, col_max].pack('vv')
append(packed_row)
else
# Write a default Row record if there isn't a user defined ROW.
write_row_default(row, col_min, col_max)
end
# If 32 rows have been written or we are at the last row in the
# worksheet then write the cell data and the DBCELL record.
#
if written_rows.size == 32 || row == @dimension.row_max - 1
# Offsets to the first cell of each row.
cell_offsets = []
cell_offsets.push(row_offset - 20)
# Write the cell data in each row and sum their lengths for the
# cell offsets.
#
written_rows.each do |rw|
cell_offset = 0
if @table[rw]
@table[rw].each do |clm|
next unless clm
append(clm)
length = clm.bytesize
row_offset += length
cell_offset += length
end
end
cell_offsets.push(cell_offset)
end
# The last offset isn't required.
cell_offsets.pop
# Stores the DBCELL offset for use in the INDEX record.
@db_indices.push(@datasize)
# Write the DBCELL record.
store_dbcell(row_offset, cell_offsets)
# Clear the variable for the next block of rows.
written_rows = []
cell_offsets = []
row_offset = 0
end
end
end | ruby | def store_table #:nodoc:
return unless compatibility?
# Offset from the DBCELL record back to the first ROW of the 32 row block.
row_offset = 0
# Track rows that have cell data or modified by set_row().
written_rows = []
# Write the ROW records with updated max/min col fields.
#
(0 .. @dimension.row_max-1).each do |row|
# Skip unless there is cell data in row or the row has been modified.
next unless @table[row] or @row_data[row]
# Store the rows with data.
written_rows.push(row)
# Increase the row offset by the length of a ROW record;
row_offset += 20
# The max/min cols in the ROW records are the same as in DIMENSIONS.
col_min = @dimension.col_min
col_max = @dimension.col_max
# Write a user specified ROW record (modified by set_row()).
if @row_data[row]
# Rewrite the min and max cols for user defined row record.
packed_row = @row_data[row]
packed_row[6..9] = [col_min, col_max].pack('vv')
append(packed_row)
else
# Write a default Row record if there isn't a user defined ROW.
write_row_default(row, col_min, col_max)
end
# If 32 rows have been written or we are at the last row in the
# worksheet then write the cell data and the DBCELL record.
#
if written_rows.size == 32 || row == @dimension.row_max - 1
# Offsets to the first cell of each row.
cell_offsets = []
cell_offsets.push(row_offset - 20)
# Write the cell data in each row and sum their lengths for the
# cell offsets.
#
written_rows.each do |rw|
cell_offset = 0
if @table[rw]
@table[rw].each do |clm|
next unless clm
append(clm)
length = clm.bytesize
row_offset += length
cell_offset += length
end
end
cell_offsets.push(cell_offset)
end
# The last offset isn't required.
cell_offsets.pop
# Stores the DBCELL offset for use in the INDEX record.
@db_indices.push(@datasize)
# Write the DBCELL record.
store_dbcell(row_offset, cell_offsets)
# Clear the variable for the next block of rows.
written_rows = []
cell_offsets = []
row_offset = 0
end
end
end | [
"def",
"store_table",
"#:nodoc:",
"return",
"unless",
"compatibility?",
"# Offset from the DBCELL record back to the first ROW of the 32 row block.",
"row_offset",
"=",
"0",
"# Track rows that have cell data or modified by set_row().",
"written_rows",
"=",
"[",
"]",
"# Write the ROW records with updated max/min col fields.",
"#",
"(",
"0",
"..",
"@dimension",
".",
"row_max",
"-",
"1",
")",
".",
"each",
"do",
"|",
"row",
"|",
"# Skip unless there is cell data in row or the row has been modified.",
"next",
"unless",
"@table",
"[",
"row",
"]",
"or",
"@row_data",
"[",
"row",
"]",
"# Store the rows with data.",
"written_rows",
".",
"push",
"(",
"row",
")",
"# Increase the row offset by the length of a ROW record;",
"row_offset",
"+=",
"20",
"# The max/min cols in the ROW records are the same as in DIMENSIONS.",
"col_min",
"=",
"@dimension",
".",
"col_min",
"col_max",
"=",
"@dimension",
".",
"col_max",
"# Write a user specified ROW record (modified by set_row()).",
"if",
"@row_data",
"[",
"row",
"]",
"# Rewrite the min and max cols for user defined row record.",
"packed_row",
"=",
"@row_data",
"[",
"row",
"]",
"packed_row",
"[",
"6",
"..",
"9",
"]",
"=",
"[",
"col_min",
",",
"col_max",
"]",
".",
"pack",
"(",
"'vv'",
")",
"append",
"(",
"packed_row",
")",
"else",
"# Write a default Row record if there isn't a user defined ROW.",
"write_row_default",
"(",
"row",
",",
"col_min",
",",
"col_max",
")",
"end",
"# If 32 rows have been written or we are at the last row in the",
"# worksheet then write the cell data and the DBCELL record.",
"#",
"if",
"written_rows",
".",
"size",
"==",
"32",
"||",
"row",
"==",
"@dimension",
".",
"row_max",
"-",
"1",
"# Offsets to the first cell of each row.",
"cell_offsets",
"=",
"[",
"]",
"cell_offsets",
".",
"push",
"(",
"row_offset",
"-",
"20",
")",
"# Write the cell data in each row and sum their lengths for the",
"# cell offsets.",
"#",
"written_rows",
".",
"each",
"do",
"|",
"rw",
"|",
"cell_offset",
"=",
"0",
"if",
"@table",
"[",
"rw",
"]",
"@table",
"[",
"rw",
"]",
".",
"each",
"do",
"|",
"clm",
"|",
"next",
"unless",
"clm",
"append",
"(",
"clm",
")",
"length",
"=",
"clm",
".",
"bytesize",
"row_offset",
"+=",
"length",
"cell_offset",
"+=",
"length",
"end",
"end",
"cell_offsets",
".",
"push",
"(",
"cell_offset",
")",
"end",
"# The last offset isn't required.",
"cell_offsets",
".",
"pop",
"# Stores the DBCELL offset for use in the INDEX record.",
"@db_indices",
".",
"push",
"(",
"@datasize",
")",
"# Write the DBCELL record.",
"store_dbcell",
"(",
"row_offset",
",",
"cell_offsets",
")",
"# Clear the variable for the next block of rows.",
"written_rows",
"=",
"[",
"]",
"cell_offsets",
"=",
"[",
"]",
"row_offset",
"=",
"0",
"end",
"end",
"end"
] | Note about compatibility mode.
Excel doesn't require every possible Biff record to be present in a file.
In particular if the indexing records INDEX, ROW and DBCELL aren't present
it just ignores the fact and reads the cells anyway. This is also true of
the EXTSST record. Gnumeric and OOo also take this approach. This allows
WriteExcel to ignore these records in order to minimise the amount of data
stored in memory. However, other third party applications that read Excel
files often expect these records to be present. In "compatibility mode"
WriteExcel writes these records and tries to be as close to an Excel
generated file as possible.
This requires additional data to be stored in memory until the file is
about to be written. This incurs a memory and speed penalty and may not be
suitable for very large files.
Write cell data stored in the worksheet row/col table.
This is only used when compatibity_mode() is in operation.
This method writes ROW data, then cell data (NUMBER, LABELSST, etc) and then
DBCELL records in blocks of 32 rows. This is explained in detail (for a
change) in the Excel SDK and in the OOo Excel file format doc. | [
"Note",
"about",
"compatibility",
"mode",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6219-L6297 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.size_col | def size_col(col) #:nodoc:
# Look up the cell value to see if it has been changed
if @col_sizes[col]
width = @col_sizes[col]
# The relationship is different for user units less than 1.
if width < 1
(width *12).to_i
else
(width *7 +5 ).to_i
end
else
64
end
end | ruby | def size_col(col) #:nodoc:
# Look up the cell value to see if it has been changed
if @col_sizes[col]
width = @col_sizes[col]
# The relationship is different for user units less than 1.
if width < 1
(width *12).to_i
else
(width *7 +5 ).to_i
end
else
64
end
end | [
"def",
"size_col",
"(",
"col",
")",
"#:nodoc:",
"# Look up the cell value to see if it has been changed",
"if",
"@col_sizes",
"[",
"col",
"]",
"width",
"=",
"@col_sizes",
"[",
"col",
"]",
"# The relationship is different for user units less than 1.",
"if",
"width",
"<",
"1",
"(",
"width",
"12",
")",
".",
"to_i",
"else",
"(",
"width",
"7",
"+",
"5",
")",
".",
"to_i",
"end",
"else",
"64",
"end",
"end"
] | Convert the width of a cell from user's units to pixels. Excel rounds the
column width to the nearest pixel. If the width hasn't been set by the user
we use the default value. If the column is hidden we use a value of zero. | [
"Convert",
"the",
"width",
"of",
"a",
"cell",
"from",
"user",
"s",
"units",
"to",
"pixels",
".",
"Excel",
"rounds",
"the",
"column",
"width",
"to",
"the",
"nearest",
"pixel",
".",
"If",
"the",
"width",
"hasn",
"t",
"been",
"set",
"by",
"the",
"user",
"we",
"use",
"the",
"default",
"value",
".",
"If",
"the",
"column",
"is",
"hidden",
"we",
"use",
"a",
"value",
"of",
"zero",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6364-L6378 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_autofilter | def store_autofilter(index, operator_1, token_1, #:nodoc:
join = nil, operator_2 = nil, token_2 = nil)
record = 0x009E
length = 0x0000
top10_active = 0
top10_direction = 0
top10_percent = 0
top10_value = 101
grbit = join || 0
optimised_1 = 0
optimised_2 = 0
doper_1 = ''
doper_2 = ''
string_1 = ''
string_2 = ''
# Excel used an optimisation in the case of a simple equality.
optimised_1 = 1 if operator_1 == 2
optimised_2 = 1 if operator_2 && operator_2 == 2
# Convert non-simple equalities back to type 2. See parse_filter_tokens().
operator_1 = 2 if operator_1 == 22
operator_2 = 2 if operator_2 && operator_2 == 22
# Handle a "Top" style expression.
if operator_1 >= 30
# Remove the second expression if present.
operator_2 = nil
token_2 = nil
# Set the active flag.
top10_active = 1
if (operator_1 == 30 or operator_1 == 31)
top10_direction = 1
end
if (operator_1 == 31 or operator_1 == 33)
top10_percent = 1
end
if (top10_direction == 1)
operator_1 = 6
else
operator_1 = 3
end
top10_value = token_1.to_i
token_1 = 0
end
grbit |= optimised_1 << 2
grbit |= optimised_2 << 3
grbit |= top10_active << 4
grbit |= top10_direction << 5
grbit |= top10_percent << 6
grbit |= top10_value << 7
doper_1, string_1 = pack_doper(operator_1, token_1)
doper_2, string_2 = pack_doper(operator_2, token_2)
doper_1 = '' unless doper_1
doper_2 = '' unless doper_2
string_1 = '' unless string_1
string_2 = '' unless string_2
data = [index].pack('v')
data += [grbit].pack('v')
data += doper_1 + doper_2 + string_1 + string_2
length = data.bytesize
header = [record, length].pack('vv')
prepend(header, data)
end | ruby | def store_autofilter(index, operator_1, token_1, #:nodoc:
join = nil, operator_2 = nil, token_2 = nil)
record = 0x009E
length = 0x0000
top10_active = 0
top10_direction = 0
top10_percent = 0
top10_value = 101
grbit = join || 0
optimised_1 = 0
optimised_2 = 0
doper_1 = ''
doper_2 = ''
string_1 = ''
string_2 = ''
# Excel used an optimisation in the case of a simple equality.
optimised_1 = 1 if operator_1 == 2
optimised_2 = 1 if operator_2 && operator_2 == 2
# Convert non-simple equalities back to type 2. See parse_filter_tokens().
operator_1 = 2 if operator_1 == 22
operator_2 = 2 if operator_2 && operator_2 == 22
# Handle a "Top" style expression.
if operator_1 >= 30
# Remove the second expression if present.
operator_2 = nil
token_2 = nil
# Set the active flag.
top10_active = 1
if (operator_1 == 30 or operator_1 == 31)
top10_direction = 1
end
if (operator_1 == 31 or operator_1 == 33)
top10_percent = 1
end
if (top10_direction == 1)
operator_1 = 6
else
operator_1 = 3
end
top10_value = token_1.to_i
token_1 = 0
end
grbit |= optimised_1 << 2
grbit |= optimised_2 << 3
grbit |= top10_active << 4
grbit |= top10_direction << 5
grbit |= top10_percent << 6
grbit |= top10_value << 7
doper_1, string_1 = pack_doper(operator_1, token_1)
doper_2, string_2 = pack_doper(operator_2, token_2)
doper_1 = '' unless doper_1
doper_2 = '' unless doper_2
string_1 = '' unless string_1
string_2 = '' unless string_2
data = [index].pack('v')
data += [grbit].pack('v')
data += doper_1 + doper_2 + string_1 + string_2
length = data.bytesize
header = [record, length].pack('vv')
prepend(header, data)
end | [
"def",
"store_autofilter",
"(",
"index",
",",
"operator_1",
",",
"token_1",
",",
"#:nodoc:",
"join",
"=",
"nil",
",",
"operator_2",
"=",
"nil",
",",
"token_2",
"=",
"nil",
")",
"record",
"=",
"0x009E",
"length",
"=",
"0x0000",
"top10_active",
"=",
"0",
"top10_direction",
"=",
"0",
"top10_percent",
"=",
"0",
"top10_value",
"=",
"101",
"grbit",
"=",
"join",
"||",
"0",
"optimised_1",
"=",
"0",
"optimised_2",
"=",
"0",
"doper_1",
"=",
"''",
"doper_2",
"=",
"''",
"string_1",
"=",
"''",
"string_2",
"=",
"''",
"# Excel used an optimisation in the case of a simple equality.",
"optimised_1",
"=",
"1",
"if",
"operator_1",
"==",
"2",
"optimised_2",
"=",
"1",
"if",
"operator_2",
"&&",
"operator_2",
"==",
"2",
"# Convert non-simple equalities back to type 2. See parse_filter_tokens().",
"operator_1",
"=",
"2",
"if",
"operator_1",
"==",
"22",
"operator_2",
"=",
"2",
"if",
"operator_2",
"&&",
"operator_2",
"==",
"22",
"# Handle a \"Top\" style expression.",
"if",
"operator_1",
">=",
"30",
"# Remove the second expression if present.",
"operator_2",
"=",
"nil",
"token_2",
"=",
"nil",
"# Set the active flag.",
"top10_active",
"=",
"1",
"if",
"(",
"operator_1",
"==",
"30",
"or",
"operator_1",
"==",
"31",
")",
"top10_direction",
"=",
"1",
"end",
"if",
"(",
"operator_1",
"==",
"31",
"or",
"operator_1",
"==",
"33",
")",
"top10_percent",
"=",
"1",
"end",
"if",
"(",
"top10_direction",
"==",
"1",
")",
"operator_1",
"=",
"6",
"else",
"operator_1",
"=",
"3",
"end",
"top10_value",
"=",
"token_1",
".",
"to_i",
"token_1",
"=",
"0",
"end",
"grbit",
"|=",
"optimised_1",
"<<",
"2",
"grbit",
"|=",
"optimised_2",
"<<",
"3",
"grbit",
"|=",
"top10_active",
"<<",
"4",
"grbit",
"|=",
"top10_direction",
"<<",
"5",
"grbit",
"|=",
"top10_percent",
"<<",
"6",
"grbit",
"|=",
"top10_value",
"<<",
"7",
"doper_1",
",",
"string_1",
"=",
"pack_doper",
"(",
"operator_1",
",",
"token_1",
")",
"doper_2",
",",
"string_2",
"=",
"pack_doper",
"(",
"operator_2",
",",
"token_2",
")",
"doper_1",
"=",
"''",
"unless",
"doper_1",
"doper_2",
"=",
"''",
"unless",
"doper_2",
"string_1",
"=",
"''",
"unless",
"string_1",
"string_2",
"=",
"''",
"unless",
"string_2",
"data",
"=",
"[",
"index",
"]",
".",
"pack",
"(",
"'v'",
")",
"data",
"+=",
"[",
"grbit",
"]",
".",
"pack",
"(",
"'v'",
")",
"data",
"+=",
"doper_1",
"+",
"doper_2",
"+",
"string_1",
"+",
"string_2",
"length",
"=",
"data",
".",
"bytesize",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"'vv'",
")",
"prepend",
"(",
"header",
",",
"data",
")",
"end"
] | Function to write worksheet AUTOFILTER records. These contain 2 Biff Doper
structures to represent the 2 possible filter conditions. | [
"Function",
"to",
"write",
"worksheet",
"AUTOFILTER",
"records",
".",
"These",
"contain",
"2",
"Biff",
"Doper",
"structures",
"to",
"represent",
"the",
"2",
"possible",
"filter",
"conditions",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6444-L6520 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.pack_doper | def pack_doper(operator, token) #:nodoc:
doper = ''
string = ''
# Return default doper for non-defined filters.
unless operator
return pack_unused_doper, string
end
if token.to_s =~ /^blanks|nonblanks$/i
doper = pack_blanks_doper(operator, token)
elsif operator == 2 or
!(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
# Excel treats all tokens as strings if the operator is equality, =.
string = token.to_s
ruby_19 { string = convert_to_ascii_if_ascii(string) }
encoding = 0
length = string.bytesize
# Handle utf8 strings
if is_utf8?(string)
string = utf8_to_16be(string)
encodign = 1
end
string =
ruby_18 { [encoding].pack('C') + string } ||
ruby_19 { [encoding].pack('C') + string.force_encoding('BINARY') }
doper = pack_string_doper(operator, length)
else
string = ''
doper = pack_number_doper(operator, token)
end
[doper, string]
end | ruby | def pack_doper(operator, token) #:nodoc:
doper = ''
string = ''
# Return default doper for non-defined filters.
unless operator
return pack_unused_doper, string
end
if token.to_s =~ /^blanks|nonblanks$/i
doper = pack_blanks_doper(operator, token)
elsif operator == 2 or
!(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
# Excel treats all tokens as strings if the operator is equality, =.
string = token.to_s
ruby_19 { string = convert_to_ascii_if_ascii(string) }
encoding = 0
length = string.bytesize
# Handle utf8 strings
if is_utf8?(string)
string = utf8_to_16be(string)
encodign = 1
end
string =
ruby_18 { [encoding].pack('C') + string } ||
ruby_19 { [encoding].pack('C') + string.force_encoding('BINARY') }
doper = pack_string_doper(operator, length)
else
string = ''
doper = pack_number_doper(operator, token)
end
[doper, string]
end | [
"def",
"pack_doper",
"(",
"operator",
",",
"token",
")",
"#:nodoc:",
"doper",
"=",
"''",
"string",
"=",
"''",
"# Return default doper for non-defined filters.",
"unless",
"operator",
"return",
"pack_unused_doper",
",",
"string",
"end",
"if",
"token",
".",
"to_s",
"=~",
"/",
"/i",
"doper",
"=",
"pack_blanks_doper",
"(",
"operator",
",",
"token",
")",
"elsif",
"operator",
"==",
"2",
"or",
"!",
"(",
"token",
".",
"to_s",
"=~",
"/",
"\\d",
"\\.",
"\\d",
"\\d",
"\\.",
"\\d",
"\\d",
"/",
")",
"# Excel treats all tokens as strings if the operator is equality, =.",
"string",
"=",
"token",
".",
"to_s",
"ruby_19",
"{",
"string",
"=",
"convert_to_ascii_if_ascii",
"(",
"string",
")",
"}",
"encoding",
"=",
"0",
"length",
"=",
"string",
".",
"bytesize",
"# Handle utf8 strings",
"if",
"is_utf8?",
"(",
"string",
")",
"string",
"=",
"utf8_to_16be",
"(",
"string",
")",
"encodign",
"=",
"1",
"end",
"string",
"=",
"ruby_18",
"{",
"[",
"encoding",
"]",
".",
"pack",
"(",
"'C'",
")",
"+",
"string",
"}",
"||",
"ruby_19",
"{",
"[",
"encoding",
"]",
".",
"pack",
"(",
"'C'",
")",
"+",
"string",
".",
"force_encoding",
"(",
"'BINARY'",
")",
"}",
"doper",
"=",
"pack_string_doper",
"(",
"operator",
",",
"length",
")",
"else",
"string",
"=",
"''",
"doper",
"=",
"pack_number_doper",
"(",
"operator",
",",
"token",
")",
"end",
"[",
"doper",
",",
"string",
"]",
"end"
] | Create a Biff Doper structure that represents a filter expression. Depending
on the type of the token we pack an Empty, String or Number doper. | [
"Create",
"a",
"Biff",
"Doper",
"structure",
"that",
"represents",
"a",
"filter",
"expression",
".",
"Depending",
"on",
"the",
"type",
"of",
"the",
"token",
"we",
"pack",
"an",
"Empty",
"String",
"or",
"Number",
"doper",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6526-L6562 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.pack_number_doper | def pack_number_doper(operator, number) #:nodoc:
number = [number].pack('d')
number.reverse! if @byte_order
[0x04, operator].pack('CC') + number
end | ruby | def pack_number_doper(operator, number) #:nodoc:
number = [number].pack('d')
number.reverse! if @byte_order
[0x04, operator].pack('CC') + number
end | [
"def",
"pack_number_doper",
"(",
"operator",
",",
"number",
")",
"#:nodoc:",
"number",
"=",
"[",
"number",
"]",
".",
"pack",
"(",
"'d'",
")",
"number",
".",
"reverse!",
"if",
"@byte_order",
"[",
"0x04",
",",
"operator",
"]",
".",
"pack",
"(",
"'CC'",
")",
"+",
"number",
"end"
] | Pack an IEEE double number Doper structure. | [
"Pack",
"an",
"IEEE",
"double",
"number",
"Doper",
"structure",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6604-L6609 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_images | def store_images #:nodoc:
# Skip this if there aren't any images.
return if @images.array.empty?
spid = @object_ids.spid
@images.array.each_index do |i|
@images.array[i].store_image_record(i, @images.array.size, charts_size, @filter_area.count, comments_size, spid)
store_obj_image(i + 1)
end
@object_ids.spid = spid
end | ruby | def store_images #:nodoc:
# Skip this if there aren't any images.
return if @images.array.empty?
spid = @object_ids.spid
@images.array.each_index do |i|
@images.array[i].store_image_record(i, @images.array.size, charts_size, @filter_area.count, comments_size, spid)
store_obj_image(i + 1)
end
@object_ids.spid = spid
end | [
"def",
"store_images",
"#:nodoc:",
"# Skip this if there aren't any images.",
"return",
"if",
"@images",
".",
"array",
".",
"empty?",
"spid",
"=",
"@object_ids",
".",
"spid",
"@images",
".",
"array",
".",
"each_index",
"do",
"|",
"i",
"|",
"@images",
".",
"array",
"[",
"i",
"]",
".",
"store_image_record",
"(",
"i",
",",
"@images",
".",
"array",
".",
"size",
",",
"charts_size",
",",
"@filter_area",
".",
"count",
",",
"comments_size",
",",
"spid",
")",
"store_obj_image",
"(",
"i",
"+",
"1",
")",
"end",
"@object_ids",
".",
"spid",
"=",
"spid",
"end"
] | Store the collections of records that make up images. | [
"Store",
"the",
"collections",
"of",
"records",
"that",
"make",
"up",
"images",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6614-L6626 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_charts | def store_charts #:nodoc:
# Skip this if there aren't any charts.
return if charts_size == 0
record = 0x00EC # Record identifier
charts = @charts.array
charts.each_index do |i|
data = ''
if i == 0 && images_size == 0
dg_length = 192 + 120 * (charts_size - 1) + 96 * filter_count + 128 * comments_size
spgr_length = dg_length - 24
# Write the parent MSODRAWIING record.
data += store_parent_mso_record(dg_length, spgr_length, @object_ids.spid)
@object_ids.spid += 1
end
data += store_mso_sp_container_sp(@object_ids.spid)
data += store_mso_opt_chart_client_anchor_client_data(*charts[i].vertices)
length = data.bytesize
header = [record, length].pack("vv")
append(header, data)
store_obj_chart(images_size + i + 1)
store_chart_binary(charts[i].chart)
@object_ids.spid += 1
end
# Simulate the EXTERNSHEET link between the chart and data using a formula
# such as '=Sheet1!A1'.
# TODO. Won't work for external data refs. Also should use a more direct
# method.
#
store_formula("='#{@name}'!A1")
end | ruby | def store_charts #:nodoc:
# Skip this if there aren't any charts.
return if charts_size == 0
record = 0x00EC # Record identifier
charts = @charts.array
charts.each_index do |i|
data = ''
if i == 0 && images_size == 0
dg_length = 192 + 120 * (charts_size - 1) + 96 * filter_count + 128 * comments_size
spgr_length = dg_length - 24
# Write the parent MSODRAWIING record.
data += store_parent_mso_record(dg_length, spgr_length, @object_ids.spid)
@object_ids.spid += 1
end
data += store_mso_sp_container_sp(@object_ids.spid)
data += store_mso_opt_chart_client_anchor_client_data(*charts[i].vertices)
length = data.bytesize
header = [record, length].pack("vv")
append(header, data)
store_obj_chart(images_size + i + 1)
store_chart_binary(charts[i].chart)
@object_ids.spid += 1
end
# Simulate the EXTERNSHEET link between the chart and data using a formula
# such as '=Sheet1!A1'.
# TODO. Won't work for external data refs. Also should use a more direct
# method.
#
store_formula("='#{@name}'!A1")
end | [
"def",
"store_charts",
"#:nodoc:",
"# Skip this if there aren't any charts.",
"return",
"if",
"charts_size",
"==",
"0",
"record",
"=",
"0x00EC",
"# Record identifier",
"charts",
"=",
"@charts",
".",
"array",
"charts",
".",
"each_index",
"do",
"|",
"i",
"|",
"data",
"=",
"''",
"if",
"i",
"==",
"0",
"&&",
"images_size",
"==",
"0",
"dg_length",
"=",
"192",
"+",
"120",
"*",
"(",
"charts_size",
"-",
"1",
")",
"+",
"96",
"*",
"filter_count",
"+",
"128",
"*",
"comments_size",
"spgr_length",
"=",
"dg_length",
"-",
"24",
"# Write the parent MSODRAWIING record.",
"data",
"+=",
"store_parent_mso_record",
"(",
"dg_length",
",",
"spgr_length",
",",
"@object_ids",
".",
"spid",
")",
"@object_ids",
".",
"spid",
"+=",
"1",
"end",
"data",
"+=",
"store_mso_sp_container_sp",
"(",
"@object_ids",
".",
"spid",
")",
"data",
"+=",
"store_mso_opt_chart_client_anchor_client_data",
"(",
"charts",
"[",
"i",
"]",
".",
"vertices",
")",
"length",
"=",
"data",
".",
"bytesize",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"append",
"(",
"header",
",",
"data",
")",
"store_obj_chart",
"(",
"images_size",
"+",
"i",
"+",
"1",
")",
"store_chart_binary",
"(",
"charts",
"[",
"i",
"]",
".",
"chart",
")",
"@object_ids",
".",
"spid",
"+=",
"1",
"end",
"# Simulate the EXTERNSHEET link between the chart and data using a formula",
"# such as '=Sheet1!A1'.",
"# TODO. Won't work for external data refs. Also should use a more direct",
"# method.",
"#",
"store_formula",
"(",
"\"='#{@name}'!A1\"",
")",
"end"
] | Store the collections of records that make up charts. | [
"Store",
"the",
"collections",
"of",
"records",
"that",
"make",
"up",
"charts",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6639-L6674 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_comments | def store_comments #:nodoc:
return if @comments.array.empty?
spid = @object_ids.spid
num_comments = comments_size
# Number of objects written so far.
num_objects = images_size + @filter_area.count + charts_size
@comments.array.each_index { |i| spid = @comments.array[i].store_comment_record(i, num_objects, num_comments, spid) }
# Write the NOTE records after MSODRAWIING records.
@comments.array.each_index { |i| @comments.array[i].store_note_record(num_objects + i + 1) }
end | ruby | def store_comments #:nodoc:
return if @comments.array.empty?
spid = @object_ids.spid
num_comments = comments_size
# Number of objects written so far.
num_objects = images_size + @filter_area.count + charts_size
@comments.array.each_index { |i| spid = @comments.array[i].store_comment_record(i, num_objects, num_comments, spid) }
# Write the NOTE records after MSODRAWIING records.
@comments.array.each_index { |i| @comments.array[i].store_note_record(num_objects + i + 1) }
end | [
"def",
"store_comments",
"#:nodoc:",
"return",
"if",
"@comments",
".",
"array",
".",
"empty?",
"spid",
"=",
"@object_ids",
".",
"spid",
"num_comments",
"=",
"comments_size",
"# Number of objects written so far.",
"num_objects",
"=",
"images_size",
"+",
"@filter_area",
".",
"count",
"+",
"charts_size",
"@comments",
".",
"array",
".",
"each_index",
"{",
"|",
"i",
"|",
"spid",
"=",
"@comments",
".",
"array",
"[",
"i",
"]",
".",
"store_comment_record",
"(",
"i",
",",
"num_objects",
",",
"num_comments",
",",
"spid",
")",
"}",
"# Write the NOTE records after MSODRAWIING records.",
"@comments",
".",
"array",
".",
"each_index",
"{",
"|",
"i",
"|",
"@comments",
".",
"array",
"[",
"i",
"]",
".",
"store_note_record",
"(",
"num_objects",
"+",
"i",
"+",
"1",
")",
"}",
"end"
] | Store the collections of records that make up cell comments.
NOTE: We write the comment objects last since that makes it a little easier
to write the NOTE records directly after the MSODRAWIING records. | [
"Store",
"the",
"collections",
"of",
"records",
"that",
"make",
"up",
"cell",
"comments",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6728-L6741 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_dg_container | def store_mso_dg_container(length) #:nodoc:
type = 0xF002
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_dg_container(length) #:nodoc:
type = 0xF002
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_dg_container",
"(",
"length",
")",
"#:nodoc:",
"type",
"=",
"0xF002",
"version",
"=",
"15",
"instance",
"=",
"0",
"data",
"=",
"''",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher DgContainer record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"DgContainer",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6746-L6752 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_dg | def store_mso_dg #:nodoc:
type = 0xF008
version = 0
length = 8
data = [@object_ids.num_shapes, @object_ids.max_spid].pack("VV")
add_mso_generic(type, version, @object_ids.drawings_saved, data, length)
end | ruby | def store_mso_dg #:nodoc:
type = 0xF008
version = 0
length = 8
data = [@object_ids.num_shapes, @object_ids.max_spid].pack("VV")
add_mso_generic(type, version, @object_ids.drawings_saved, data, length)
end | [
"def",
"store_mso_dg",
"#:nodoc:",
"type",
"=",
"0xF008",
"version",
"=",
"0",
"length",
"=",
"8",
"data",
"=",
"[",
"@object_ids",
".",
"num_shapes",
",",
"@object_ids",
".",
"max_spid",
"]",
".",
"pack",
"(",
"\"VV\"",
")",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"@object_ids",
".",
"drawings_saved",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher Dg record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"Dg",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6757-L6764 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_spgr_container | def store_mso_spgr_container(length) #:nodoc:
type = 0xF003
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_spgr_container(length) #:nodoc:
type = 0xF003
version = 15
instance = 0
data = ''
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_spgr_container",
"(",
"length",
")",
"#:nodoc:",
"type",
"=",
"0xF003",
"version",
"=",
"15",
"instance",
"=",
"0",
"data",
"=",
"''",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher SpgrContainer record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"SpgrContainer",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6769-L6776 | train |
cxn03651/writeexcel | lib/writeexcel/worksheet.rb | Writeexcel.Worksheet.store_mso_spgr | def store_mso_spgr #:nodoc:
type = 0xF009
version = 1
instance = 0
data = [0, 0, 0, 0].pack("VVVV")
length = 16
add_mso_generic(type, version, instance, data, length)
end | ruby | def store_mso_spgr #:nodoc:
type = 0xF009
version = 1
instance = 0
data = [0, 0, 0, 0].pack("VVVV")
length = 16
add_mso_generic(type, version, instance, data, length)
end | [
"def",
"store_mso_spgr",
"#:nodoc:",
"type",
"=",
"0xF009",
"version",
"=",
"1",
"instance",
"=",
"0",
"data",
"=",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
".",
"pack",
"(",
"\"VVVV\"",
")",
"length",
"=",
"16",
"add_mso_generic",
"(",
"type",
",",
"version",
",",
"instance",
",",
"data",
",",
"length",
")",
"end"
] | Write the Escher Spgr record that is part of MSODRAWING. | [
"Write",
"the",
"Escher",
"Spgr",
"record",
"that",
"is",
"part",
"of",
"MSODRAWING",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/worksheet.rb#L6781-L6789 | train |
cxn03651/writeexcel | lib/writeexcel/format.rb | Writeexcel.Format.get_font | def get_font # :nodoc:
# my $record; # Record identifier
# my $length; # Record length
# my $dyHeight; # Height of font (1/20 of a point)
# my $grbit; # Font attributes
# my $icv; # Index to color palette
# my $bls; # Bold style
# my $sss; # Superscript/subscript
# my $uls; # Underline
# my $bFamily; # Font family
# my $bCharSet; # Character set
# my $reserved; # Reserved
# my $cch; # Length of font name
# my $rgch; # Font name
# my $encoding; # Font name character encoding
dyHeight = @size * 20
icv = @color
bls = @bold
sss = @font_script
uls = @underline
bFamily = @font_family
bCharSet = @font_charset
rgch = @font
encoding = @font_encoding
ruby_19 { rgch = convert_to_ascii_if_ascii(rgch) }
# Handle utf8 strings
if is_utf8?(rgch)
rgch = utf8_to_16be(rgch)
encoding = 1
end
cch = rgch.bytesize
#
# Handle Unicode font names.
if (encoding == 1)
raise "Uneven number of bytes in Unicode font name" if cch % 2 != 0
cch /= 2 if encoding !=0
rgch = utf16be_to_16le(rgch)
end
record = 0x31
length = 0x10 + rgch.bytesize
reserved = 0x00
grbit = 0x00
grbit |= 0x02 if @italic != 0
grbit |= 0x08 if @font_strikeout != 0
grbit |= 0x10 if @font_outline != 0
grbit |= 0x20 if @font_shadow != 0
header = [record, length].pack("vv")
data = [dyHeight, grbit, icv, bls,
sss, uls, bFamily,
bCharSet, reserved, cch, encoding].pack('vvvvvCCCCCC')
header + data + rgch
end | ruby | def get_font # :nodoc:
# my $record; # Record identifier
# my $length; # Record length
# my $dyHeight; # Height of font (1/20 of a point)
# my $grbit; # Font attributes
# my $icv; # Index to color palette
# my $bls; # Bold style
# my $sss; # Superscript/subscript
# my $uls; # Underline
# my $bFamily; # Font family
# my $bCharSet; # Character set
# my $reserved; # Reserved
# my $cch; # Length of font name
# my $rgch; # Font name
# my $encoding; # Font name character encoding
dyHeight = @size * 20
icv = @color
bls = @bold
sss = @font_script
uls = @underline
bFamily = @font_family
bCharSet = @font_charset
rgch = @font
encoding = @font_encoding
ruby_19 { rgch = convert_to_ascii_if_ascii(rgch) }
# Handle utf8 strings
if is_utf8?(rgch)
rgch = utf8_to_16be(rgch)
encoding = 1
end
cch = rgch.bytesize
#
# Handle Unicode font names.
if (encoding == 1)
raise "Uneven number of bytes in Unicode font name" if cch % 2 != 0
cch /= 2 if encoding !=0
rgch = utf16be_to_16le(rgch)
end
record = 0x31
length = 0x10 + rgch.bytesize
reserved = 0x00
grbit = 0x00
grbit |= 0x02 if @italic != 0
grbit |= 0x08 if @font_strikeout != 0
grbit |= 0x10 if @font_outline != 0
grbit |= 0x20 if @font_shadow != 0
header = [record, length].pack("vv")
data = [dyHeight, grbit, icv, bls,
sss, uls, bFamily,
bCharSet, reserved, cch, encoding].pack('vvvvvCCCCCC')
header + data + rgch
end | [
"def",
"get_font",
"# :nodoc:",
"# my $record; # Record identifier",
"# my $length; # Record length",
"# my $dyHeight; # Height of font (1/20 of a point)",
"# my $grbit; # Font attributes",
"# my $icv; # Index to color palette",
"# my $bls; # Bold style",
"# my $sss; # Superscript/subscript",
"# my $uls; # Underline",
"# my $bFamily; # Font family",
"# my $bCharSet; # Character set",
"# my $reserved; # Reserved",
"# my $cch; # Length of font name",
"# my $rgch; # Font name",
"# my $encoding; # Font name character encoding",
"dyHeight",
"=",
"@size",
"*",
"20",
"icv",
"=",
"@color",
"bls",
"=",
"@bold",
"sss",
"=",
"@font_script",
"uls",
"=",
"@underline",
"bFamily",
"=",
"@font_family",
"bCharSet",
"=",
"@font_charset",
"rgch",
"=",
"@font",
"encoding",
"=",
"@font_encoding",
"ruby_19",
"{",
"rgch",
"=",
"convert_to_ascii_if_ascii",
"(",
"rgch",
")",
"}",
"# Handle utf8 strings",
"if",
"is_utf8?",
"(",
"rgch",
")",
"rgch",
"=",
"utf8_to_16be",
"(",
"rgch",
")",
"encoding",
"=",
"1",
"end",
"cch",
"=",
"rgch",
".",
"bytesize",
"#",
"# Handle Unicode font names.",
"if",
"(",
"encoding",
"==",
"1",
")",
"raise",
"\"Uneven number of bytes in Unicode font name\"",
"if",
"cch",
"%",
"2",
"!=",
"0",
"cch",
"/=",
"2",
"if",
"encoding",
"!=",
"0",
"rgch",
"=",
"utf16be_to_16le",
"(",
"rgch",
")",
"end",
"record",
"=",
"0x31",
"length",
"=",
"0x10",
"+",
"rgch",
".",
"bytesize",
"reserved",
"=",
"0x00",
"grbit",
"=",
"0x00",
"grbit",
"|=",
"0x02",
"if",
"@italic",
"!=",
"0",
"grbit",
"|=",
"0x08",
"if",
"@font_strikeout",
"!=",
"0",
"grbit",
"|=",
"0x10",
"if",
"@font_outline",
"!=",
"0",
"grbit",
"|=",
"0x20",
"if",
"@font_shadow",
"!=",
"0",
"header",
"=",
"[",
"record",
",",
"length",
"]",
".",
"pack",
"(",
"\"vv\"",
")",
"data",
"=",
"[",
"dyHeight",
",",
"grbit",
",",
"icv",
",",
"bls",
",",
"sss",
",",
"uls",
",",
"bFamily",
",",
"bCharSet",
",",
"reserved",
",",
"cch",
",",
"encoding",
"]",
".",
"pack",
"(",
"'vvvvvCCCCCC'",
")",
"header",
"+",
"data",
"+",
"rgch",
"end"
] | Generate an Excel BIFF FONT record. | [
"Generate",
"an",
"Excel",
"BIFF",
"FONT",
"record",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/format.rb#L336-L399 | train |
cxn03651/writeexcel | lib/writeexcel/format.rb | Writeexcel.Format.set_border | def set_border(style)
set_bottom(style)
set_top(style)
set_left(style)
set_right(style)
end | ruby | def set_border(style)
set_bottom(style)
set_top(style)
set_left(style)
set_right(style)
end | [
"def",
"set_border",
"(",
"style",
")",
"set_bottom",
"(",
"style",
")",
"set_top",
"(",
"style",
")",
"set_left",
"(",
"style",
")",
"set_right",
"(",
"style",
")",
"end"
] | Set cells borders to the same style
Also applies to: set_bottom()
set_top()
set_left()
set_right()
Default state: Border is off
Default action: Set border type 1
Valid args: 0-13, See below.
A cell border is comprised of a border on the bottom, top, left and right.
These can be set to the same value using set_border() or individually
using the relevant method calls shown above.
The following shows the border styles sorted by WriteExcel index number:
Index Name Weight Style
===== ============= ====== ===========
0 None 0
1 Continuous 1 -----------
2 Continuous 2 -----------
3 Dash 1 - - - - - -
4 Dot 1 . . . . . .
5 Continuous 3 -----------
6 Double 3 ===========
7 Continuous 0 -----------
8 Dash 2 - - - - - -
9 Dash Dot 1 - . - . - .
10 Dash Dot 2 - . - . - .
11 Dash Dot Dot 1 - . . - . .
12 Dash Dot Dot 2 - . . - . .
13 SlantDash Dot 2 / - . / - .
The following shows the borders sorted by style:
Name Weight Style Index
============= ====== =========== =====
Continuous 0 ----------- 7
Continuous 1 ----------- 1
Continuous 2 ----------- 2
Continuous 3 ----------- 5
Dash 1 - - - - - - 3
Dash 2 - - - - - - 8
Dash Dot 1 - . - . - . 9
Dash Dot 2 - . - . - . 10
Dash Dot Dot 1 - . . - . . 11
Dash Dot Dot 2 - . . - . . 12
Dot 1 . . . . . . 4
Double 3 =========== 6
None 0 0
SlantDash Dot 2 / - . / - . 13
The following shows the borders in the order shown in the Excel Dialog.
Index Style Index Style
===== ===== ===== =====
0 None 12 - . . - . .
7 ----------- 13 / - . / - .
4 . . . . . . 10 - . - . - .
11 - . . - . . 8 - - - - - -
9 - . - . - . 2 -----------
3 - - - - - - 5 -----------
1 ----------- 6 ===========
Examples of the available border styles are shown in the 'Borders' worksheet
created by formats.rb. | [
"Set",
"cells",
"borders",
"to",
"the",
"same",
"style"
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/format.rb#L1106-L1111 | train |
cxn03651/writeexcel | lib/writeexcel/format.rb | Writeexcel.Format.set_border_color | def set_border_color(color)
set_bottom_color(color)
set_top_color(color)
set_left_color(color)
set_right_color(color)
end | ruby | def set_border_color(color)
set_bottom_color(color)
set_top_color(color)
set_left_color(color)
set_right_color(color)
end | [
"def",
"set_border_color",
"(",
"color",
")",
"set_bottom_color",
"(",
"color",
")",
"set_top_color",
"(",
"color",
")",
"set_left_color",
"(",
"color",
")",
"set_right_color",
"(",
"color",
")",
"end"
] | Set cells border to the same color
Also applies to: set_bottom_color()
set_top_color()
set_left_color()
set_right_color()
Default state: Color is off
Default action: Undefined
Valid args: See set_color()
Set the colour of the cell borders. A cell border is comprised of a border
on the bottom, top, left and right. These can be set to the same colour
using set_border_color() or individually using the relevant method calls
shown above. Examples of the border styles and colours are shown in the
'Borders' worksheet created by formats.rb. | [
"Set",
"cells",
"border",
"to",
"the",
"same",
"color"
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/format.rb#L1163-L1168 | train |
cxn03651/writeexcel | lib/writeexcel/format.rb | Writeexcel.Format.method_missing | def method_missing(name, *args) # :nodoc:
# -- original perl comment --
# There are two types of set methods: set_property() and
# set_property_color(). When a method is AUTOLOADED we store a new anonymous
# sub in the appropriate slot in the symbol table. The speeds up subsequent
# calls to the same method.
method = "#{name}"
# Check for a valid method names, i.e. "set_xxx_yyy".
method =~ /set_(\w+)/ or raise "Unknown method: #{method}\n"
# Match the attribute, i.e. "@xxx_yyy".
attribute = "@#{$1}"
# Check that the attribute exists
# ........
if method =~ /set\w+color$/ # for "set_property_color" methods
value = get_color(args[0])
else # for "set_xxx" methods
value = args[0].nil? ? 1 : args[0]
end
if value.respond_to?(:to_str) || !value.respond_to?(:+)
s = %Q!#{attribute} = "#{value.to_s}"!
else
s = %Q!#{attribute} = #{value.to_s}!
end
eval s
end | ruby | def method_missing(name, *args) # :nodoc:
# -- original perl comment --
# There are two types of set methods: set_property() and
# set_property_color(). When a method is AUTOLOADED we store a new anonymous
# sub in the appropriate slot in the symbol table. The speeds up subsequent
# calls to the same method.
method = "#{name}"
# Check for a valid method names, i.e. "set_xxx_yyy".
method =~ /set_(\w+)/ or raise "Unknown method: #{method}\n"
# Match the attribute, i.e. "@xxx_yyy".
attribute = "@#{$1}"
# Check that the attribute exists
# ........
if method =~ /set\w+color$/ # for "set_property_color" methods
value = get_color(args[0])
else # for "set_xxx" methods
value = args[0].nil? ? 1 : args[0]
end
if value.respond_to?(:to_str) || !value.respond_to?(:+)
s = %Q!#{attribute} = "#{value.to_s}"!
else
s = %Q!#{attribute} = #{value.to_s}!
end
eval s
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"args",
")",
"# :nodoc:",
"# -- original perl comment --",
"# There are two types of set methods: set_property() and",
"# set_property_color(). When a method is AUTOLOADED we store a new anonymous",
"# sub in the appropriate slot in the symbol table. The speeds up subsequent",
"# calls to the same method.",
"method",
"=",
"\"#{name}\"",
"# Check for a valid method names, i.e. \"set_xxx_yyy\".",
"method",
"=~",
"/",
"\\w",
"/",
"or",
"raise",
"\"Unknown method: #{method}\\n\"",
"# Match the attribute, i.e. \"@xxx_yyy\".",
"attribute",
"=",
"\"@#{$1}\"",
"# Check that the attribute exists",
"# ........",
"if",
"method",
"=~",
"/",
"\\w",
"/",
"# for \"set_property_color\" methods",
"value",
"=",
"get_color",
"(",
"args",
"[",
"0",
"]",
")",
"else",
"# for \"set_xxx\" methods",
"value",
"=",
"args",
"[",
"0",
"]",
".",
"nil?",
"?",
"1",
":",
"args",
"[",
"0",
"]",
"end",
"if",
"value",
".",
"respond_to?",
"(",
":to_str",
")",
"||",
"!",
"value",
".",
"respond_to?",
"(",
":+",
")",
"s",
"=",
"%Q!#{attribute} = \"#{value.to_s}\"!",
"else",
"s",
"=",
"%Q!#{attribute} = #{value.to_s}!",
"end",
"eval",
"s",
"end"
] | Dynamically create set methods that aren't already defined. | [
"Dynamically",
"create",
"set",
"methods",
"that",
"aren",
"t",
"already",
"defined",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/format.rb#L1543-L1571 | train |
cxn03651/writeexcel | lib/writeexcel/image.rb | Writeexcel.Image.process_jpg | def process_jpg(data)
@type = 5 # Excel Blip type (MSOBLIPTYPE).
offset = 2
data_length = data.bytesize
# Search through the image data to find the 0xFFC0 marker. The height and
# width are contained in the data for that sub element.
while offset < data_length
marker = data[offset, 2].unpack("n")
marker = marker[0]
length = data[offset+2, 2].unpack("n")
length = length[0]
if marker == 0xFFC0 || marker == 0xFFC2
height = data[offset+5, 2].unpack("n")
@height = height[0]
width = data[offset+7, 2].unpack("n")
@width = width[0]
break
end
offset += length + 2
break if marker == 0xFFDA
end
raise "#{@filename}: no size data found in jpeg image.\n" unless @height
end | ruby | def process_jpg(data)
@type = 5 # Excel Blip type (MSOBLIPTYPE).
offset = 2
data_length = data.bytesize
# Search through the image data to find the 0xFFC0 marker. The height and
# width are contained in the data for that sub element.
while offset < data_length
marker = data[offset, 2].unpack("n")
marker = marker[0]
length = data[offset+2, 2].unpack("n")
length = length[0]
if marker == 0xFFC0 || marker == 0xFFC2
height = data[offset+5, 2].unpack("n")
@height = height[0]
width = data[offset+7, 2].unpack("n")
@width = width[0]
break
end
offset += length + 2
break if marker == 0xFFDA
end
raise "#{@filename}: no size data found in jpeg image.\n" unless @height
end | [
"def",
"process_jpg",
"(",
"data",
")",
"@type",
"=",
"5",
"# Excel Blip type (MSOBLIPTYPE).",
"offset",
"=",
"2",
"data_length",
"=",
"data",
".",
"bytesize",
"# Search through the image data to find the 0xFFC0 marker. The height and",
"# width are contained in the data for that sub element.",
"while",
"offset",
"<",
"data_length",
"marker",
"=",
"data",
"[",
"offset",
",",
"2",
"]",
".",
"unpack",
"(",
"\"n\"",
")",
"marker",
"=",
"marker",
"[",
"0",
"]",
"length",
"=",
"data",
"[",
"offset",
"+",
"2",
",",
"2",
"]",
".",
"unpack",
"(",
"\"n\"",
")",
"length",
"=",
"length",
"[",
"0",
"]",
"if",
"marker",
"==",
"0xFFC0",
"||",
"marker",
"==",
"0xFFC2",
"height",
"=",
"data",
"[",
"offset",
"+",
"5",
",",
"2",
"]",
".",
"unpack",
"(",
"\"n\"",
")",
"@height",
"=",
"height",
"[",
"0",
"]",
"width",
"=",
"data",
"[",
"offset",
"+",
"7",
",",
"2",
"]",
".",
"unpack",
"(",
"\"n\"",
")",
"@width",
"=",
"width",
"[",
"0",
"]",
"break",
"end",
"offset",
"+=",
"length",
"+",
"2",
"break",
"if",
"marker",
"==",
"0xFFDA",
"end",
"raise",
"\"#{@filename}: no size data found in jpeg image.\\n\"",
"unless",
"@height",
"end"
] | Extract width and height information from a JPEG file. | [
"Extract",
"width",
"and",
"height",
"information",
"from",
"a",
"JPEG",
"file",
"."
] | d0345067c21b14a7141ba66b6752be8f4be379de | https://github.com/cxn03651/writeexcel/blob/d0345067c21b14a7141ba66b6752be8f4be379de/lib/writeexcel/image.rb#L119-L146 | train |
burtlo/yard-cucumber | lib/yard/code_objects/step_transformer.rb | YARD::CodeObjects.StepTransformerObject.value | def value
unless @processed
@processed = true
until (nested = constants_from_value).empty?
nested.each {|n| @value.gsub!(value_regex(n),find_value_for_constant(n)) }
end
end
@value
end | ruby | def value
unless @processed
@processed = true
until (nested = constants_from_value).empty?
nested.each {|n| @value.gsub!(value_regex(n),find_value_for_constant(n)) }
end
end
@value
end | [
"def",
"value",
"unless",
"@processed",
"@processed",
"=",
"true",
"until",
"(",
"nested",
"=",
"constants_from_value",
")",
".",
"empty?",
"nested",
".",
"each",
"{",
"|",
"n",
"|",
"@value",
".",
"gsub!",
"(",
"value_regex",
"(",
"n",
")",
",",
"find_value_for_constant",
"(",
"n",
")",
")",
"}",
"end",
"end",
"@value",
"end"
] | When requesting a step tranformer object value, process it, if it hasn't
alredy been processed, replacing any constants that may be lurking within
the value.
Processing it means looking for any escaped characters that happen to be
CONSTANTS that could be matched and then replaced. This is done recursively
as CONSTANTS can be defined with more CONSTANTS. | [
"When",
"requesting",
"a",
"step",
"tranformer",
"object",
"value",
"process",
"it",
"if",
"it",
"hasn",
"t",
"alredy",
"been",
"processed",
"replacing",
"any",
"constants",
"that",
"may",
"be",
"lurking",
"within",
"the",
"value",
"."
] | 177e5ad17aa4973660ce646b398118a6408d8913 | https://github.com/burtlo/yard-cucumber/blob/177e5ad17aa4973660ce646b398118a6408d8913/lib/yard/code_objects/step_transformer.rb#L31-L40 | train |
burtlo/yard-cucumber | lib/yard/code_objects/step_transformer.rb | YARD::CodeObjects.StepTransformerObject.constants_from_value | def constants_from_value(data=@value)
data.scan(escape_pattern).flatten.collect { |value| value.strip }
end | ruby | def constants_from_value(data=@value)
data.scan(escape_pattern).flatten.collect { |value| value.strip }
end | [
"def",
"constants_from_value",
"(",
"data",
"=",
"@value",
")",
"data",
".",
"scan",
"(",
"escape_pattern",
")",
".",
"flatten",
".",
"collect",
"{",
"|",
"value",
"|",
"value",
".",
"strip",
"}",
"end"
] | Look through the specified data for the escape pattern and return an array
of those constants found. This defaults to the @value within step transformer
as it is used internally, however, it can be called externally if it's
needed somewhere. | [
"Look",
"through",
"the",
"specified",
"data",
"for",
"the",
"escape",
"pattern",
"and",
"return",
"an",
"array",
"of",
"those",
"constants",
"found",
".",
"This",
"defaults",
"to",
"the"
] | 177e5ad17aa4973660ce646b398118a6408d8913 | https://github.com/burtlo/yard-cucumber/blob/177e5ad17aa4973660ce646b398118a6408d8913/lib/yard/code_objects/step_transformer.rb#L68-L70 | train |
burtlo/yard-cucumber | lib/yard/code_objects/step_transformer.rb | YARD::CodeObjects.StepTransformerObject.find_value_for_constant | def find_value_for_constant(name)
constant = YARD::Registry.all(:constant).find{|c| c.name == name.to_sym }
log.warn "StepTransformer#find_value_for_constant : Could not find the CONSTANT [#{name}] using the string value." unless constant
constant ? strip_regex_from(constant.value) : name
end | ruby | def find_value_for_constant(name)
constant = YARD::Registry.all(:constant).find{|c| c.name == name.to_sym }
log.warn "StepTransformer#find_value_for_constant : Could not find the CONSTANT [#{name}] using the string value." unless constant
constant ? strip_regex_from(constant.value) : name
end | [
"def",
"find_value_for_constant",
"(",
"name",
")",
"constant",
"=",
"YARD",
"::",
"Registry",
".",
"all",
"(",
":constant",
")",
".",
"find",
"{",
"|",
"c",
"|",
"c",
".",
"name",
"==",
"name",
".",
"to_sym",
"}",
"log",
".",
"warn",
"\"StepTransformer#find_value_for_constant : Could not find the CONSTANT [#{name}] using the string value.\"",
"unless",
"constant",
"constant",
"?",
"strip_regex_from",
"(",
"constant",
".",
"value",
")",
":",
"name",
"end"
] | Looking through all the constants in the registry and returning the value
with the regex items replaced from the constnat if present | [
"Looking",
"through",
"all",
"the",
"constants",
"in",
"the",
"registry",
"and",
"returning",
"the",
"value",
"with",
"the",
"regex",
"items",
"replaced",
"from",
"the",
"constnat",
"if",
"present"
] | 177e5ad17aa4973660ce646b398118a6408d8913 | https://github.com/burtlo/yard-cucumber/blob/177e5ad17aa4973660ce646b398118a6408d8913/lib/yard/code_objects/step_transformer.rb#L78-L82 | train |
burtlo/yard-cucumber | lib/yard/parser/cucumber/feature.rb | YARD::Parser::Cucumber.FeatureParser.parse | def parse
begin
@parser.parse(@source)
@feature = @builder.ast
return nil if @feature.nil? # Nothing matched
# The parser used the following keywords when parsing the feature
# @feature.language = @parser.i18n_language.get_code_keywords.map {|word| word }
rescue Gherkin::ParserError => e
e.message.insert(0, "#{@file}: ")
warn e
end
self
end | ruby | def parse
begin
@parser.parse(@source)
@feature = @builder.ast
return nil if @feature.nil? # Nothing matched
# The parser used the following keywords when parsing the feature
# @feature.language = @parser.i18n_language.get_code_keywords.map {|word| word }
rescue Gherkin::ParserError => e
e.message.insert(0, "#{@file}: ")
warn e
end
self
end | [
"def",
"parse",
"begin",
"@parser",
".",
"parse",
"(",
"@source",
")",
"@feature",
"=",
"@builder",
".",
"ast",
"return",
"nil",
"if",
"@feature",
".",
"nil?",
"# Nothing matched",
"# The parser used the following keywords when parsing the feature",
"# @feature.language = @parser.i18n_language.get_code_keywords.map {|word| word }",
"rescue",
"Gherkin",
"::",
"ParserError",
"=>",
"e",
"e",
".",
"message",
".",
"insert",
"(",
"0",
",",
"\"#{@file}: \"",
")",
"warn",
"e",
"end",
"self",
"end"
] | Each found feature found is creates a new FeatureParser
This logic was copied from the logic found in Cucumber to create the builder
and then set up the formatter and parser. The difference is really the
custom Cucumber::Parser::CityBuilder that is being used to parse the elements
of the feature into YARD::CodeObjects.
@param [<String>] source containing the string conents of the feauture file
@param [<String>] file the filename that contains the source
When parse is called, the gherkin parser is executed and all the feature
elements that are found are sent to the various methods in the
Cucumber::Parser::CityBuilder. The result of which is the feature element
that contains all the scenarios, steps, etc. associated with that feature.
@see Cucumber::Parser::CityBuilder | [
"Each",
"found",
"feature",
"found",
"is",
"creates",
"a",
"new",
"FeatureParser"
] | 177e5ad17aa4973660ce646b398118a6408d8913 | https://github.com/burtlo/yard-cucumber/blob/177e5ad17aa4973660ce646b398118a6408d8913/lib/yard/parser/cucumber/feature.rb#L35-L50 | train |
hidroh/cucumber-api | lib/cucumber-api/response.rb | CucumberApi.Response.has | def has json_path, json=nil
if json.nil?
json = JSON.parse body
end
not JsonPath.new(json_path).on(json).empty?
end | ruby | def has json_path, json=nil
if json.nil?
json = JSON.parse body
end
not JsonPath.new(json_path).on(json).empty?
end | [
"def",
"has",
"json_path",
",",
"json",
"=",
"nil",
"if",
"json",
".",
"nil?",
"json",
"=",
"JSON",
".",
"parse",
"body",
"end",
"not",
"JsonPath",
".",
"new",
"(",
"json_path",
")",
".",
"on",
"(",
"json",
")",
".",
"empty?",
"end"
] | Check if given JSON path exists
@param json_path [String] a valid JSON path expression
@param json [String] optional JSON from which to check JSON path, default to response body
@return [true, false] true if JSON path is valid and exists, false otherwise | [
"Check",
"if",
"given",
"JSON",
"path",
"exists"
] | 8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11 | https://github.com/hidroh/cucumber-api/blob/8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11/lib/cucumber-api/response.rb#L22-L27 | train |
hidroh/cucumber-api | lib/cucumber-api/response.rb | CucumberApi.Response.get | def get json_path, json=nil
if json.nil?
json = JSON.parse body
end
results = JsonPath.new(json_path).on(json)
if results.empty?
raise %/Expected json path '#{json_path}' not found\n#{to_json_s}/
end
results.first
end | ruby | def get json_path, json=nil
if json.nil?
json = JSON.parse body
end
results = JsonPath.new(json_path).on(json)
if results.empty?
raise %/Expected json path '#{json_path}' not found\n#{to_json_s}/
end
results.first
end | [
"def",
"get",
"json_path",
",",
"json",
"=",
"nil",
"if",
"json",
".",
"nil?",
"json",
"=",
"JSON",
".",
"parse",
"body",
"end",
"results",
"=",
"JsonPath",
".",
"new",
"(",
"json_path",
")",
".",
"on",
"(",
"json",
")",
"if",
"results",
".",
"empty?",
"raise",
"%/Expected json path '#{json_path}' not found\\n#{to_json_s}/",
"end",
"results",
".",
"first",
"end"
] | Retrieve value of the first JSON element with given JSON path
@param json_path [String] a valid JSON path expression
@param json [String] optional JSON from which to apply JSON path, default to response body
@return [Object] value of first retrieved JSON element in form of Ruby object
@raise [Exception] if JSON path is invalid or no matching JSON element found | [
"Retrieve",
"value",
"of",
"the",
"first",
"JSON",
"element",
"with",
"given",
"JSON",
"path"
] | 8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11 | https://github.com/hidroh/cucumber-api/blob/8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11/lib/cucumber-api/response.rb#L34-L43 | train |
hidroh/cucumber-api | lib/cucumber-api/response.rb | CucumberApi.Response.get_as_type | def get_as_type json_path, type, json=nil
value = get json_path, json
case type
when 'numeric'
valid = value.is_a? Numeric
when 'array'
valid = value.is_a? Array
when 'string'
valid = value.is_a? String
when 'boolean'
valid = !!value == value
when 'numeric_string'
valid = value.is_a?(Numeric) or value.is_a?(String)
when 'object'
valid = value.is_a? Hash
else
raise %/Invalid expected type '#{type}'/
end
unless valid
raise %/Expect '#{json_path}' as a '#{type}' but was '#{value.class}'\n#{to_json_s}/
end
value
end | ruby | def get_as_type json_path, type, json=nil
value = get json_path, json
case type
when 'numeric'
valid = value.is_a? Numeric
when 'array'
valid = value.is_a? Array
when 'string'
valid = value.is_a? String
when 'boolean'
valid = !!value == value
when 'numeric_string'
valid = value.is_a?(Numeric) or value.is_a?(String)
when 'object'
valid = value.is_a? Hash
else
raise %/Invalid expected type '#{type}'/
end
unless valid
raise %/Expect '#{json_path}' as a '#{type}' but was '#{value.class}'\n#{to_json_s}/
end
value
end | [
"def",
"get_as_type",
"json_path",
",",
"type",
",",
"json",
"=",
"nil",
"value",
"=",
"get",
"json_path",
",",
"json",
"case",
"type",
"when",
"'numeric'",
"valid",
"=",
"value",
".",
"is_a?",
"Numeric",
"when",
"'array'",
"valid",
"=",
"value",
".",
"is_a?",
"Array",
"when",
"'string'",
"valid",
"=",
"value",
".",
"is_a?",
"String",
"when",
"'boolean'",
"valid",
"=",
"!",
"!",
"value",
"==",
"value",
"when",
"'numeric_string'",
"valid",
"=",
"value",
".",
"is_a?",
"(",
"Numeric",
")",
"or",
"value",
".",
"is_a?",
"(",
"String",
")",
"when",
"'object'",
"valid",
"=",
"value",
".",
"is_a?",
"Hash",
"else",
"raise",
"%/Invalid expected type '#{type}'/",
"end",
"unless",
"valid",
"raise",
"%/Expect '#{json_path}' as a '#{type}' but was '#{value.class}'\\n#{to_json_s}/",
"end",
"value",
"end"
] | Retrieve value of the first JSON element with given JSON path as given type
@param json_path [String] a valid JSON path expression
@param type [String] required type, possible values are 'numeric', 'array', 'string', 'boolean', 'numeric_string'
or 'object'
@param json [String] optional JSON from which to apply JSON path, default to response body
@return [Object] value of first retrieved JSON element in form of given type
@raise [Exception] if JSON path is invalid or no matching JSON element found or matching element does not match
required type | [
"Retrieve",
"value",
"of",
"the",
"first",
"JSON",
"element",
"with",
"given",
"JSON",
"path",
"as",
"given",
"type"
] | 8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11 | https://github.com/hidroh/cucumber-api/blob/8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11/lib/cucumber-api/response.rb#L53-L76 | train |
hidroh/cucumber-api | lib/cucumber-api/response.rb | CucumberApi.Response.get_as_type_or_null | def get_as_type_or_null json_path, type, json=nil
value = get json_path, json
value.nil? ? value : get_as_type(json_path, type, json)
end | ruby | def get_as_type_or_null json_path, type, json=nil
value = get json_path, json
value.nil? ? value : get_as_type(json_path, type, json)
end | [
"def",
"get_as_type_or_null",
"json_path",
",",
"type",
",",
"json",
"=",
"nil",
"value",
"=",
"get",
"json_path",
",",
"json",
"value",
".",
"nil?",
"?",
"value",
":",
"get_as_type",
"(",
"json_path",
",",
"type",
",",
"json",
")",
"end"
] | Retrieve value of the first JSON element with given JSON path as given type, with nil value allowed
@param json_path [String] a valid JSON path expression
@param type [String] required type, possible values are 'numeric', 'array', 'string', 'boolean', 'numeric_string'
or 'object'
@param json [String] optional JSON from which to apply JSON path, default to response body
@return [Object] value of first retrieved JSON element in form of given type or nil
@raise [Exception] if JSON path is invalid or no matching JSON element found or matching element does not match
required type | [
"Retrieve",
"value",
"of",
"the",
"first",
"JSON",
"element",
"with",
"given",
"JSON",
"path",
"as",
"given",
"type",
"with",
"nil",
"value",
"allowed"
] | 8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11 | https://github.com/hidroh/cucumber-api/blob/8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11/lib/cucumber-api/response.rb#L86-L89 | train |
hidroh/cucumber-api | lib/cucumber-api/response.rb | CucumberApi.Response.get_as_type_and_check_value | def get_as_type_and_check_value json_path, type, value, json=nil
v = get_as_type json_path, type, json
if value != v.to_s
raise %/Expect '#{json_path}' to be '#{value}' but was '#{v}'\n#{to_json_s}/
end
end | ruby | def get_as_type_and_check_value json_path, type, value, json=nil
v = get_as_type json_path, type, json
if value != v.to_s
raise %/Expect '#{json_path}' to be '#{value}' but was '#{v}'\n#{to_json_s}/
end
end | [
"def",
"get_as_type_and_check_value",
"json_path",
",",
"type",
",",
"value",
",",
"json",
"=",
"nil",
"v",
"=",
"get_as_type",
"json_path",
",",
"type",
",",
"json",
"if",
"value",
"!=",
"v",
".",
"to_s",
"raise",
"%/Expect '#{json_path}' to be '#{value}' but was '#{v}'\\n#{to_json_s}/",
"end",
"end"
] | Retrieve value of the first JSON element with given JSON path as given type, and check for a given value
@param json_path [String] a valid JSON path expression
@param type [String] required type, possible values are 'numeric', 'string', 'boolean', or 'numeric_string'
@param value [String] value to check for
@param json [String] optional JSON from which to apply JSON path, default to response body
@return [Object] value of first retrieved JSON element in form of given type or nil
@raise [Exception] if JSON path is invalid or no matching JSON element found or matching element does not match
required type or value | [
"Retrieve",
"value",
"of",
"the",
"first",
"JSON",
"element",
"with",
"given",
"JSON",
"path",
"as",
"given",
"type",
"and",
"check",
"for",
"a",
"given",
"value"
] | 8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11 | https://github.com/hidroh/cucumber-api/blob/8d101d166b5eb0dd2f9f6eee5019e062bc3d4f11/lib/cucumber-api/response.rb#L99-L104 | train |
square/rails-auth | lib/rails/auth/helpers.rb | Rails.Auth.authorized! | def authorized!(rack_env, allowed_by)
Env.new(rack_env).tap do |env|
env.authorize(allowed_by)
end.to_rack
end | ruby | def authorized!(rack_env, allowed_by)
Env.new(rack_env).tap do |env|
env.authorize(allowed_by)
end.to_rack
end | [
"def",
"authorized!",
"(",
"rack_env",
",",
"allowed_by",
")",
"Env",
".",
"new",
"(",
"rack_env",
")",
".",
"tap",
"do",
"|",
"env",
"|",
"env",
".",
"authorize",
"(",
"allowed_by",
")",
"end",
".",
"to_rack",
"end"
] | Mark a request as externally authorized. Causes ACL checks to be skipped.
@param [Hash] :rack_env Rack environment
@param [String] :allowed_by what allowed the request | [
"Mark",
"a",
"request",
"as",
"externally",
"authorized",
".",
"Causes",
"ACL",
"checks",
"to",
"be",
"skipped",
"."
] | 7cac4119c043f7de923f67255d1789ea70aeba5d | https://github.com/square/rails-auth/blob/7cac4119c043f7de923f67255d1789ea70aeba5d/lib/rails/auth/helpers.rb#L11-L15 | train |
square/rails-auth | lib/rails/auth/helpers.rb | Rails.Auth.set_allowed_by | def set_allowed_by(rack_env, allowed_by)
Env.new(rack_env).tap do |env|
env.allowed_by = allowed_by
end.to_rack
end | ruby | def set_allowed_by(rack_env, allowed_by)
Env.new(rack_env).tap do |env|
env.allowed_by = allowed_by
end.to_rack
end | [
"def",
"set_allowed_by",
"(",
"rack_env",
",",
"allowed_by",
")",
"Env",
".",
"new",
"(",
"rack_env",
")",
".",
"tap",
"do",
"|",
"env",
"|",
"env",
".",
"allowed_by",
"=",
"allowed_by",
"end",
".",
"to_rack",
"end"
] | Mark what authorized the request in the Rack environment
@param [Hash] :rack_env Rack environment
@param [String] :allowed_by what allowed this request | [
"Mark",
"what",
"authorized",
"the",
"request",
"in",
"the",
"Rack",
"environment"
] | 7cac4119c043f7de923f67255d1789ea70aeba5d | https://github.com/square/rails-auth/blob/7cac4119c043f7de923f67255d1789ea70aeba5d/lib/rails/auth/helpers.rb#L29-L33 | train |
square/rails-auth | lib/rails/auth/helpers.rb | Rails.Auth.add_credential | def add_credential(rack_env, type, credential)
Env.new(rack_env).tap do |env|
env.credentials[type] = credential
end.to_rack
end | ruby | def add_credential(rack_env, type, credential)
Env.new(rack_env).tap do |env|
env.credentials[type] = credential
end.to_rack
end | [
"def",
"add_credential",
"(",
"rack_env",
",",
"type",
",",
"credential",
")",
"Env",
".",
"new",
"(",
"rack_env",
")",
".",
"tap",
"do",
"|",
"env",
"|",
"env",
".",
"credentials",
"[",
"type",
"]",
"=",
"credential",
"end",
".",
"to_rack",
"end"
] | Add a credential to the Rack environment
@param [Hash] :rack_env Rack environment
@param [String] :type credential type to add to the environment
@param [Object] :credential object to add to the environment | [
"Add",
"a",
"credential",
"to",
"the",
"Rack",
"environment"
] | 7cac4119c043f7de923f67255d1789ea70aeba5d | https://github.com/square/rails-auth/blob/7cac4119c043f7de923f67255d1789ea70aeba5d/lib/rails/auth/helpers.rb#L58-L62 | train |
cristibalan/braid | lib/braid/config.rb | Braid.Config.write_db | def write_db
new_db = {}
@db.keys.sort.each do |key|
new_db[key] = {}
Braid::Mirror::ATTRIBUTES.each do |k|
new_db[key][k] = @db[key][k] if @db[key].has_key?(k)
end
end
new_data = {
'config_version' => CURRENT_CONFIG_VERSION,
'mirrors' => new_db
}
File.open(@config_file, 'wb') do |f|
f.write JSON.pretty_generate(new_data)
f.write "\n"
end
end | ruby | def write_db
new_db = {}
@db.keys.sort.each do |key|
new_db[key] = {}
Braid::Mirror::ATTRIBUTES.each do |k|
new_db[key][k] = @db[key][k] if @db[key].has_key?(k)
end
end
new_data = {
'config_version' => CURRENT_CONFIG_VERSION,
'mirrors' => new_db
}
File.open(@config_file, 'wb') do |f|
f.write JSON.pretty_generate(new_data)
f.write "\n"
end
end | [
"def",
"write_db",
"new_db",
"=",
"{",
"}",
"@db",
".",
"keys",
".",
"sort",
".",
"each",
"do",
"|",
"key",
"|",
"new_db",
"[",
"key",
"]",
"=",
"{",
"}",
"Braid",
"::",
"Mirror",
"::",
"ATTRIBUTES",
".",
"each",
"do",
"|",
"k",
"|",
"new_db",
"[",
"key",
"]",
"[",
"k",
"]",
"=",
"@db",
"[",
"key",
"]",
"[",
"k",
"]",
"if",
"@db",
"[",
"key",
"]",
".",
"has_key?",
"(",
"k",
")",
"end",
"end",
"new_data",
"=",
"{",
"'config_version'",
"=>",
"CURRENT_CONFIG_VERSION",
",",
"'mirrors'",
"=>",
"new_db",
"}",
"File",
".",
"open",
"(",
"@config_file",
",",
"'wb'",
")",
"do",
"|",
"f",
"|",
"f",
".",
"write",
"JSON",
".",
"pretty_generate",
"(",
"new_data",
")",
"f",
".",
"write",
"\"\\n\"",
"end",
"end"
] | Public for upgrade-config command only. | [
"Public",
"for",
"upgrade",
"-",
"config",
"command",
"only",
"."
] | d5eba17bb2905e75227e36858709b0a49b988b9e | https://github.com/cristibalan/braid/blob/d5eba17bb2905e75227e36858709b0a49b988b9e/lib/braid/config.rb#L194-L210 | train |
michaelherold/benchmark-memory | lib/benchmark/memory.rb | Benchmark.Memory.memory | def memory(quiet: false)
raise ConfigurationError unless block_given?
job = Job.new(quiet: quiet)
yield job
job.run
job.run_comparison
job.full_report
end | ruby | def memory(quiet: false)
raise ConfigurationError unless block_given?
job = Job.new(quiet: quiet)
yield job
job.run
job.run_comparison
job.full_report
end | [
"def",
"memory",
"(",
"quiet",
":",
"false",
")",
"raise",
"ConfigurationError",
"unless",
"block_given?",
"job",
"=",
"Job",
".",
"new",
"(",
"quiet",
":",
"quiet",
")",
"yield",
"job",
"job",
".",
"run",
"job",
".",
"run_comparison",
"job",
".",
"full_report",
"end"
] | Measure memory usage in report blocks.
@param quiet [Boolean] A flag to toggle benchmark output.
@return [Report] | [
"Measure",
"memory",
"usage",
"in",
"report",
"blocks",
"."
] | cd91f5ba81e20cbcea583f305a5b9b9d77cecdd3 | https://github.com/michaelherold/benchmark-memory/blob/cd91f5ba81e20cbcea583f305a5b9b9d77cecdd3/lib/benchmark/memory.rb#L15-L25 | train |
ryanb/populator | lib/populator/factory.rb | Populator.Factory.populate | def populate(amount, options = {}, &block)
self.class.remember_depth do
build_records(Populator.interpret_value(amount), options[:per_query] || DEFAULT_RECORDS_PER_QUERY, &block)
end
end | ruby | def populate(amount, options = {}, &block)
self.class.remember_depth do
build_records(Populator.interpret_value(amount), options[:per_query] || DEFAULT_RECORDS_PER_QUERY, &block)
end
end | [
"def",
"populate",
"(",
"amount",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"self",
".",
"class",
".",
"remember_depth",
"do",
"build_records",
"(",
"Populator",
".",
"interpret_value",
"(",
"amount",
")",
",",
"options",
"[",
":per_query",
"]",
"||",
"DEFAULT_RECORDS_PER_QUERY",
",",
"block",
")",
"end",
"end"
] | Use for_model instead of instatiating a record directly.
Entry method for building records. Delegates to build_records after remember_depth. | [
"Use",
"for_model",
"instead",
"of",
"instatiating",
"a",
"record",
"directly",
".",
"Entry",
"method",
"for",
"building",
"records",
".",
"Delegates",
"to",
"build_records",
"after",
"remember_depth",
"."
] | cd1373d8c0a89709a892db9abb2517a87646ed41 | https://github.com/ryanb/populator/blob/cd1373d8c0a89709a892db9abb2517a87646ed41/lib/populator/factory.rb#L41-L45 | train |
ryanb/populator | lib/populator/factory.rb | Populator.Factory.save_records | def save_records
unless @records.empty?
@model_class.connection.populate(@model_class.quoted_table_name, columns_sql, rows_sql_arr, "#{@model_class.name} Populate")
@last_id_in_database = @records.last.id
@records.clear
end
end | ruby | def save_records
unless @records.empty?
@model_class.connection.populate(@model_class.quoted_table_name, columns_sql, rows_sql_arr, "#{@model_class.name} Populate")
@last_id_in_database = @records.last.id
@records.clear
end
end | [
"def",
"save_records",
"unless",
"@records",
".",
"empty?",
"@model_class",
".",
"connection",
".",
"populate",
"(",
"@model_class",
".",
"quoted_table_name",
",",
"columns_sql",
",",
"rows_sql_arr",
",",
"\"#{@model_class.name} Populate\"",
")",
"@last_id_in_database",
"=",
"@records",
".",
"last",
".",
"id",
"@records",
".",
"clear",
"end",
"end"
] | Saves the records to the database by calling populate on the current database adapter. | [
"Saves",
"the",
"records",
"to",
"the",
"database",
"by",
"calling",
"populate",
"on",
"the",
"current",
"database",
"adapter",
"."
] | cd1373d8c0a89709a892db9abb2517a87646ed41 | https://github.com/ryanb/populator/blob/cd1373d8c0a89709a892db9abb2517a87646ed41/lib/populator/factory.rb#L60-L66 | train |
ryanb/populator | lib/populator/model_additions.rb | Populator.ModelAdditions.populate | def populate(amount, options = {}, &block)
Factory.for_model(self).populate(amount, options, &block)
end | ruby | def populate(amount, options = {}, &block)
Factory.for_model(self).populate(amount, options, &block)
end | [
"def",
"populate",
"(",
"amount",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"Factory",
".",
"for_model",
"(",
"self",
")",
".",
"populate",
"(",
"amount",
",",
"options",
",",
"block",
")",
"end"
] | Call populate on any ActiveRecord model to fill it with data.
Pass the number of records you want to create, and a block to
set the attributes. You can nest calls to handle associations
and use ranges or arrays to randomize the values.
Person.populate(3000) do |person|
person.name = "John Doe"
person.gender = ['male', 'female']
Project.populate(10..30, :per_query => 100) do |project|
project.person_id = person.id
project.due_at = 5.days.from_now..2.years.from_now
project.name = Populator.words(1..3).titleize
project.description = Populator.sentences(2..10)
end
end
The following options are supported.
* <tt>:per_query</tt> - limit how many records are inserted per query, defaults to 1000
Populator::Factory is where all the work happens. | [
"Call",
"populate",
"on",
"any",
"ActiveRecord",
"model",
"to",
"fill",
"it",
"with",
"data",
".",
"Pass",
"the",
"number",
"of",
"records",
"you",
"want",
"to",
"create",
"and",
"a",
"block",
"to",
"set",
"the",
"attributes",
".",
"You",
"can",
"nest",
"calls",
"to",
"handle",
"associations",
"and",
"use",
"ranges",
"or",
"arrays",
"to",
"randomize",
"the",
"values",
"."
] | cd1373d8c0a89709a892db9abb2517a87646ed41 | https://github.com/ryanb/populator/blob/cd1373d8c0a89709a892db9abb2517a87646ed41/lib/populator/model_additions.rb#L24-L26 | train |
ryanb/populator | lib/populator/random.rb | Populator.Random.value_in_range | def value_in_range(range)
case range.first
when Integer then number_in_range(range)
when Time then time_in_range(range)
when Date then date_in_range(range)
else range.to_a[rand(range.to_a.size)]
end
end | ruby | def value_in_range(range)
case range.first
when Integer then number_in_range(range)
when Time then time_in_range(range)
when Date then date_in_range(range)
else range.to_a[rand(range.to_a.size)]
end
end | [
"def",
"value_in_range",
"(",
"range",
")",
"case",
"range",
".",
"first",
"when",
"Integer",
"then",
"number_in_range",
"(",
"range",
")",
"when",
"Time",
"then",
"time_in_range",
"(",
"range",
")",
"when",
"Date",
"then",
"date_in_range",
"(",
"range",
")",
"else",
"range",
".",
"to_a",
"[",
"rand",
"(",
"range",
".",
"to_a",
".",
"size",
")",
"]",
"end",
"end"
] | Pick a random value out of a given range. | [
"Pick",
"a",
"random",
"value",
"out",
"of",
"a",
"given",
"range",
"."
] | cd1373d8c0a89709a892db9abb2517a87646ed41 | https://github.com/ryanb/populator/blob/cd1373d8c0a89709a892db9abb2517a87646ed41/lib/populator/random.rb#L8-L15 | train |
sophsec/ruby-nmap | lib/nmap/program.rb | Nmap.Program.scan | def scan(options={},exec_options={},&block)
run_task(Task.new(options,&block),exec_options)
end | ruby | def scan(options={},exec_options={},&block)
run_task(Task.new(options,&block),exec_options)
end | [
"def",
"scan",
"(",
"options",
"=",
"{",
"}",
",",
"exec_options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"run_task",
"(",
"Task",
".",
"new",
"(",
"options",
",",
"block",
")",
",",
"exec_options",
")",
"end"
] | Performs a scan.
@param [Hash{Symbol => Object}] options
Additional options for nmap.
@param [Hash{Symbol => Object}] exec_options
Additional exec-options.
@yield [task]
If a block is given, it will be passed a task object
used to specify options for nmap.
@yieldparam [Task] task
The nmap task object.
@return [Boolean]
Specifies whether the command exited normally.
@see http://rubydoc.info/gems/rprogram/0.3.0/RProgram/Program#run-instance_method
For additional exec-options. | [
"Performs",
"a",
"scan",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/program.rb#L86-L88 | train |
sophsec/ruby-nmap | lib/nmap/program.rb | Nmap.Program.sudo_scan | def sudo_scan(options={},exec_options={},&block)
sudo_task(Task.new(options,&block),exec_options)
end | ruby | def sudo_scan(options={},exec_options={},&block)
sudo_task(Task.new(options,&block),exec_options)
end | [
"def",
"sudo_scan",
"(",
"options",
"=",
"{",
"}",
",",
"exec_options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"sudo_task",
"(",
"Task",
".",
"new",
"(",
"options",
",",
"block",
")",
",",
"exec_options",
")",
"end"
] | Performs a scan and runs `nmap` under `sudo`.
@see #scan
@since 0.8.0 | [
"Performs",
"a",
"scan",
"and",
"runs",
"nmap",
"under",
"sudo",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/program.rb#L97-L99 | train |
sophsec/ruby-nmap | lib/nmap/xml.rb | Nmap.XML.scanner | def scanner
@scanner ||= Scanner.new(
@doc.root['scanner'],
@doc.root['version'],
@doc.root['args'],
Time.at(@doc.root['start'].to_i)
)
end | ruby | def scanner
@scanner ||= Scanner.new(
@doc.root['scanner'],
@doc.root['version'],
@doc.root['args'],
Time.at(@doc.root['start'].to_i)
)
end | [
"def",
"scanner",
"@scanner",
"||=",
"Scanner",
".",
"new",
"(",
"@doc",
".",
"root",
"[",
"'scanner'",
"]",
",",
"@doc",
".",
"root",
"[",
"'version'",
"]",
",",
"@doc",
".",
"root",
"[",
"'args'",
"]",
",",
"Time",
".",
"at",
"(",
"@doc",
".",
"root",
"[",
"'start'",
"]",
".",
"to_i",
")",
")",
"end"
] | Parses the scanner information.
@return [Scanner]
The scanner that was used and generated the scan file. | [
"Parses",
"the",
"scanner",
"information",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/xml.rb#L99-L106 | train |
sophsec/ruby-nmap | lib/nmap/xml.rb | Nmap.XML.scan_info | def scan_info
@doc.xpath('/nmaprun/scaninfo').map do |scaninfo|
Scan.new(
scaninfo['type'].to_sym,
scaninfo['protocol'].to_sym,
scaninfo['services'].split(',').map { |ports|
if ports.include?('-')
Range.new(*(ports.split('-',2)))
else
ports.to_i
end
}
)
end
end | ruby | def scan_info
@doc.xpath('/nmaprun/scaninfo').map do |scaninfo|
Scan.new(
scaninfo['type'].to_sym,
scaninfo['protocol'].to_sym,
scaninfo['services'].split(',').map { |ports|
if ports.include?('-')
Range.new(*(ports.split('-',2)))
else
ports.to_i
end
}
)
end
end | [
"def",
"scan_info",
"@doc",
".",
"xpath",
"(",
"'/nmaprun/scaninfo'",
")",
".",
"map",
"do",
"|",
"scaninfo",
"|",
"Scan",
".",
"new",
"(",
"scaninfo",
"[",
"'type'",
"]",
".",
"to_sym",
",",
"scaninfo",
"[",
"'protocol'",
"]",
".",
"to_sym",
",",
"scaninfo",
"[",
"'services'",
"]",
".",
"split",
"(",
"','",
")",
".",
"map",
"{",
"|",
"ports",
"|",
"if",
"ports",
".",
"include?",
"(",
"'-'",
")",
"Range",
".",
"new",
"(",
"(",
"ports",
".",
"split",
"(",
"'-'",
",",
"2",
")",
")",
")",
"else",
"ports",
".",
"to_i",
"end",
"}",
")",
"end",
"end"
] | Parses the scan information.
@return [Array<Scan>]
The scan information. | [
"Parses",
"the",
"scan",
"information",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/xml.rb#L124-L138 | train |
sophsec/ruby-nmap | lib/nmap/xml.rb | Nmap.XML.each_run_stat | def each_run_stat
return enum_for(__method__) unless block_given?
@doc.xpath('/nmaprun/runstats/finished').each do |run_stat|
yield RunStat.new(
Time.at(run_stat['time'].to_i),
run_stat['elapsed'],
run_stat['summary'],
run_stat['exit']
)
end
return self
end | ruby | def each_run_stat
return enum_for(__method__) unless block_given?
@doc.xpath('/nmaprun/runstats/finished').each do |run_stat|
yield RunStat.new(
Time.at(run_stat['time'].to_i),
run_stat['elapsed'],
run_stat['summary'],
run_stat['exit']
)
end
return self
end | [
"def",
"each_run_stat",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@doc",
".",
"xpath",
"(",
"'/nmaprun/runstats/finished'",
")",
".",
"each",
"do",
"|",
"run_stat",
"|",
"yield",
"RunStat",
".",
"new",
"(",
"Time",
".",
"at",
"(",
"run_stat",
"[",
"'time'",
"]",
".",
"to_i",
")",
",",
"run_stat",
"[",
"'elapsed'",
"]",
",",
"run_stat",
"[",
"'summary'",
"]",
",",
"run_stat",
"[",
"'exit'",
"]",
")",
"end",
"return",
"self",
"end"
] | Parses the essential runstats information.
@yield [run_stat]
The given block will be passed each runstat.
@yieldparam [RunStat] run_stat
A runstat.
@return [Enumerator]
If no block is given, an enumerator will be returned.
@since 0.7.0 | [
"Parses",
"the",
"essential",
"runstats",
"information",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/xml.rb#L154-L167 | train |
sophsec/ruby-nmap | lib/nmap/xml.rb | Nmap.XML.each_task | def each_task
return enum_for(__method__) unless block_given?
@doc.xpath('/nmaprun/taskbegin').each do |task_begin|
task_end = task_begin.xpath('following-sibling::taskend').first
yield ScanTask.new(
task_begin['task'],
Time.at(task_begin['time'].to_i),
Time.at(task_end['time'].to_i),
task_end['extrainfo']
)
end
return self
end | ruby | def each_task
return enum_for(__method__) unless block_given?
@doc.xpath('/nmaprun/taskbegin').each do |task_begin|
task_end = task_begin.xpath('following-sibling::taskend').first
yield ScanTask.new(
task_begin['task'],
Time.at(task_begin['time'].to_i),
Time.at(task_end['time'].to_i),
task_end['extrainfo']
)
end
return self
end | [
"def",
"each_task",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@doc",
".",
"xpath",
"(",
"'/nmaprun/taskbegin'",
")",
".",
"each",
"do",
"|",
"task_begin",
"|",
"task_end",
"=",
"task_begin",
".",
"xpath",
"(",
"'following-sibling::taskend'",
")",
".",
"first",
"yield",
"ScanTask",
".",
"new",
"(",
"task_begin",
"[",
"'task'",
"]",
",",
"Time",
".",
"at",
"(",
"task_begin",
"[",
"'time'",
"]",
".",
"to_i",
")",
",",
"Time",
".",
"at",
"(",
"task_end",
"[",
"'time'",
"]",
".",
"to_i",
")",
",",
"task_end",
"[",
"'extrainfo'",
"]",
")",
"end",
"return",
"self",
"end"
] | Parses the tasks of the scan.
@yield [task]
The given block will be passed each scan task.
@yieldparam [ScanTask] task
A task from the scan.
@return [Enumerator]
If no block is given, an enumerator will be returned.
@since 0.7.0 | [
"Parses",
"the",
"tasks",
"of",
"the",
"scan",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/xml.rb#L215-L230 | train |
sophsec/ruby-nmap | lib/nmap/xml.rb | Nmap.XML.each_up_host | def each_up_host
return enum_for(__method__) unless block_given?
@doc.xpath("/nmaprun/host[status[@state='up']]").each do |host|
yield Host.new(host)
end
return self
end | ruby | def each_up_host
return enum_for(__method__) unless block_given?
@doc.xpath("/nmaprun/host[status[@state='up']]").each do |host|
yield Host.new(host)
end
return self
end | [
"def",
"each_up_host",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@doc",
".",
"xpath",
"(",
"\"/nmaprun/host[status[@state='up']]\"",
")",
".",
"each",
"do",
"|",
"host",
"|",
"yield",
"Host",
".",
"new",
"(",
"host",
")",
"end",
"return",
"self",
"end"
] | Parses the hosts that were found to be up during the scan.
@yield [host]
Each host will be passed to a given block.
@yieldparam [Host] host
A host in the scan.
@return [XML, Enumerator]
The XML parser. If no block was given, an enumerator object will
be returned. | [
"Parses",
"the",
"hosts",
"that",
"were",
"found",
"to",
"be",
"up",
"during",
"the",
"scan",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/xml.rb#L381-L389 | train |
sophsec/ruby-nmap | lib/nmap/host.rb | Nmap.Host.each_address | def each_address
return enum_for(__method__) unless block_given?
@node.xpath("address[@addr]").each do |addr|
address = Address.new(
addr['addrtype'].to_sym,
addr['addr'],
addr['vendor']
)
yield address
end
return self
end | ruby | def each_address
return enum_for(__method__) unless block_given?
@node.xpath("address[@addr]").each do |addr|
address = Address.new(
addr['addrtype'].to_sym,
addr['addr'],
addr['vendor']
)
yield address
end
return self
end | [
"def",
"each_address",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"\"address[@addr]\"",
")",
".",
"each",
"do",
"|",
"addr",
"|",
"address",
"=",
"Address",
".",
"new",
"(",
"addr",
"[",
"'addrtype'",
"]",
".",
"to_sym",
",",
"addr",
"[",
"'addr'",
"]",
",",
"addr",
"[",
"'vendor'",
"]",
")",
"yield",
"address",
"end",
"return",
"self",
"end"
] | Parses each address of the host.
@yield [addr]
Each parsed address will be pass to a given block.
@yieldparam [Address] addr
A address of the host.
@return [Host, Enumerator]
The host.
If no block was given, an enumerator will be returned. | [
"Parses",
"each",
"address",
"of",
"the",
"host",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/host.rb#L90-L104 | train |
sophsec/ruby-nmap | lib/nmap/host.rb | Nmap.Host.each_hostname | def each_hostname
return enum_for(__method__) unless block_given?
@node.xpath("hostnames/hostname[@name]").each do |host|
yield Hostname.new(host['type'],host['name'])
end
return self
end | ruby | def each_hostname
return enum_for(__method__) unless block_given?
@node.xpath("hostnames/hostname[@name]").each do |host|
yield Hostname.new(host['type'],host['name'])
end
return self
end | [
"def",
"each_hostname",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"\"hostnames/hostname[@name]\"",
")",
".",
"each",
"do",
"|",
"host",
"|",
"yield",
"Hostname",
".",
"new",
"(",
"host",
"[",
"'type'",
"]",
",",
"host",
"[",
"'name'",
"]",
")",
"end",
"return",
"self",
"end"
] | Parses the hostnames of the host.
@yield [host]
Each parsed hostname will be passed to the given block.
@yieldparam [Hostname] host
A hostname of the host.
@return [Host, Enumerator]
The host.
If no block was given, an enumerator will be returned. | [
"Parses",
"the",
"hostnames",
"of",
"the",
"host",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/host.rb#L199-L207 | train |
sophsec/ruby-nmap | lib/nmap/host.rb | Nmap.Host.uptime | def uptime
@uptime ||= if (uptime = @node.at_xpath('uptime'))
Uptime.new(
uptime['seconds'].to_i,
Time.parse(uptime['lastboot'])
)
end
yield @uptime if (@uptime && block_given?)
return @uptime
end | ruby | def uptime
@uptime ||= if (uptime = @node.at_xpath('uptime'))
Uptime.new(
uptime['seconds'].to_i,
Time.parse(uptime['lastboot'])
)
end
yield @uptime if (@uptime && block_given?)
return @uptime
end | [
"def",
"uptime",
"@uptime",
"||=",
"if",
"(",
"uptime",
"=",
"@node",
".",
"at_xpath",
"(",
"'uptime'",
")",
")",
"Uptime",
".",
"new",
"(",
"uptime",
"[",
"'seconds'",
"]",
".",
"to_i",
",",
"Time",
".",
"parse",
"(",
"uptime",
"[",
"'lastboot'",
"]",
")",
")",
"end",
"yield",
"@uptime",
"if",
"(",
"@uptime",
"&&",
"block_given?",
")",
"return",
"@uptime",
"end"
] | Parses the Uptime analysis of the host.
@yield [uptime]
If a block is given, it will be passed the resulting object
@yieldparam [Uptime]
Uptime value.
@return [Uptime]
The parsed object.
@since 0.7.0 | [
"Parses",
"the",
"Uptime",
"analysis",
"of",
"the",
"host",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/host.rb#L265-L275 | train |
sophsec/ruby-nmap | lib/nmap/host.rb | Nmap.Host.each_tcp_port | def each_tcp_port
return enum_for(__method__) unless block_given?
@node.xpath("ports/port[@protocol='tcp']").each do |port|
yield Port.new(port)
end
return self
end | ruby | def each_tcp_port
return enum_for(__method__) unless block_given?
@node.xpath("ports/port[@protocol='tcp']").each do |port|
yield Port.new(port)
end
return self
end | [
"def",
"each_tcp_port",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"\"ports/port[@protocol='tcp']\"",
")",
".",
"each",
"do",
"|",
"port",
"|",
"yield",
"Port",
".",
"new",
"(",
"port",
")",
"end",
"return",
"self",
"end"
] | Parses the TCP ports of the host.
@yield [port]
Each TCP port of the host.
@yieldparam [Port] port
An TCP scanned port of the host.
@return [Host, Enumerator]
The host.
If no block was given, an enumerator will be returned. | [
"Parses",
"the",
"TCP",
"ports",
"of",
"the",
"host",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/host.rb#L446-L454 | train |
sophsec/ruby-nmap | lib/nmap/scripts.rb | Nmap.Scripts.script_data | def script_data
unless @script_data
@script_data = {}
traverse = lambda do |node|
case node.name
when 'script', 'table'
unless node.xpath('*[@key]').empty?
hash = {}
node.elements.each do |element|
hash[element['key']] = traverse.call(element)
end
hash
else
array = []
node.elements.each do |element|
array << traverse.call(element)
end
array
end
when 'elem'
node.inner_text
else
raise(NotImplementedError,"unrecognized XML NSE element: #{node}")
end
end
@node.xpath('script').each do |script|
@script_data[script['id']] = traverse.call(script)
end
end
return @script_data
end | ruby | def script_data
unless @script_data
@script_data = {}
traverse = lambda do |node|
case node.name
when 'script', 'table'
unless node.xpath('*[@key]').empty?
hash = {}
node.elements.each do |element|
hash[element['key']] = traverse.call(element)
end
hash
else
array = []
node.elements.each do |element|
array << traverse.call(element)
end
array
end
when 'elem'
node.inner_text
else
raise(NotImplementedError,"unrecognized XML NSE element: #{node}")
end
end
@node.xpath('script').each do |script|
@script_data[script['id']] = traverse.call(script)
end
end
return @script_data
end | [
"def",
"script_data",
"unless",
"@script_data",
"@script_data",
"=",
"{",
"}",
"traverse",
"=",
"lambda",
"do",
"|",
"node",
"|",
"case",
"node",
".",
"name",
"when",
"'script'",
",",
"'table'",
"unless",
"node",
".",
"xpath",
"(",
"'*[@key]'",
")",
".",
"empty?",
"hash",
"=",
"{",
"}",
"node",
".",
"elements",
".",
"each",
"do",
"|",
"element",
"|",
"hash",
"[",
"element",
"[",
"'key'",
"]",
"]",
"=",
"traverse",
".",
"call",
"(",
"element",
")",
"end",
"hash",
"else",
"array",
"=",
"[",
"]",
"node",
".",
"elements",
".",
"each",
"do",
"|",
"element",
"|",
"array",
"<<",
"traverse",
".",
"call",
"(",
"element",
")",
"end",
"array",
"end",
"when",
"'elem'",
"node",
".",
"inner_text",
"else",
"raise",
"(",
"NotImplementedError",
",",
"\"unrecognized XML NSE element: #{node}\"",
")",
"end",
"end",
"@node",
".",
"xpath",
"(",
"'script'",
")",
".",
"each",
"do",
"|",
"script",
"|",
"@script_data",
"[",
"script",
"[",
"'id'",
"]",
"]",
"=",
"traverse",
".",
"call",
"(",
"script",
")",
"end",
"end",
"return",
"@script_data",
"end"
] | The structured output of the NSE scripts.
@return [Hash{String => Hash{String => Array<String>}}]
The NSE script names and their structured output.
@since 0.9.0 | [
"The",
"structured",
"output",
"of",
"the",
"NSE",
"scripts",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/scripts.rb#L31-L68 | train |
sophsec/ruby-nmap | lib/nmap/traceroute.rb | Nmap.Traceroute.each | def each
return enum_for(__method__) unless block_given?
@node.xpath('hop').each do |hop|
yield Hop.new(hop['ipaddr'],hop['host'],hop['ttl'],hop['rtt'])
end
return self
end | ruby | def each
return enum_for(__method__) unless block_given?
@node.xpath('hop').each do |hop|
yield Hop.new(hop['ipaddr'],hop['host'],hop['ttl'],hop['rtt'])
end
return self
end | [
"def",
"each",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"'hop'",
")",
".",
"each",
"do",
"|",
"hop",
"|",
"yield",
"Hop",
".",
"new",
"(",
"hop",
"[",
"'ipaddr'",
"]",
",",
"hop",
"[",
"'host'",
"]",
",",
"hop",
"[",
"'ttl'",
"]",
",",
"hop",
"[",
"'rtt'",
"]",
")",
"end",
"return",
"self",
"end"
] | Parses the traceroute information for the host.
@yield [hop]
Each hop to the host.
@yieldparam [Hop] hop
A hop to the host.
@return [Traceroute, Enumerator]
The traceroute.
If no block was given, an enumerator will be returned. | [
"Parses",
"the",
"traceroute",
"information",
"for",
"the",
"host",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/traceroute.rb#L60-L68 | train |
sophsec/ruby-nmap | lib/nmap/os.rb | Nmap.OS.each_class | def each_class
return enum_for(__method__) unless block_given?
@node.xpath("osmatch/osclass").each do |osclass|
yield OSClass.new(osclass)
end
return self
end | ruby | def each_class
return enum_for(__method__) unless block_given?
@node.xpath("osmatch/osclass").each do |osclass|
yield OSClass.new(osclass)
end
return self
end | [
"def",
"each_class",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"\"osmatch/osclass\"",
")",
".",
"each",
"do",
"|",
"osclass",
"|",
"yield",
"OSClass",
".",
"new",
"(",
"osclass",
")",
"end",
"return",
"self",
"end"
] | Creates a new OS object.
@param [Nokogiri::XML::Node] node
The node that contains the OS guessing information.
Parses the OS class information.
@yield [class]
Passes each OS class to the given block.
@yieldparam [OSClass] class
The OS class information.
@return [OS, Enumerator]
The OS information. If no block was given, an enumerator object
will be returned. | [
"Creates",
"a",
"new",
"OS",
"object",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/os.rb#L35-L43 | train |
sophsec/ruby-nmap | lib/nmap/os.rb | Nmap.OS.each_match | def each_match
return enum_for(__method__) unless block_given?
@node.xpath("osmatch").map do |osclass|
os_match = OSMatch.new(
osclass['name'],
osclass['accuracy'].to_i
)
yield os_match
end
return self
end | ruby | def each_match
return enum_for(__method__) unless block_given?
@node.xpath("osmatch").map do |osclass|
os_match = OSMatch.new(
osclass['name'],
osclass['accuracy'].to_i
)
yield os_match
end
return self
end | [
"def",
"each_match",
"return",
"enum_for",
"(",
"__method__",
")",
"unless",
"block_given?",
"@node",
".",
"xpath",
"(",
"\"osmatch\"",
")",
".",
"map",
"do",
"|",
"osclass",
"|",
"os_match",
"=",
"OSMatch",
".",
"new",
"(",
"osclass",
"[",
"'name'",
"]",
",",
"osclass",
"[",
"'accuracy'",
"]",
".",
"to_i",
")",
"yield",
"os_match",
"end",
"return",
"self",
"end"
] | Parses the OS match information.
@yield [match]
Passes each OS match to the given block.
@yieldparam [OSMatch] class
The OS match information.
@return [OS, Enumerator]
The OS information. If no block was given, an enumerator object
will be returned. | [
"Parses",
"the",
"OS",
"match",
"information",
"."
] | f6060a7b2238872357622572145add88fc2ba412 | https://github.com/sophsec/ruby-nmap/blob/f6060a7b2238872357622572145add88fc2ba412/lib/nmap/os.rb#L68-L81 | train |
veger/ruby-bbcode | lib/ruby-bbcode/bbtree.rb | RubyBBCode.BBTree.retrogress_bbtree | def retrogress_bbtree
if @tags_list[-1].definition[:self_closable]
# It is possible that the next (self_closable) tag is on the next line
# Remove newline of current tag and parent tag as they are (probably) not intented as an actual newline here but as tag separator
@tags_list[-1][:nodes][0][:text].chomp! unless @tags_list[-1][:nodes][0][:text].nil?
@tags_list[-2][:nodes][0][:text].chomp! unless @tags_list.length < 2 or @tags_list[-2][:nodes][0][:text].nil?
end
@tags_list.pop # remove latest tag in tags_list since it's closed now...
# The parsed data manifests in @bbtree.current_node.children << TagNode.new(element) which I think is more confusing than needed
if within_open_tag?
@current_node = @tags_list[-1]
else # If we're still at the root of the BBTree or have returned back to the root via encountring closing tags...
@current_node = TagNode.new({:nodes => self.nodes}) # Note: just passing in self works too...
end
end | ruby | def retrogress_bbtree
if @tags_list[-1].definition[:self_closable]
# It is possible that the next (self_closable) tag is on the next line
# Remove newline of current tag and parent tag as they are (probably) not intented as an actual newline here but as tag separator
@tags_list[-1][:nodes][0][:text].chomp! unless @tags_list[-1][:nodes][0][:text].nil?
@tags_list[-2][:nodes][0][:text].chomp! unless @tags_list.length < 2 or @tags_list[-2][:nodes][0][:text].nil?
end
@tags_list.pop # remove latest tag in tags_list since it's closed now...
# The parsed data manifests in @bbtree.current_node.children << TagNode.new(element) which I think is more confusing than needed
if within_open_tag?
@current_node = @tags_list[-1]
else # If we're still at the root of the BBTree or have returned back to the root via encountring closing tags...
@current_node = TagNode.new({:nodes => self.nodes}) # Note: just passing in self works too...
end
end | [
"def",
"retrogress_bbtree",
"if",
"@tags_list",
"[",
"-",
"1",
"]",
".",
"definition",
"[",
":self_closable",
"]",
"# It is possible that the next (self_closable) tag is on the next line",
"# Remove newline of current tag and parent tag as they are (probably) not intented as an actual newline here but as tag separator",
"@tags_list",
"[",
"-",
"1",
"]",
"[",
":nodes",
"]",
"[",
"0",
"]",
"[",
":text",
"]",
".",
"chomp!",
"unless",
"@tags_list",
"[",
"-",
"1",
"]",
"[",
":nodes",
"]",
"[",
"0",
"]",
"[",
":text",
"]",
".",
"nil?",
"@tags_list",
"[",
"-",
"2",
"]",
"[",
":nodes",
"]",
"[",
"0",
"]",
"[",
":text",
"]",
".",
"chomp!",
"unless",
"@tags_list",
".",
"length",
"<",
"2",
"or",
"@tags_list",
"[",
"-",
"2",
"]",
"[",
":nodes",
"]",
"[",
"0",
"]",
"[",
":text",
"]",
".",
"nil?",
"end",
"@tags_list",
".",
"pop",
"# remove latest tag in tags_list since it's closed now...",
"# The parsed data manifests in @bbtree.current_node.children << TagNode.new(element) which I think is more confusing than needed",
"if",
"within_open_tag?",
"@current_node",
"=",
"@tags_list",
"[",
"-",
"1",
"]",
"else",
"# If we're still at the root of the BBTree or have returned back to the root via encountring closing tags...",
"@current_node",
"=",
"TagNode",
".",
"new",
"(",
"{",
":nodes",
"=>",
"self",
".",
"nodes",
"}",
")",
"# Note: just passing in self works too...",
"end",
"end"
] | Step down the bbtree a notch because we've reached a closing tag | [
"Step",
"down",
"the",
"bbtree",
"a",
"notch",
"because",
"we",
"ve",
"reached",
"a",
"closing",
"tag"
] | 0b9ea504060f3e5b1ae9c3e5d9586a5672ec5fc7 | https://github.com/veger/ruby-bbcode/blob/0b9ea504060f3e5b1ae9c3e5d9586a5672ec5fc7/lib/ruby-bbcode/bbtree.rb#L48-L64 | train |
veger/ruby-bbcode | lib/ruby-bbcode/tag_sifter.rb | RubyBBCode.TagSifter.get_formatted_between | def get_formatted_between
between = @ti[:text]
# perform special formatting for cenrtain tags
between = match_url_id(between, @bbtree.current_node.definition[:url_matches]) if @bbtree.current_node.definition[:url_matches]
return between
end | ruby | def get_formatted_between
between = @ti[:text]
# perform special formatting for cenrtain tags
between = match_url_id(between, @bbtree.current_node.definition[:url_matches]) if @bbtree.current_node.definition[:url_matches]
return between
end | [
"def",
"get_formatted_between",
"between",
"=",
"@ti",
"[",
":text",
"]",
"# perform special formatting for cenrtain tags",
"between",
"=",
"match_url_id",
"(",
"between",
",",
"@bbtree",
".",
"current_node",
".",
"definition",
"[",
":url_matches",
"]",
")",
"if",
"@bbtree",
".",
"current_node",
".",
"definition",
"[",
":url_matches",
"]",
"return",
"between",
"end"
] | Get 'between tag' for tag | [
"Get",
"between",
"tag",
"for",
"tag"
] | 0b9ea504060f3e5b1ae9c3e5d9586a5672ec5fc7 | https://github.com/veger/ruby-bbcode/blob/0b9ea504060f3e5b1ae9c3e5d9586a5672ec5fc7/lib/ruby-bbcode/tag_sifter.rb#L139-L144 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.up | def up(*services,
abort_on_container_exit: false,
detached: false, timeout: 10, build: false,
exit_code_from: nil,
no_build: false, no_deps: false, no_start: false)
o = opts(
abort_on_container_exit: [abort_on_container_exit, false],
d: [detached, false],
timeout: [timeout, 10],
build: [build, false],
exit_code_from: [exit_code_from, nil],
no_build: [no_build, false],
no_deps: [no_deps, false],
no_start: [no_start, false]
)
run!('up', o, services)
true
end | ruby | def up(*services,
abort_on_container_exit: false,
detached: false, timeout: 10, build: false,
exit_code_from: nil,
no_build: false, no_deps: false, no_start: false)
o = opts(
abort_on_container_exit: [abort_on_container_exit, false],
d: [detached, false],
timeout: [timeout, 10],
build: [build, false],
exit_code_from: [exit_code_from, nil],
no_build: [no_build, false],
no_deps: [no_deps, false],
no_start: [no_start, false]
)
run!('up', o, services)
true
end | [
"def",
"up",
"(",
"*",
"services",
",",
"abort_on_container_exit",
":",
"false",
",",
"detached",
":",
"false",
",",
"timeout",
":",
"10",
",",
"build",
":",
"false",
",",
"exit_code_from",
":",
"nil",
",",
"no_build",
":",
"false",
",",
"no_deps",
":",
"false",
",",
"no_start",
":",
"false",
")",
"o",
"=",
"opts",
"(",
"abort_on_container_exit",
":",
"[",
"abort_on_container_exit",
",",
"false",
"]",
",",
"d",
":",
"[",
"detached",
",",
"false",
"]",
",",
"timeout",
":",
"[",
"timeout",
",",
"10",
"]",
",",
"build",
":",
"[",
"build",
",",
"false",
"]",
",",
"exit_code_from",
":",
"[",
"exit_code_from",
",",
"nil",
"]",
",",
"no_build",
":",
"[",
"no_build",
",",
"false",
"]",
",",
"no_deps",
":",
"[",
"no_deps",
",",
"false",
"]",
",",
"no_start",
":",
"[",
"no_start",
",",
"false",
"]",
")",
"run!",
"(",
"'up'",
",",
"o",
",",
"services",
")",
"true",
"end"
] | Idempotently up the given services in the project.
@param [Array] services list of String service names to run
@param [Boolean] detached if true, to start services in the background;
otherwise, monitor logs in the foreground and shutdown on Ctrl+C
@param [Integer] timeout how long to wait for each service to start
@param [Boolean] build if true, build images before starting containers
@param [Boolean] no_build if true, don't build images, even if they're
missing
@param [Boolean] no_deps if true, just run specified services without
running the services that they depend on
@return [true] always returns true
@raise [Error] if command fails | [
"Idempotently",
"up",
"the",
"given",
"services",
"in",
"the",
"project",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L83-L100 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.scale | def scale(container_count, timeout: 10)
args = container_count.map {|service, count| "#{service}=#{count}"}
o = opts(timeout: [timeout, 10])
run!('scale', o, *args)
end | ruby | def scale(container_count, timeout: 10)
args = container_count.map {|service, count| "#{service}=#{count}"}
o = opts(timeout: [timeout, 10])
run!('scale', o, *args)
end | [
"def",
"scale",
"(",
"container_count",
",",
"timeout",
":",
"10",
")",
"args",
"=",
"container_count",
".",
"map",
"{",
"|",
"service",
",",
"count",
"|",
"\"#{service}=#{count}\"",
"}",
"o",
"=",
"opts",
"(",
"timeout",
":",
"[",
"timeout",
",",
"10",
"]",
")",
"run!",
"(",
"'scale'",
",",
"o",
",",
"args",
")",
"end"
] | Idempotently scales the number of containers for given services in the project.
@param [Hash] container_count per service, e.g. {web: 2, worker: 3}
@param [Integer] timeout how long to wait for each service to scale | [
"Idempotently",
"scales",
"the",
"number",
"of",
"containers",
"for",
"given",
"services",
"in",
"the",
"project",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L105-L109 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.run | def run(service, *cmd, detached: false, no_deps: false, volumes: [], env: [], rm: false, no_tty: false, user: nil, service_ports: false)
o = opts(d: [detached, false], no_deps: [no_deps, false], rm: [rm, false], T: [no_tty, false], u: [user, nil], service_ports: [service_ports, false])
env_params = env.map { |v| { e: v } }
volume_params = volumes.map { |v| { v: v } }
run!('run', o, *env_params, *volume_params, service, cmd)
end | ruby | def run(service, *cmd, detached: false, no_deps: false, volumes: [], env: [], rm: false, no_tty: false, user: nil, service_ports: false)
o = opts(d: [detached, false], no_deps: [no_deps, false], rm: [rm, false], T: [no_tty, false], u: [user, nil], service_ports: [service_ports, false])
env_params = env.map { |v| { e: v } }
volume_params = volumes.map { |v| { v: v } }
run!('run', o, *env_params, *volume_params, service, cmd)
end | [
"def",
"run",
"(",
"service",
",",
"*",
"cmd",
",",
"detached",
":",
"false",
",",
"no_deps",
":",
"false",
",",
"volumes",
":",
"[",
"]",
",",
"env",
":",
"[",
"]",
",",
"rm",
":",
"false",
",",
"no_tty",
":",
"false",
",",
"user",
":",
"nil",
",",
"service_ports",
":",
"false",
")",
"o",
"=",
"opts",
"(",
"d",
":",
"[",
"detached",
",",
"false",
"]",
",",
"no_deps",
":",
"[",
"no_deps",
",",
"false",
"]",
",",
"rm",
":",
"[",
"rm",
",",
"false",
"]",
",",
"T",
":",
"[",
"no_tty",
",",
"false",
"]",
",",
"u",
":",
"[",
"user",
",",
"nil",
"]",
",",
"service_ports",
":",
"[",
"service_ports",
",",
"false",
"]",
")",
"env_params",
"=",
"env",
".",
"map",
"{",
"|",
"v",
"|",
"{",
"e",
":",
"v",
"}",
"}",
"volume_params",
"=",
"volumes",
".",
"map",
"{",
"|",
"v",
"|",
"{",
"v",
":",
"v",
"}",
"}",
"run!",
"(",
"'run'",
",",
"o",
",",
"env_params",
",",
"volume_params",
",",
"service",
",",
"cmd",
")",
"end"
] | Idempotently run an arbitrary command with a service container.
@param [String] service name to run
@param [String] cmd command statement to run
@param [Boolean] detached if true, to start services in the background;
otherwise, monitor logs in the foreground and shutdown on Ctrl+C
@param [Boolean] no_deps if true, just run specified services without
running the services that they depend on
@param [Array] env a list of environment variables (see: -e flag)
@param [Array] volumes a list of volumes to bind mount (see: -v flag)
@param [Boolean] rm remove the container when done
@param [Boolean] no_tty disable pseudo-tty allocation (see: -T flag)
@param [String] user run as specified username or uid (see: -u flag)
@raise [Error] if command fails | [
"Idempotently",
"run",
"an",
"arbitrary",
"command",
"with",
"a",
"service",
"container",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L140-L145 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.stop | def stop(*services, timeout: 10)
o = opts(timeout: [timeout, 10])
run!('stop', o, services)
end | ruby | def stop(*services, timeout: 10)
o = opts(timeout: [timeout, 10])
run!('stop', o, services)
end | [
"def",
"stop",
"(",
"*",
"services",
",",
"timeout",
":",
"10",
")",
"o",
"=",
"opts",
"(",
"timeout",
":",
"[",
"timeout",
",",
"10",
"]",
")",
"run!",
"(",
"'stop'",
",",
"o",
",",
"services",
")",
"end"
] | Stop running services.
@param [Array] services list of String service names to stop
@param [Integer] timeout how long to wait for each service to stop
@raise [Error] if command fails | [
"Stop",
"running",
"services",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L168-L171 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.kill | def kill(*services, signal: 'KILL')
o = opts(signal: [signal, 'KILL'])
run!('kill', o, services)
end | ruby | def kill(*services, signal: 'KILL')
o = opts(signal: [signal, 'KILL'])
run!('kill', o, services)
end | [
"def",
"kill",
"(",
"*",
"services",
",",
"signal",
":",
"'KILL'",
")",
"o",
"=",
"opts",
"(",
"signal",
":",
"[",
"signal",
",",
"'KILL'",
"]",
")",
"run!",
"(",
"'kill'",
",",
"o",
",",
"services",
")",
"end"
] | Forcibly stop running services.
@param [Array] services list of String service names to stop
@param [String] name of murderous signal to use, default is 'KILL'
@see Signal.list for a list of acceptable signal names | [
"Forcibly",
"stop",
"running",
"services",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L177-L180 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.version | def version(short: false)
o = opts(short: [short, false])
result = run!('version', o, file: false, dir: false)
if short
result.strip
else
lines = result.split(/[\r\n]+/)
lines.inject({}) do |h, line|
kv = line.split(/: +/, 2)
h[kv.first] = kv.last
h
end
end
end | ruby | def version(short: false)
o = opts(short: [short, false])
result = run!('version', o, file: false, dir: false)
if short
result.strip
else
lines = result.split(/[\r\n]+/)
lines.inject({}) do |h, line|
kv = line.split(/: +/, 2)
h[kv.first] = kv.last
h
end
end
end | [
"def",
"version",
"(",
"short",
":",
"false",
")",
"o",
"=",
"opts",
"(",
"short",
":",
"[",
"short",
",",
"false",
"]",
")",
"result",
"=",
"run!",
"(",
"'version'",
",",
"o",
",",
"file",
":",
"false",
",",
"dir",
":",
"false",
")",
"if",
"short",
"result",
".",
"strip",
"else",
"lines",
"=",
"result",
".",
"split",
"(",
"/",
"\\r",
"\\n",
"/",
")",
"lines",
".",
"inject",
"(",
"{",
"}",
")",
"do",
"|",
"h",
",",
"line",
"|",
"kv",
"=",
"line",
".",
"split",
"(",
"/",
"/",
",",
"2",
")",
"h",
"[",
"kv",
".",
"first",
"]",
"=",
"kv",
".",
"last",
"h",
"end",
"end",
"end"
] | Determine the installed version of docker-compose.
@param [Boolean] short whether to return terse version information
@return [String, Hash] if short==true, returns a version string;
otherwise, returns a Hash of component-name strings to version strings
@raise [Error] if command fails | [
"Determine",
"the",
"installed",
"version",
"of",
"docker",
"-",
"compose",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L220-L234 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.run! | def run!(*args)
file_args = case @file
when 'docker-compose.yml'
[]
when Array
# backticks sugar can't handle array values; build a list of hashes
# IMPORTANT: preserve the order of the files so overrides work correctly
file_args = @file.map { |filepath| { :file => filepath } }
else
# a single String (or Pathname, etc); use normal sugar to add it
[{ file: @file.to_s }]
end
@shell.chdir = dir
@last_command = @shell.run('docker-compose', *file_args, *args).join
status = @last_command.status
out = @last_command.captured_output
err = @last_command.captured_error
status.success? || fail(Error.new(args.first, status, out+err))
out
end | ruby | def run!(*args)
file_args = case @file
when 'docker-compose.yml'
[]
when Array
# backticks sugar can't handle array values; build a list of hashes
# IMPORTANT: preserve the order of the files so overrides work correctly
file_args = @file.map { |filepath| { :file => filepath } }
else
# a single String (or Pathname, etc); use normal sugar to add it
[{ file: @file.to_s }]
end
@shell.chdir = dir
@last_command = @shell.run('docker-compose', *file_args, *args).join
status = @last_command.status
out = @last_command.captured_output
err = @last_command.captured_error
status.success? || fail(Error.new(args.first, status, out+err))
out
end | [
"def",
"run!",
"(",
"*",
"args",
")",
"file_args",
"=",
"case",
"@file",
"when",
"'docker-compose.yml'",
"[",
"]",
"when",
"Array",
"# backticks sugar can't handle array values; build a list of hashes",
"# IMPORTANT: preserve the order of the files so overrides work correctly",
"file_args",
"=",
"@file",
".",
"map",
"{",
"|",
"filepath",
"|",
"{",
":file",
"=>",
"filepath",
"}",
"}",
"else",
"# a single String (or Pathname, etc); use normal sugar to add it",
"[",
"{",
"file",
":",
"@file",
".",
"to_s",
"}",
"]",
"end",
"@shell",
".",
"chdir",
"=",
"dir",
"@last_command",
"=",
"@shell",
".",
"run",
"(",
"'docker-compose'",
",",
"file_args",
",",
"args",
")",
".",
"join",
"status",
"=",
"@last_command",
".",
"status",
"out",
"=",
"@last_command",
".",
"captured_output",
"err",
"=",
"@last_command",
".",
"captured_error",
"status",
".",
"success?",
"||",
"fail",
"(",
"Error",
".",
"new",
"(",
"args",
".",
"first",
",",
"status",
",",
"out",
"+",
"err",
")",
")",
"out",
"end"
] | Run a docker-compose command without validating that the CLI parameters
make sense. Prepend project and file options if suitable.
@see Docker::Compose::Shell#command
@param [Array] args command-line arguments in the format accepted by
Backticks::Runner#command
@return [String] output of the command
@raise [Error] if command fails | [
"Run",
"a",
"docker",
"-",
"compose",
"command",
"without",
"validating",
"that",
"the",
"CLI",
"parameters",
"make",
"sense",
".",
"Prepend",
"project",
"and",
"file",
"options",
"if",
"suitable",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L252-L272 | train |
xeger/docker-compose | lib/docker/compose/session.rb | Docker::Compose.Session.parse | def parse(str)
fields = []
nest = 0
field = ''
str.each_char do |ch|
got = false
if nest == 0
if ch == '('
nest += 1
end
else
if ch == '('
nest += 1
field << ch
elsif ch == ')'
nest -= 1
if nest == 0
got = true
else
field << ch
end
else
field << ch
end
end
if got
fields << field
field = ''
end
end
fields
end | ruby | def parse(str)
fields = []
nest = 0
field = ''
str.each_char do |ch|
got = false
if nest == 0
if ch == '('
nest += 1
end
else
if ch == '('
nest += 1
field << ch
elsif ch == ')'
nest -= 1
if nest == 0
got = true
else
field << ch
end
else
field << ch
end
end
if got
fields << field
field = ''
end
end
fields
end | [
"def",
"parse",
"(",
"str",
")",
"fields",
"=",
"[",
"]",
"nest",
"=",
"0",
"field",
"=",
"''",
"str",
".",
"each_char",
"do",
"|",
"ch",
"|",
"got",
"=",
"false",
"if",
"nest",
"==",
"0",
"if",
"ch",
"==",
"'('",
"nest",
"+=",
"1",
"end",
"else",
"if",
"ch",
"==",
"'('",
"nest",
"+=",
"1",
"field",
"<<",
"ch",
"elsif",
"ch",
"==",
"')'",
"nest",
"-=",
"1",
"if",
"nest",
"==",
"0",
"got",
"=",
"true",
"else",
"field",
"<<",
"ch",
"end",
"else",
"field",
"<<",
"ch",
"end",
"end",
"if",
"got",
"fields",
"<<",
"field",
"field",
"=",
"''",
"end",
"end",
"fields",
"end"
] | Parse a string that consists of a sequence of values enclosed within parentheses.
Ignore any bytes that are outside of parentheses. Values may include nested parentheses.
@param [String] str e.g. "(foo) ((bar)) ... (baz)"
@return [Array] e.g. ["foo", "bar", "baz"] | [
"Parse",
"a",
"string",
"that",
"consists",
"of",
"a",
"sequence",
"of",
"values",
"enclosed",
"within",
"parentheses",
".",
"Ignore",
"any",
"bytes",
"that",
"are",
"outside",
"of",
"parentheses",
".",
"Values",
"may",
"include",
"nested",
"parentheses",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/session.rb#L310-L343 | train |
xeger/docker-compose | lib/docker/compose/rake_tasks.rb | Docker::Compose.RakeTasks.export_env | def export_env(print:)
Docker::Compose::Mapper.map(host_env,
session: @session,
net_info: @net_info) do |k, v|
ENV[k] = serialize_for_env(v)
print_env(k, ENV[k]) if print
end
extra_host_env.each do |k, v|
ENV[k] = serialize_for_env(v)
print_env(k, ENV[k]) if print
end
end | ruby | def export_env(print:)
Docker::Compose::Mapper.map(host_env,
session: @session,
net_info: @net_info) do |k, v|
ENV[k] = serialize_for_env(v)
print_env(k, ENV[k]) if print
end
extra_host_env.each do |k, v|
ENV[k] = serialize_for_env(v)
print_env(k, ENV[k]) if print
end
end | [
"def",
"export_env",
"(",
"print",
":",
")",
"Docker",
"::",
"Compose",
"::",
"Mapper",
".",
"map",
"(",
"host_env",
",",
"session",
":",
"@session",
",",
"net_info",
":",
"@net_info",
")",
"do",
"|",
"k",
",",
"v",
"|",
"ENV",
"[",
"k",
"]",
"=",
"serialize_for_env",
"(",
"v",
")",
"print_env",
"(",
"k",
",",
"ENV",
"[",
"k",
"]",
")",
"if",
"print",
"end",
"extra_host_env",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"ENV",
"[",
"k",
"]",
"=",
"serialize_for_env",
"(",
"v",
")",
"print_env",
"(",
"k",
",",
"ENV",
"[",
"k",
"]",
")",
"if",
"print",
"end",
"end"
] | Substitute and set environment variables that point to network ports
published by docker-compose services. Optionally also print bash export
statements so this information can be made available to a user's shell. | [
"Substitute",
"and",
"set",
"environment",
"variables",
"that",
"point",
"to",
"network",
"ports",
"published",
"by",
"docker",
"-",
"compose",
"services",
".",
"Optionally",
"also",
"print",
"bash",
"export",
"statements",
"so",
"this",
"information",
"can",
"be",
"made",
"available",
"to",
"a",
"user",
"s",
"shell",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/rake_tasks.rb#L111-L123 | train |
xeger/docker-compose | lib/docker/compose/rake_tasks.rb | Docker::Compose.RakeTasks.serialize_for_env | def serialize_for_env(v)
case v
when String
v
when NilClass
nil
when Array
JSON.dump(v)
else
fail ArgumentError, "Can't represent a #{v.class} in the environment"
end
end | ruby | def serialize_for_env(v)
case v
when String
v
when NilClass
nil
when Array
JSON.dump(v)
else
fail ArgumentError, "Can't represent a #{v.class} in the environment"
end
end | [
"def",
"serialize_for_env",
"(",
"v",
")",
"case",
"v",
"when",
"String",
"v",
"when",
"NilClass",
"nil",
"when",
"Array",
"JSON",
".",
"dump",
"(",
"v",
")",
"else",
"fail",
"ArgumentError",
",",
"\"Can't represent a #{v.class} in the environment\"",
"end",
"end"
] | Transform a Ruby value into a String that can be stored in the
environment. This accepts nil, String, or Array and returns nil, String
or JSON-serialized Array. | [
"Transform",
"a",
"Ruby",
"value",
"into",
"a",
"String",
"that",
"can",
"be",
"stored",
"in",
"the",
"environment",
".",
"This",
"accepts",
"nil",
"String",
"or",
"Array",
"and",
"returns",
"nil",
"String",
"or",
"JSON",
"-",
"serialized",
"Array",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/rake_tasks.rb#L129-L140 | train |
xeger/docker-compose | lib/docker/compose/rake_tasks.rb | Docker::Compose.RakeTasks.print_env | def print_env(k, v)
if v
puts @shell_printer.export(k, v)
else
puts @shell_printer.unset(k)
end
end | ruby | def print_env(k, v)
if v
puts @shell_printer.export(k, v)
else
puts @shell_printer.unset(k)
end
end | [
"def",
"print_env",
"(",
"k",
",",
"v",
")",
"if",
"v",
"puts",
"@shell_printer",
".",
"export",
"(",
"k",
",",
"v",
")",
"else",
"puts",
"@shell_printer",
".",
"unset",
"(",
"k",
")",
"end",
"end"
] | Print an export or unset statement suitable for user's shell | [
"Print",
"an",
"export",
"or",
"unset",
"statement",
"suitable",
"for",
"user",
"s",
"shell"
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/rake_tasks.rb#L144-L150 | train |
xeger/docker-compose | lib/docker/compose/net_info.rb | Docker::Compose.NetInfo.docker_routable_ip | def docker_routable_ip
case @docker_url.scheme
when 'tcp', 'http', 'https'
docker_dns = @docker_url.host
docker_port = @docker_url.port || 2376
else
# Cheap trick: for unix, file or other protocols, assume docker ports
# are proxied to localhost in addition to other interfaces
docker_dns = 'localhost'
docker_port = 2376
end
addr = Addrinfo.getaddrinfo(
docker_dns, docker_port,
Socket::AF_INET, Socket::SOCK_STREAM).first
addr && addr.ip_address
end | ruby | def docker_routable_ip
case @docker_url.scheme
when 'tcp', 'http', 'https'
docker_dns = @docker_url.host
docker_port = @docker_url.port || 2376
else
# Cheap trick: for unix, file or other protocols, assume docker ports
# are proxied to localhost in addition to other interfaces
docker_dns = 'localhost'
docker_port = 2376
end
addr = Addrinfo.getaddrinfo(
docker_dns, docker_port,
Socket::AF_INET, Socket::SOCK_STREAM).first
addr && addr.ip_address
end | [
"def",
"docker_routable_ip",
"case",
"@docker_url",
".",
"scheme",
"when",
"'tcp'",
",",
"'http'",
",",
"'https'",
"docker_dns",
"=",
"@docker_url",
".",
"host",
"docker_port",
"=",
"@docker_url",
".",
"port",
"||",
"2376",
"else",
"# Cheap trick: for unix, file or other protocols, assume docker ports",
"# are proxied to localhost in addition to other interfaces",
"docker_dns",
"=",
"'localhost'",
"docker_port",
"=",
"2376",
"end",
"addr",
"=",
"Addrinfo",
".",
"getaddrinfo",
"(",
"docker_dns",
",",
"docker_port",
",",
"Socket",
"::",
"AF_INET",
",",
"Socket",
"::",
"SOCK_STREAM",
")",
".",
"first",
"addr",
"&&",
"addr",
".",
"ip_address",
"end"
] | Figure out the likely IP address of the host pointed to by
self.docker_url.
@return [String] host-reachable IPv4 address of docker host | [
"Figure",
"out",
"the",
"likely",
"IP",
"address",
"of",
"the",
"host",
"pointed",
"to",
"by",
"self",
".",
"docker_url",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/net_info.rb#L70-L87 | train |
xeger/docker-compose | lib/docker/compose/mapper.rb | Docker::Compose.Mapper.map | def map(value)
if value.respond_to?(:map)
value.map { |e| map_scalar(e) }
else
map_scalar(value)
end
end | ruby | def map(value)
if value.respond_to?(:map)
value.map { |e| map_scalar(e) }
else
map_scalar(value)
end
end | [
"def",
"map",
"(",
"value",
")",
"if",
"value",
".",
"respond_to?",
"(",
":map",
")",
"value",
".",
"map",
"{",
"|",
"e",
"|",
"map_scalar",
"(",
"e",
")",
"}",
"else",
"map_scalar",
"(",
"value",
")",
"end",
"end"
] | Create an instance of Mapper
@param [Docker::Compose::Session] session
@param [NetInfo] net_info
Substitute service hostnames and ports that appear in a URL or a
host:port string. If either component of a host:port string is
surrounded by square brackets, "elide" that component, removing it
from the result but using it to find the correct service and port.
@example map MySQL on local docker host with 3306 published to 13847
map("tcp://db:3306") # => "tcp://127.0.0.1:13847"
@example map just the hostname of MySQL on local docker host
map("db:[3306]") # => "127.0.0.1"
@example map just the port of MySQL on local docker host
map("[db]:3306") # => "13847"
@example map an array of database hosts
map(["[db1]:3306", "[db2]:3306"])
@param [String,#map] value a URI, host:port pair, or an array of either
@return [String,Array] the mapped value with container-names and ports substituted
@raise [BadSubstitution] if a substitution string can't be parsed
@raise [NoService] if service is not up or does not publish port | [
"Create",
"an",
"instance",
"of",
"Mapper"
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/mapper.rb#L88-L94 | train |
xeger/docker-compose | lib/docker/compose/mapper.rb | Docker::Compose.Mapper.map_scalar | def map_scalar(value)
uri = begin
URI.parse(value)
rescue
nil
end
pair = value.split(':')
if uri && uri.scheme && uri.host
# absolute URI with scheme, authority, etc
uri.host, uri.port = host_and_port(uri.host, uri.port)
return uri.to_s
elsif pair.size == 2
# "host:port" pair; three sub-cases...
if pair.first =~ ELIDED
# output only the port
service = pair.first.gsub(REMOVE_ELIDED, '')
_, port = host_and_port(service, pair.last)
return port.to_s
elsif pair.last =~ ELIDED
# output only the hostname; resolve the port anyway to ensure that
# the service is running.
service = pair.first
port = pair.last.gsub(REMOVE_ELIDED, '')
host, = host_and_port(service, port)
return host
else
# output port:hostname pair
host, port = host_and_port(pair.first, pair.last)
return "#{host}:#{port}"
end
else
fail BadSubstitution, "Can't understand '#{value}'"
end
end | ruby | def map_scalar(value)
uri = begin
URI.parse(value)
rescue
nil
end
pair = value.split(':')
if uri && uri.scheme && uri.host
# absolute URI with scheme, authority, etc
uri.host, uri.port = host_and_port(uri.host, uri.port)
return uri.to_s
elsif pair.size == 2
# "host:port" pair; three sub-cases...
if pair.first =~ ELIDED
# output only the port
service = pair.first.gsub(REMOVE_ELIDED, '')
_, port = host_and_port(service, pair.last)
return port.to_s
elsif pair.last =~ ELIDED
# output only the hostname; resolve the port anyway to ensure that
# the service is running.
service = pair.first
port = pair.last.gsub(REMOVE_ELIDED, '')
host, = host_and_port(service, port)
return host
else
# output port:hostname pair
host, port = host_and_port(pair.first, pair.last)
return "#{host}:#{port}"
end
else
fail BadSubstitution, "Can't understand '#{value}'"
end
end | [
"def",
"map_scalar",
"(",
"value",
")",
"uri",
"=",
"begin",
"URI",
".",
"parse",
"(",
"value",
")",
"rescue",
"nil",
"end",
"pair",
"=",
"value",
".",
"split",
"(",
"':'",
")",
"if",
"uri",
"&&",
"uri",
".",
"scheme",
"&&",
"uri",
".",
"host",
"# absolute URI with scheme, authority, etc",
"uri",
".",
"host",
",",
"uri",
".",
"port",
"=",
"host_and_port",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"return",
"uri",
".",
"to_s",
"elsif",
"pair",
".",
"size",
"==",
"2",
"# \"host:port\" pair; three sub-cases...",
"if",
"pair",
".",
"first",
"=~",
"ELIDED",
"# output only the port",
"service",
"=",
"pair",
".",
"first",
".",
"gsub",
"(",
"REMOVE_ELIDED",
",",
"''",
")",
"_",
",",
"port",
"=",
"host_and_port",
"(",
"service",
",",
"pair",
".",
"last",
")",
"return",
"port",
".",
"to_s",
"elsif",
"pair",
".",
"last",
"=~",
"ELIDED",
"# output only the hostname; resolve the port anyway to ensure that",
"# the service is running.",
"service",
"=",
"pair",
".",
"first",
"port",
"=",
"pair",
".",
"last",
".",
"gsub",
"(",
"REMOVE_ELIDED",
",",
"''",
")",
"host",
",",
"=",
"host_and_port",
"(",
"service",
",",
"port",
")",
"return",
"host",
"else",
"# output port:hostname pair",
"host",
",",
"port",
"=",
"host_and_port",
"(",
"pair",
".",
"first",
",",
"pair",
".",
"last",
")",
"return",
"\"#{host}:#{port}\"",
"end",
"else",
"fail",
"BadSubstitution",
",",
"\"Can't understand '#{value}'\"",
"end",
"end"
] | Map a single string, replacing service names with IPs and container ports
with the host ports that they have been mapped to.
@param [String] value
@return [String] | [
"Map",
"a",
"single",
"string",
"replacing",
"service",
"names",
"with",
"IPs",
"and",
"container",
"ports",
"with",
"the",
"host",
"ports",
"that",
"they",
"have",
"been",
"mapped",
"to",
"."
] | c1428491b686a33cbafdc26e609e6a863e2ec6fa | https://github.com/xeger/docker-compose/blob/c1428491b686a33cbafdc26e609e6a863e2ec6fa/lib/docker/compose/mapper.rb#L122-L156 | train |
sue445/rubicure | lib/rubicure/girl.rb | Rubicure.Girl.birthday? | def birthday?(date = Date.today)
return false unless have_birthday?
# NOTE: birthday is "mm/dd"
month, day = birthday.split("/")
birthday_date = Date.new(date.year, month.to_i, day.to_i)
birthday_date == date
end | ruby | def birthday?(date = Date.today)
return false unless have_birthday?
# NOTE: birthday is "mm/dd"
month, day = birthday.split("/")
birthday_date = Date.new(date.year, month.to_i, day.to_i)
birthday_date == date
end | [
"def",
"birthday?",
"(",
"date",
"=",
"Date",
".",
"today",
")",
"return",
"false",
"unless",
"have_birthday?",
"# NOTE: birthday is \"mm/dd\"",
"month",
",",
"day",
"=",
"birthday",
".",
"split",
"(",
"\"/\"",
")",
"birthday_date",
"=",
"Date",
".",
"new",
"(",
"date",
".",
"year",
",",
"month",
".",
"to_i",
",",
"day",
".",
"to_i",
")",
"birthday_date",
"==",
"date",
"end"
] | Whether `date` is her birthday
@param date [Date]
@return [Boolean]
@example
Cure.twinkle.birthday?(Date.parse("2015-9-12"))
#=> true | [
"Whether",
"date",
"is",
"her",
"birthday"
] | bdd5efc2127774a0620399e779b076d9f8f4aeab | https://github.com/sue445/rubicure/blob/bdd5efc2127774a0620399e779b076d9f8f4aeab/lib/rubicure/girl.rb#L131-L140 | train |
sue445/rubicure | lib/rubicure/core.rb | Rubicure.Core.all_stars | def all_stars(arg = Time.current)
extra_girls = []
# args is Time or Date
date = to_date(arg)
if date
last_all_stars_date = Rubicure::Movie.find(:stmm).started_date
if date > last_all_stars_date
date = last_all_stars_date
end
else
# args is movie name
movie = Rubicure::Movie.find(arg.to_sym)
date = movie.started_date
if movie.has_key?(:extra_girls)
extra_girls = movie.extra_girls.map {|girl_name| Rubicure::Girl.find(girl_name.to_sym) }
end
end
all_girls(date) - [Cure.echo] + extra_girls
end | ruby | def all_stars(arg = Time.current)
extra_girls = []
# args is Time or Date
date = to_date(arg)
if date
last_all_stars_date = Rubicure::Movie.find(:stmm).started_date
if date > last_all_stars_date
date = last_all_stars_date
end
else
# args is movie name
movie = Rubicure::Movie.find(arg.to_sym)
date = movie.started_date
if movie.has_key?(:extra_girls)
extra_girls = movie.extra_girls.map {|girl_name| Rubicure::Girl.find(girl_name.to_sym) }
end
end
all_girls(date) - [Cure.echo] + extra_girls
end | [
"def",
"all_stars",
"(",
"arg",
"=",
"Time",
".",
"current",
")",
"extra_girls",
"=",
"[",
"]",
"# args is Time or Date",
"date",
"=",
"to_date",
"(",
"arg",
")",
"if",
"date",
"last_all_stars_date",
"=",
"Rubicure",
"::",
"Movie",
".",
"find",
"(",
":stmm",
")",
".",
"started_date",
"if",
"date",
">",
"last_all_stars_date",
"date",
"=",
"last_all_stars_date",
"end",
"else",
"# args is movie name",
"movie",
"=",
"Rubicure",
"::",
"Movie",
".",
"find",
"(",
"arg",
".",
"to_sym",
")",
"date",
"=",
"movie",
".",
"started_date",
"if",
"movie",
".",
"has_key?",
"(",
":extra_girls",
")",
"extra_girls",
"=",
"movie",
".",
"extra_girls",
".",
"map",
"{",
"|",
"girl_name",
"|",
"Rubicure",
"::",
"Girl",
".",
"find",
"(",
"girl_name",
".",
"to_sym",
")",
"}",
"end",
"end",
"all_girls",
"(",
"date",
")",
"-",
"[",
"Cure",
".",
"echo",
"]",
"+",
"extra_girls",
"end"
] | Get precure all stars
@param [Time,Date,String,Symbol] arg Time, Date or date like String (ex. "2013-12-16")
@return [Array<Rubicure::Girl>]
@example precure all stars
Precure.all_stars.count
Precure.all_stars.map(&:precure_name)
# returns current precure count and names
Precure.all_stars.include?(Cure.echo)
#=> false
Precure.all_stars("2013-10-26").count
#=> 33
Precure.all_stars(:dx).count
#=> 14
Precure.all_stars(:dx2).count
#=> 17
Precure.all_stars(:dx3).count
#=> 21
Precure.all_stars(:new_stage).count
#=> 29
Precure.all_stars(:new_stage).include?(Cure.echo)
#=> true
Precure.all_stars(:new_stage2).count
#=> 32
Precure.all_stars(:new_stage3).count
#=> 37
Precure.all_stars(:new_stage3).include?(Cure.echo)
#=> true
Precure.all_stars(:spring_carnival).count
#=> 40
Precure.all_stars(:sing_together_miracle_magic).count
#=> 44
Precure.all_stars(:sing_together_miracle_magic).include?(Cure.echo)
#=> true | [
"Get",
"precure",
"all",
"stars"
] | bdd5efc2127774a0620399e779b076d9f8f4aeab | https://github.com/sue445/rubicure/blob/bdd5efc2127774a0620399e779b076d9f8f4aeab/lib/rubicure/core.rb#L98-L120 | train |
sue445/rubicure | lib/rubicure/core.rb | Rubicure.Core.all_girls | def all_girls(arg = Time.current)
date = to_date(arg)
unless @all_girls
@all_girls = []
Rubicure::Girl.names.each do |girl_name|
@all_girls << Rubicure::Girl.find(girl_name)
end
@all_girls.uniq!(&:human_name)
end
@all_girls.select {|girl| girl.created_date && girl.created_date <= date }
end | ruby | def all_girls(arg = Time.current)
date = to_date(arg)
unless @all_girls
@all_girls = []
Rubicure::Girl.names.each do |girl_name|
@all_girls << Rubicure::Girl.find(girl_name)
end
@all_girls.uniq!(&:human_name)
end
@all_girls.select {|girl| girl.created_date && girl.created_date <= date }
end | [
"def",
"all_girls",
"(",
"arg",
"=",
"Time",
".",
"current",
")",
"date",
"=",
"to_date",
"(",
"arg",
")",
"unless",
"@all_girls",
"@all_girls",
"=",
"[",
"]",
"Rubicure",
"::",
"Girl",
".",
"names",
".",
"each",
"do",
"|",
"girl_name",
"|",
"@all_girls",
"<<",
"Rubicure",
"::",
"Girl",
".",
"find",
"(",
"girl_name",
")",
"end",
"@all_girls",
".",
"uniq!",
"(",
":human_name",
")",
"end",
"@all_girls",
".",
"select",
"{",
"|",
"girl",
"|",
"girl",
".",
"created_date",
"&&",
"girl",
".",
"created_date",
"<=",
"date",
"}",
"end"
] | Get all precures
@param [Time,Date] arg Time, Date or date like String (ex. "2013-12-16")
@return [Array<Rubicure::Girl>] all precures
@example
Precure.all_girls.count
Precure.all_girls.map(&:precure_name)
# returns current precure count and names
Precure.all_girls("2013-10-26").count
#=> 33
Precure.all_girls.include?(Cure.echo)
#=> true | [
"Get",
"all",
"precures"
] | bdd5efc2127774a0620399e779b076d9f8f4aeab | https://github.com/sue445/rubicure/blob/bdd5efc2127774a0620399e779b076d9f8f4aeab/lib/rubicure/core.rb#L138-L151 | train |
sue445/rubicure | lib/rubicure/core.rb | Rubicure.Core.dream_stars | def dream_stars
return @dream_stars if @dream_stars
girls = Precure.go_princess.girls + Precure.maho_girls.girls + Precure.a_la_mode.girls
dream_stars_date = Rubicure::Movie.find(:dream_stars).started_date
@dream_stars = girls.select {|girl| girl.created_date && girl.created_date <= dream_stars_date }
@dream_stars
end | ruby | def dream_stars
return @dream_stars if @dream_stars
girls = Precure.go_princess.girls + Precure.maho_girls.girls + Precure.a_la_mode.girls
dream_stars_date = Rubicure::Movie.find(:dream_stars).started_date
@dream_stars = girls.select {|girl| girl.created_date && girl.created_date <= dream_stars_date }
@dream_stars
end | [
"def",
"dream_stars",
"return",
"@dream_stars",
"if",
"@dream_stars",
"girls",
"=",
"Precure",
".",
"go_princess",
".",
"girls",
"+",
"Precure",
".",
"maho_girls",
".",
"girls",
"+",
"Precure",
".",
"a_la_mode",
".",
"girls",
"dream_stars_date",
"=",
"Rubicure",
"::",
"Movie",
".",
"find",
"(",
":dream_stars",
")",
".",
"started_date",
"@dream_stars",
"=",
"girls",
".",
"select",
"{",
"|",
"girl",
"|",
"girl",
".",
"created_date",
"&&",
"girl",
".",
"created_date",
"<=",
"dream_stars_date",
"}",
"@dream_stars",
"end"
] | Get precure dream stars
@return [Array<Rubicure::Girl>] precure dream stars
@example
Precure.dream_stars.count
#=> 12
Precure.dream_stars.map(&:precure_name)
#=> ["キュアフローラ", "キュアマーメイド", "キュアトゥインクル", "キュアスカーレット", "キュアミラクル", "キュアマジカル", "キュアフェリーチェ", "キュアホイップ", "キュアカスタード", "キュアジェラート", "キュアマカロン", "キュアショコラ"] | [
"Get",
"precure",
"dream",
"stars"
] | bdd5efc2127774a0620399e779b076d9f8f4aeab | https://github.com/sue445/rubicure/blob/bdd5efc2127774a0620399e779b076d9f8f4aeab/lib/rubicure/core.rb#L165-L174 | train |
sue445/rubicure | lib/rubicure/core.rb | Rubicure.Core.super_stars | def super_stars
return @super_stars if @super_stars
girls = Precure.maho_girls.girls + Precure.a_la_mode.girls + Precure.hugtto.girls
super_stars_date = Rubicure::Movie.find(:super_stars).started_date
@super_stars = girls.select {|girl| girl.created_date && girl.created_date <= super_stars_date }
@super_stars
end | ruby | def super_stars
return @super_stars if @super_stars
girls = Precure.maho_girls.girls + Precure.a_la_mode.girls + Precure.hugtto.girls
super_stars_date = Rubicure::Movie.find(:super_stars).started_date
@super_stars = girls.select {|girl| girl.created_date && girl.created_date <= super_stars_date }
@super_stars
end | [
"def",
"super_stars",
"return",
"@super_stars",
"if",
"@super_stars",
"girls",
"=",
"Precure",
".",
"maho_girls",
".",
"girls",
"+",
"Precure",
".",
"a_la_mode",
".",
"girls",
"+",
"Precure",
".",
"hugtto",
".",
"girls",
"super_stars_date",
"=",
"Rubicure",
"::",
"Movie",
".",
"find",
"(",
":super_stars",
")",
".",
"started_date",
"@super_stars",
"=",
"girls",
".",
"select",
"{",
"|",
"girl",
"|",
"girl",
".",
"created_date",
"&&",
"girl",
".",
"created_date",
"<=",
"super_stars_date",
"}",
"@super_stars",
"end"
] | Get precure super stars
@return [Array<Rubicure::Girl>] precure super stars
@example
Precure.super_stars.count
#=> 12
Precure.super_stars.map(&:precure_name)
#=> ["キュアミラクル", "キュアマジカル", "キュアフェリーチェ", "キュアホイップ", "キュアカスタード", "キュアジェラート", "キュアマカロン", "キュアショコラ", "キュアパルフェ", "キュアエール", "キュアアンジュ", "キュアエトワール"] | [
"Get",
"precure",
"super",
"stars"
] | bdd5efc2127774a0620399e779b076d9f8f4aeab | https://github.com/sue445/rubicure/blob/bdd5efc2127774a0620399e779b076d9f8f4aeab/lib/rubicure/core.rb#L186-L195 | train |
pinnymz/migration_comments | lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb | MigrationComments::ActiveRecord::ConnectionAdapters.PostgreSQLAdapter.set_column_comment | def set_column_comment(table_name, column_name, comment_text)
execute comment_sql(CommentDefinition.new(table_name, column_name, comment_text))
end | ruby | def set_column_comment(table_name, column_name, comment_text)
execute comment_sql(CommentDefinition.new(table_name, column_name, comment_text))
end | [
"def",
"set_column_comment",
"(",
"table_name",
",",
"column_name",
",",
"comment_text",
")",
"execute",
"comment_sql",
"(",
"CommentDefinition",
".",
"new",
"(",
"table_name",
",",
"column_name",
",",
"comment_text",
")",
")",
"end"
] | Set a comment on a column | [
"Set",
"a",
"comment",
"on",
"a",
"column"
] | 2b62e5291deb982a5034052504fdf30cb20450bc | https://github.com/pinnymz/migration_comments/blob/2b62e5291deb982a5034052504fdf30cb20450bc/lib/migration_comments/active_record/connection_adapters/postgresql_adapter.rb#L18-L20 | train |
microformats/microformats-ruby | lib/microformats/format_parser.rb | Microformats.FormatParser.imply_dates | def imply_dates
return unless !@properties['end'].nil? && !@properties['start'].nil?
start_date = nil
@properties['start'].each do |start_val|
if start_val =~ /^(\d{4}-[01]\d-[0-3]\d)/
start_date = Regexp.last_match(1) if start_date.nil?
elsif start_val =~ /^(\d{4}-[0-3]\d\d)/
start_date = Regexp.last_match(1) if start_date.nil?
end
end
unless start_date.nil?
@properties['end'].map! do |end_val|
if end_val.match?(/^\d{4}-[01]\d-[0-3]\d/)
end_val
elsif end_val.match?(/^\d{4}-[0-3]\d\d/)
end_val
else
start_date + ' ' + end_val
end
end
end
end | ruby | def imply_dates
return unless !@properties['end'].nil? && !@properties['start'].nil?
start_date = nil
@properties['start'].each do |start_val|
if start_val =~ /^(\d{4}-[01]\d-[0-3]\d)/
start_date = Regexp.last_match(1) if start_date.nil?
elsif start_val =~ /^(\d{4}-[0-3]\d\d)/
start_date = Regexp.last_match(1) if start_date.nil?
end
end
unless start_date.nil?
@properties['end'].map! do |end_val|
if end_val.match?(/^\d{4}-[01]\d-[0-3]\d/)
end_val
elsif end_val.match?(/^\d{4}-[0-3]\d\d/)
end_val
else
start_date + ' ' + end_val
end
end
end
end | [
"def",
"imply_dates",
"return",
"unless",
"!",
"@properties",
"[",
"'end'",
"]",
".",
"nil?",
"&&",
"!",
"@properties",
"[",
"'start'",
"]",
".",
"nil?",
"start_date",
"=",
"nil",
"@properties",
"[",
"'start'",
"]",
".",
"each",
"do",
"|",
"start_val",
"|",
"if",
"start_val",
"=~",
"/",
"\\d",
"\\d",
"\\d",
"/",
"start_date",
"=",
"Regexp",
".",
"last_match",
"(",
"1",
")",
"if",
"start_date",
".",
"nil?",
"elsif",
"start_val",
"=~",
"/",
"\\d",
"\\d",
"\\d",
"/",
"start_date",
"=",
"Regexp",
".",
"last_match",
"(",
"1",
")",
"if",
"start_date",
".",
"nil?",
"end",
"end",
"unless",
"start_date",
".",
"nil?",
"@properties",
"[",
"'end'",
"]",
".",
"map!",
"do",
"|",
"end_val",
"|",
"if",
"end_val",
".",
"match?",
"(",
"/",
"\\d",
"\\d",
"\\d",
"/",
")",
"end_val",
"elsif",
"end_val",
".",
"match?",
"(",
"/",
"\\d",
"\\d",
"\\d",
"/",
")",
"end_val",
"else",
"start_date",
"+",
"' '",
"+",
"end_val",
"end",
"end",
"end",
"end"
] | imply date for dt-end if dt-start is defined with a date | [
"imply",
"date",
"for",
"dt",
"-",
"end",
"if",
"dt",
"-",
"start",
"is",
"defined",
"with",
"a",
"date"
] | d0841b2489ce7bf6fbae03d3e3aa1ecfbf56e98b | https://github.com/microformats/microformats-ruby/blob/d0841b2489ce7bf6fbae03d3e3aa1ecfbf56e98b/lib/microformats/format_parser.rb#L323-L347 | train |
justindomingue/markov_chains | lib/markov_chains/generator.rb | MarkovChains.Generator.get_sentences | def get_sentences(n)
sentences = []
n.times do
sentence = @dict.get_start_words
while nw = @dict.get(sentence[[email protected], @dict.order])
sentence << nw
end
sentences << (sentence[0...-1].join(" ").gsub(/\s([,;:])/, '\1') << sentence.last)
end
sentences
end | ruby | def get_sentences(n)
sentences = []
n.times do
sentence = @dict.get_start_words
while nw = @dict.get(sentence[[email protected], @dict.order])
sentence << nw
end
sentences << (sentence[0...-1].join(" ").gsub(/\s([,;:])/, '\1') << sentence.last)
end
sentences
end | [
"def",
"get_sentences",
"(",
"n",
")",
"sentences",
"=",
"[",
"]",
"n",
".",
"times",
"do",
"sentence",
"=",
"@dict",
".",
"get_start_words",
"while",
"nw",
"=",
"@dict",
".",
"get",
"(",
"sentence",
"[",
"-",
"@dict",
".",
"order",
",",
"@dict",
".",
"order",
"]",
")",
"sentence",
"<<",
"nw",
"end",
"sentences",
"<<",
"(",
"sentence",
"[",
"0",
"...",
"-",
"1",
"]",
".",
"join",
"(",
"\" \"",
")",
".",
"gsub",
"(",
"/",
"\\s",
"/",
",",
"'\\1'",
")",
"<<",
"sentence",
".",
"last",
")",
"end",
"sentences",
"end"
] | Initializes the generator
@example Create a new generator
MarkovChains::Generator.new(text)
@param Text source to generate sentences from
Returns a given number of randonly generated sentences
@example Get 5 sentences
get_sentences(5)
@param n [int] number of sentences to generate
@return Array conataining generated sentences | [
"Initializes",
"the",
"generator"
] | cc94beb2ad17bea13db6cb9dacaa5bf23e7274e8 | https://github.com/justindomingue/markov_chains/blob/cc94beb2ad17bea13db6cb9dacaa5bf23e7274e8/lib/markov_chains/generator.rb#L23-L37 | train |
codez/dry_crud | app/controllers/dry_crud/nestable.rb | DryCrud.Nestable.parents | def parents
@parents ||= Array(nesting).map do |p|
if p.is_a?(Class) && p < ActiveRecord::Base
parent_entry(p)
else
p
end
end
end | ruby | def parents
@parents ||= Array(nesting).map do |p|
if p.is_a?(Class) && p < ActiveRecord::Base
parent_entry(p)
else
p
end
end
end | [
"def",
"parents",
"@parents",
"||=",
"Array",
"(",
"nesting",
")",
".",
"map",
"do",
"|",
"p",
"|",
"if",
"p",
".",
"is_a?",
"(",
"Class",
")",
"&&",
"p",
"<",
"ActiveRecord",
"::",
"Base",
"parent_entry",
"(",
"p",
")",
"else",
"p",
"end",
"end",
"end"
] | Returns the parent entries of the current request, if any.
These are ActiveRecords or namespace symbols, corresponding
to the defined nesting attribute. | [
"Returns",
"the",
"parent",
"entries",
"of",
"the",
"current",
"request",
"if",
"any",
".",
"These",
"are",
"ActiveRecords",
"or",
"namespace",
"symbols",
"corresponding",
"to",
"the",
"defined",
"nesting",
"attribute",
"."
] | 2d034b25fe3fc2a096c602f59a29fe7be152b050 | https://github.com/codez/dry_crud/blob/2d034b25fe3fc2a096c602f59a29fe7be152b050/app/controllers/dry_crud/nestable.rb#L30-L38 | train |
nccgroup/BinProxy | lib/binproxy/proxy_message.rb | BinProxy.ProxyMessage.headers | def headers
super.merge({
size: @raw.length,
# HACK - this will prevent errors, but will mangle anything that isn't
# actually utf8. We should try to handle this upstream where we might
# know what the actual encoding is.
summary: @message.summary.force_encoding('UTF-8').scrub,
message_class: @message_class.to_s,
})
end | ruby | def headers
super.merge({
size: @raw.length,
# HACK - this will prevent errors, but will mangle anything that isn't
# actually utf8. We should try to handle this upstream where we might
# know what the actual encoding is.
summary: @message.summary.force_encoding('UTF-8').scrub,
message_class: @message_class.to_s,
})
end | [
"def",
"headers",
"super",
".",
"merge",
"(",
"{",
"size",
":",
"@raw",
".",
"length",
",",
"# HACK - this will prevent errors, but will mangle anything that isn't",
"# actually utf8. We should try to handle this upstream where we might",
"# know what the actual encoding is.",
"summary",
":",
"@message",
".",
"summary",
".",
"force_encoding",
"(",
"'UTF-8'",
")",
".",
"scrub",
",",
"message_class",
":",
"@message_class",
".",
"to_s",
",",
"}",
")",
"end"
] | The next two methods are the last stop before JSON encoding, so all strings
in the returned hash must be UTF-8 compatible. | [
"The",
"next",
"two",
"methods",
"are",
"the",
"last",
"stop",
"before",
"JSON",
"encoding",
"so",
"all",
"strings",
"in",
"the",
"returned",
"hash",
"must",
"be",
"UTF",
"-",
"8",
"compatible",
"."
] | d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27 | https://github.com/nccgroup/BinProxy/blob/d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27/lib/binproxy/proxy_message.rb#L106-L115 | train |
nccgroup/BinProxy | lib/binproxy/parser.rb | BinProxy.Parser.parse | def parse(raw_buffer, peer)
start_pos = nil
loop do
break if raw_buffer.eof?
start_pos = raw_buffer.pos
log.debug "at #{start_pos} of #{raw_buffer.length} in buffer"
read_fn = lambda { message_class.new(src: peer.to_s, protocol_state: @protocol_state).read(raw_buffer) }
message = if log.debug?
BinData::trace_reading &read_fn
else
read_fn.call
end
bytes_read = raw_buffer.pos - start_pos
log.debug "read #{bytes_read} bytes"
# Go back and grab raw bytes for validation of serialization
raw_buffer.pos = start_pos
raw_m = raw_buffer.read bytes_read
@protocol_state = message.update_state
log.debug "protocol state is now #{@protocol_state.inspect}"
pm = ProxyMessage.new(raw_m, message)
pm.src = peer
yield pm
end
rescue EOFError, IOError
log.info "Hit end of buffer while parsing. Consumed #{raw_buffer.pos - start_pos} bytes."
raw_buffer.pos = start_pos #rewind partial read
#todo, warn to client if validate flag set?
rescue Exception => e
log.err_trace(e, 'parsing message (probably an issue with user BinData class)', ::Logger::WARN)
self.class.proxy.on_bindata_error('parsing', e)
end | ruby | def parse(raw_buffer, peer)
start_pos = nil
loop do
break if raw_buffer.eof?
start_pos = raw_buffer.pos
log.debug "at #{start_pos} of #{raw_buffer.length} in buffer"
read_fn = lambda { message_class.new(src: peer.to_s, protocol_state: @protocol_state).read(raw_buffer) }
message = if log.debug?
BinData::trace_reading &read_fn
else
read_fn.call
end
bytes_read = raw_buffer.pos - start_pos
log.debug "read #{bytes_read} bytes"
# Go back and grab raw bytes for validation of serialization
raw_buffer.pos = start_pos
raw_m = raw_buffer.read bytes_read
@protocol_state = message.update_state
log.debug "protocol state is now #{@protocol_state.inspect}"
pm = ProxyMessage.new(raw_m, message)
pm.src = peer
yield pm
end
rescue EOFError, IOError
log.info "Hit end of buffer while parsing. Consumed #{raw_buffer.pos - start_pos} bytes."
raw_buffer.pos = start_pos #rewind partial read
#todo, warn to client if validate flag set?
rescue Exception => e
log.err_trace(e, 'parsing message (probably an issue with user BinData class)', ::Logger::WARN)
self.class.proxy.on_bindata_error('parsing', e)
end | [
"def",
"parse",
"(",
"raw_buffer",
",",
"peer",
")",
"start_pos",
"=",
"nil",
"loop",
"do",
"break",
"if",
"raw_buffer",
".",
"eof?",
"start_pos",
"=",
"raw_buffer",
".",
"pos",
"log",
".",
"debug",
"\"at #{start_pos} of #{raw_buffer.length} in buffer\"",
"read_fn",
"=",
"lambda",
"{",
"message_class",
".",
"new",
"(",
"src",
":",
"peer",
".",
"to_s",
",",
"protocol_state",
":",
"@protocol_state",
")",
".",
"read",
"(",
"raw_buffer",
")",
"}",
"message",
"=",
"if",
"log",
".",
"debug?",
"BinData",
"::",
"trace_reading",
"read_fn",
"else",
"read_fn",
".",
"call",
"end",
"bytes_read",
"=",
"raw_buffer",
".",
"pos",
"-",
"start_pos",
"log",
".",
"debug",
"\"read #{bytes_read} bytes\"",
"# Go back and grab raw bytes for validation of serialization",
"raw_buffer",
".",
"pos",
"=",
"start_pos",
"raw_m",
"=",
"raw_buffer",
".",
"read",
"bytes_read",
"@protocol_state",
"=",
"message",
".",
"update_state",
"log",
".",
"debug",
"\"protocol state is now #{@protocol_state.inspect}\"",
"pm",
"=",
"ProxyMessage",
".",
"new",
"(",
"raw_m",
",",
"message",
")",
"pm",
".",
"src",
"=",
"peer",
"yield",
"pm",
"end",
"rescue",
"EOFError",
",",
"IOError",
"log",
".",
"info",
"\"Hit end of buffer while parsing. Consumed #{raw_buffer.pos - start_pos} bytes.\"",
"raw_buffer",
".",
"pos",
"=",
"start_pos",
"#rewind partial read",
"#todo, warn to client if validate flag set?",
"rescue",
"Exception",
"=>",
"e",
"log",
".",
"err_trace",
"(",
"e",
",",
"'parsing message (probably an issue with user BinData class)'",
",",
"::",
"Logger",
"::",
"WARN",
")",
"self",
".",
"class",
".",
"proxy",
".",
"on_bindata_error",
"(",
"'parsing'",
",",
"e",
")",
"end"
] | Try to parse one or more messages from the buffer, and yield them | [
"Try",
"to",
"parse",
"one",
"or",
"more",
"messages",
"from",
"the",
"buffer",
"and",
"yield",
"them"
] | d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27 | https://github.com/nccgroup/BinProxy/blob/d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27/lib/binproxy/parser.rb#L36-L74 | train |
nccgroup/BinProxy | lib/binproxy/connection.rb | BinProxy.Connection.connect | def connect(host=nil, port=nil, &cb)
host ||= opts[:upstream_host] || raise('no upstream host')
port ||= opts[:upstream_port] || raise('no upstream port')
cb ||= lambda { |conn| opts[:session_callback].call(self, conn) }
log.debug "Making upstream connection to #{host}:#{port}"
EM.connect(host, port, Connection, opts[:upstream_args], &cb)
end | ruby | def connect(host=nil, port=nil, &cb)
host ||= opts[:upstream_host] || raise('no upstream host')
port ||= opts[:upstream_port] || raise('no upstream port')
cb ||= lambda { |conn| opts[:session_callback].call(self, conn) }
log.debug "Making upstream connection to #{host}:#{port}"
EM.connect(host, port, Connection, opts[:upstream_args], &cb)
end | [
"def",
"connect",
"(",
"host",
"=",
"nil",
",",
"port",
"=",
"nil",
",",
"&",
"cb",
")",
"host",
"||=",
"opts",
"[",
":upstream_host",
"]",
"||",
"raise",
"(",
"'no upstream host'",
")",
"port",
"||=",
"opts",
"[",
":upstream_port",
"]",
"||",
"raise",
"(",
"'no upstream port'",
")",
"cb",
"||=",
"lambda",
"{",
"|",
"conn",
"|",
"opts",
"[",
":session_callback",
"]",
".",
"call",
"(",
"self",
",",
"conn",
")",
"}",
"log",
".",
"debug",
"\"Making upstream connection to #{host}:#{port}\"",
"EM",
".",
"connect",
"(",
"host",
",",
"port",
",",
"Connection",
",",
"opts",
"[",
":upstream_args",
"]",
",",
"cb",
")",
"end"
] | Used by filters to initiate upstream connection in response to
inbound connection | [
"Used",
"by",
"filters",
"to",
"initiate",
"upstream",
"connection",
"in",
"response",
"to",
"inbound",
"connection"
] | d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27 | https://github.com/nccgroup/BinProxy/blob/d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27/lib/binproxy/connection.rb#L37-L43 | train |
nccgroup/BinProxy | lib/binproxy/connection.rb | BinProxy.Connection.send_message | def send_message(pm)
log.error "OOPS! message going the wrong way (to #{peer})" if pm.dest != peer
data = pm.to_binary_s
@filters.each do |f|
data = f.write data
return if data.nil? or data == ''
end
send_data(data)
end | ruby | def send_message(pm)
log.error "OOPS! message going the wrong way (to #{peer})" if pm.dest != peer
data = pm.to_binary_s
@filters.each do |f|
data = f.write data
return if data.nil? or data == ''
end
send_data(data)
end | [
"def",
"send_message",
"(",
"pm",
")",
"log",
".",
"error",
"\"OOPS! message going the wrong way (to #{peer})\"",
"if",
"pm",
".",
"dest",
"!=",
"peer",
"data",
"=",
"pm",
".",
"to_binary_s",
"@filters",
".",
"each",
"do",
"|",
"f",
"|",
"data",
"=",
"f",
".",
"write",
"data",
"return",
"if",
"data",
".",
"nil?",
"or",
"data",
"==",
"''",
"end",
"send_data",
"(",
"data",
")",
"end"
] | called with a ProxyMessage | [
"called",
"with",
"a",
"ProxyMessage"
] | d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27 | https://github.com/nccgroup/BinProxy/blob/d02fce91a1bd5aa0bd4b99a6f60f65ddc9d33c27/lib/binproxy/connection.rb#L84-L93 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.