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 |
---|---|---|---|---|---|---|---|---|---|---|---|
randym/axlsx | lib/axlsx/workbook/worksheet/row.rb | Axlsx.Row.add_cell | def add_cell(value = '', options = {})
c = Cell.new(self, value, options)
self << c
worksheet.send(:update_column_info, self, [])
c
end | ruby | def add_cell(value = '', options = {})
c = Cell.new(self, value, options)
self << c
worksheet.send(:update_column_info, self, [])
c
end | [
"def",
"add_cell",
"(",
"value",
"=",
"''",
",",
"options",
"=",
"{",
"}",
")",
"c",
"=",
"Cell",
".",
"new",
"(",
"self",
",",
"value",
",",
"options",
")",
"self",
"<<",
"c",
"worksheet",
".",
"send",
"(",
":update_column_info",
",",
"self",
",",
"[",
"]",
")",
"c",
"end"
] | Adds a single cell to the row based on the data provided and updates the worksheet's autofit data.
@return [Cell] | [
"Adds",
"a",
"single",
"cell",
"to",
"the",
"row",
"based",
"on",
"the",
"data",
"provided",
"and",
"updates",
"the",
"worksheet",
"s",
"autofit",
"data",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/row.rb#L99-L104 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/row.rb | Axlsx.Row.color= | def color=(color)
each_with_index do | cell, index |
cell.color = color.is_a?(Array) ? color[index] : color
end
end | ruby | def color=(color)
each_with_index do | cell, index |
cell.color = color.is_a?(Array) ? color[index] : color
end
end | [
"def",
"color",
"=",
"(",
"color",
")",
"each_with_index",
"do",
"|",
"cell",
",",
"index",
"|",
"cell",
".",
"color",
"=",
"color",
".",
"is_a?",
"(",
"Array",
")",
"?",
"color",
"[",
"index",
"]",
":",
"color",
"end",
"end"
] | sets the color for every cell in this row | [
"sets",
"the",
"color",
"for",
"every",
"cell",
"in",
"this",
"row"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/row.rb#L107-L111 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/row.rb | Axlsx.Row.style= | def style=(style)
each_with_index do | cell, index |
cell.style = style.is_a?(Array) ? style[index] : style
end
end | ruby | def style=(style)
each_with_index do | cell, index |
cell.style = style.is_a?(Array) ? style[index] : style
end
end | [
"def",
"style",
"=",
"(",
"style",
")",
"each_with_index",
"do",
"|",
"cell",
",",
"index",
"|",
"cell",
".",
"style",
"=",
"style",
".",
"is_a?",
"(",
"Array",
")",
"?",
"style",
"[",
"index",
"]",
":",
"style",
"end",
"end"
] | sets the style for every cell in this row | [
"sets",
"the",
"style",
"for",
"every",
"cell",
"in",
"this",
"row"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/row.rb#L114-L118 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/row.rb | Axlsx.Row.array_to_cells | def array_to_cells(values, options={})
DataTypeValidator.validate :array_to_cells, Array, values
types, style, formula_values = options.delete(:types), options.delete(:style), options.delete(:formula_values)
values.each_with_index do |value, index|
options[:style] = style.is_a?(Array) ? style[index] : style if style
options[:type] = types.is_a?(Array) ? types[index] : types if types
options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
self[index] = Cell.new(self, value, options)
end
end | ruby | def array_to_cells(values, options={})
DataTypeValidator.validate :array_to_cells, Array, values
types, style, formula_values = options.delete(:types), options.delete(:style), options.delete(:formula_values)
values.each_with_index do |value, index|
options[:style] = style.is_a?(Array) ? style[index] : style if style
options[:type] = types.is_a?(Array) ? types[index] : types if types
options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
self[index] = Cell.new(self, value, options)
end
end | [
"def",
"array_to_cells",
"(",
"values",
",",
"options",
"=",
"{",
"}",
")",
"DataTypeValidator",
".",
"validate",
":array_to_cells",
",",
"Array",
",",
"values",
"types",
",",
"style",
",",
"formula_values",
"=",
"options",
".",
"delete",
"(",
":types",
")",
",",
"options",
".",
"delete",
"(",
":style",
")",
",",
"options",
".",
"delete",
"(",
":formula_values",
")",
"values",
".",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"options",
"[",
":style",
"]",
"=",
"style",
".",
"is_a?",
"(",
"Array",
")",
"?",
"style",
"[",
"index",
"]",
":",
"style",
"if",
"style",
"options",
"[",
":type",
"]",
"=",
"types",
".",
"is_a?",
"(",
"Array",
")",
"?",
"types",
"[",
"index",
"]",
":",
"types",
"if",
"types",
"options",
"[",
":formula_value",
"]",
"=",
"formula_values",
"[",
"index",
"]",
"if",
"formula_values",
".",
"is_a?",
"(",
"Array",
")",
"self",
"[",
"index",
"]",
"=",
"Cell",
".",
"new",
"(",
"self",
",",
"value",
",",
"options",
")",
"end",
"end"
] | Converts values, types, and style options into cells and associates them with this row.
A new cell is created for each item in the values array.
If value option is defined and is a symbol it is applied to all the cells created.
If the value option is an array, cell types are applied by index for each cell
If the style option is defined and is an Integer, it is applied to all cells created.
If the style option is an array, style is applied by index for each cell.
@option options [Array] values
@option options [Array, Symbol] types
@option options [Array, Integer] style | [
"Converts",
"values",
"types",
"and",
"style",
"options",
"into",
"cells",
"and",
"associates",
"them",
"with",
"this",
"row",
".",
"A",
"new",
"cell",
"is",
"created",
"for",
"each",
"item",
"in",
"the",
"values",
"array",
".",
"If",
"value",
"option",
"is",
"defined",
"and",
"is",
"a",
"symbol",
"it",
"is",
"applied",
"to",
"all",
"the",
"cells",
"created",
".",
"If",
"the",
"value",
"option",
"is",
"an",
"array",
"cell",
"types",
"are",
"applied",
"by",
"index",
"for",
"each",
"cell",
"If",
"the",
"style",
"option",
"is",
"defined",
"and",
"is",
"an",
"Integer",
"it",
"is",
"applied",
"to",
"all",
"cells",
"created",
".",
"If",
"the",
"style",
"option",
"is",
"an",
"array",
"style",
"is",
"applied",
"by",
"index",
"for",
"each",
"cell",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/row.rb#L148-L158 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.add_image | def add_image(options={})
if options[:end_at]
TwoCellAnchor.new(self, options).add_pic(options)
else
OneCellAnchor.new(self, options)
end
@anchors.last.object
end | ruby | def add_image(options={})
if options[:end_at]
TwoCellAnchor.new(self, options).add_pic(options)
else
OneCellAnchor.new(self, options)
end
@anchors.last.object
end | [
"def",
"add_image",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"options",
"[",
":end_at",
"]",
"TwoCellAnchor",
".",
"new",
"(",
"self",
",",
"options",
")",
".",
"add_pic",
"(",
"options",
")",
"else",
"OneCellAnchor",
".",
"new",
"(",
"self",
",",
"options",
")",
"end",
"@anchors",
".",
"last",
".",
"object",
"end"
] | Creates a new Drawing object
@param [Worksheet] worksheet The worksheet that owns this drawing
Adds an image to the chart If th end_at option is specified we create a two cell anchor. By default we use a one cell anchor.
@note The recommended way to manage images is to use Worksheet.add_image. Please refer to that method for documentation.
@see Worksheet#add_image
@return [Pic] | [
"Creates",
"a",
"new",
"Drawing",
"object"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L85-L92 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.add_chart | def add_chart(chart_type, options={})
TwoCellAnchor.new(self, options)
@anchors.last.add_chart(chart_type, options)
end | ruby | def add_chart(chart_type, options={})
TwoCellAnchor.new(self, options)
@anchors.last.add_chart(chart_type, options)
end | [
"def",
"add_chart",
"(",
"chart_type",
",",
"options",
"=",
"{",
"}",
")",
"TwoCellAnchor",
".",
"new",
"(",
"self",
",",
"options",
")",
"@anchors",
".",
"last",
".",
"add_chart",
"(",
"chart_type",
",",
"options",
")",
"end"
] | Adds a chart to the drawing.
@note The recommended way to manage charts is to use Worksheet.add_chart. Please refer to that method for documentation.
@see Worksheet#add_chart | [
"Adds",
"a",
"chart",
"to",
"the",
"drawing",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L97-L100 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.charts | def charts
charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) }
charts.map { |a| a.object.chart }
end | ruby | def charts
charts = @anchors.select { |a| a.object.is_a?(GraphicFrame) }
charts.map { |a| a.object.chart }
end | [
"def",
"charts",
"charts",
"=",
"@anchors",
".",
"select",
"{",
"|",
"a",
"|",
"a",
".",
"object",
".",
"is_a?",
"(",
"GraphicFrame",
")",
"}",
"charts",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"object",
".",
"chart",
"}",
"end"
] | An array of charts that are associated with this drawing's anchors
@return [Array] | [
"An",
"array",
"of",
"charts",
"that",
"are",
"associated",
"with",
"this",
"drawing",
"s",
"anchors"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L104-L107 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.hyperlinks | def hyperlinks
links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
links.map { |a| a.hyperlink }
end | ruby | def hyperlinks
links = self.images.select { |a| a.hyperlink.is_a?(Hyperlink) }
links.map { |a| a.hyperlink }
end | [
"def",
"hyperlinks",
"links",
"=",
"self",
".",
"images",
".",
"select",
"{",
"|",
"a",
"|",
"a",
".",
"hyperlink",
".",
"is_a?",
"(",
"Hyperlink",
")",
"}",
"links",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"hyperlink",
"}",
"end"
] | An array of hyperlink objects associated with this drawings images
@return [Array] | [
"An",
"array",
"of",
"hyperlink",
"objects",
"associated",
"with",
"this",
"drawings",
"images"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L111-L114 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.images | def images
images = @anchors.select { |a| a.object.is_a?(Pic) }
images.map { |a| a.object }
end | ruby | def images
images = @anchors.select { |a| a.object.is_a?(Pic) }
images.map { |a| a.object }
end | [
"def",
"images",
"images",
"=",
"@anchors",
".",
"select",
"{",
"|",
"a",
"|",
"a",
".",
"object",
".",
"is_a?",
"(",
"Pic",
")",
"}",
"images",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"object",
"}",
"end"
] | An array of image objects that are associated with this drawing's anchors
@return [Array] | [
"An",
"array",
"of",
"image",
"objects",
"that",
"are",
"associated",
"with",
"this",
"drawing",
"s",
"anchors"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L118-L121 | train |
randym/axlsx | lib/axlsx/drawing/drawing.rb | Axlsx.Drawing.relationships | def relationships
r = Relationships.new
child_objects.each { |child| r << child.relationship }
r
end | ruby | def relationships
r = Relationships.new
child_objects.each { |child| r << child.relationship }
r
end | [
"def",
"relationships",
"r",
"=",
"Relationships",
".",
"new",
"child_objects",
".",
"each",
"{",
"|",
"child",
"|",
"r",
"<<",
"child",
".",
"relationship",
"}",
"r",
"end"
] | The drawing's relationships.
@return [Relationships] | [
"The",
"drawing",
"s",
"relationships",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/drawing.rb#L150-L154 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/sheet_pr.rb | Axlsx.SheetPr.to_xml_string | def to_xml_string(str = '')
update_properties
str << "<sheetPr #{serialized_attributes}>"
tab_color.to_xml_string(str, 'tabColor') if tab_color
outline_pr.to_xml_string(str) if @outline_pr
page_setup_pr.to_xml_string(str)
str << "</sheetPr>"
end | ruby | def to_xml_string(str = '')
update_properties
str << "<sheetPr #{serialized_attributes}>"
tab_color.to_xml_string(str, 'tabColor') if tab_color
outline_pr.to_xml_string(str) if @outline_pr
page_setup_pr.to_xml_string(str)
str << "</sheetPr>"
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"update_properties",
"str",
"<<",
"\"<sheetPr #{serialized_attributes}>\"",
"tab_color",
".",
"to_xml_string",
"(",
"str",
",",
"'tabColor'",
")",
"if",
"tab_color",
"outline_pr",
".",
"to_xml_string",
"(",
"str",
")",
"if",
"@outline_pr",
"page_setup_pr",
".",
"to_xml_string",
"(",
"str",
")",
"str",
"<<",
"\"</sheetPr>\"",
"end"
] | Serialize the object
@param [String] str serialized output will be appended to this object if provided.
@return [String] | [
"Serialize",
"the",
"object"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/sheet_pr.rb#L51-L58 | train |
randym/axlsx | lib/axlsx/drawing/pie_3D_chart.rb | Axlsx.Pie3DChart.to_xml_string | def to_xml_string(str = '')
super(str) do
str << '<c:pie3DChart>'
str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
@series.each { |ser| ser.to_xml_string(str) }
d_lbls.to_xml_string(str) if @d_lbls
str << '</c:pie3DChart>'
end
end | ruby | def to_xml_string(str = '')
super(str) do
str << '<c:pie3DChart>'
str << ('<c:varyColors val="' << vary_colors.to_s << '"/>')
@series.each { |ser| ser.to_xml_string(str) }
d_lbls.to_xml_string(str) if @d_lbls
str << '</c:pie3DChart>'
end
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"super",
"(",
"str",
")",
"do",
"str",
"<<",
"'<c:pie3DChart>'",
"str",
"<<",
"(",
"'<c:varyColors val=\"'",
"<<",
"vary_colors",
".",
"to_s",
"<<",
"'\"/>'",
")",
"@series",
".",
"each",
"{",
"|",
"ser",
"|",
"ser",
".",
"to_xml_string",
"(",
"str",
")",
"}",
"d_lbls",
".",
"to_xml_string",
"(",
"str",
")",
"if",
"@d_lbls",
"str",
"<<",
"'</c:pie3DChart>'",
"end",
"end"
] | Creates a new pie chart object
@param [GraphicFrame] frame The workbook that owns this chart.
@option options [Cell, String] title
@option options [Boolean] show_legend
@option options [Symbol] grouping
@option options [String] gap_depth
@option options [Integer] rot_x
@option options [String] h_percent
@option options [Integer] rot_y
@option options [String] depth_percent
@option options [Boolean] r_ang_ax
@option options [Integer] perspective
@see Chart
@see View3D
Serializes the object
@param [String] str
@return [String] | [
"Creates",
"a",
"new",
"pie",
"chart",
"object"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/pie_3D_chart.rb#L36-L44 | train |
randym/axlsx | lib/axlsx/workbook/workbook_views.rb | Axlsx.WorkbookViews.to_xml_string | def to_xml_string(str = '')
return if empty?
str << "<bookViews>"
each { |view| view.to_xml_string(str) }
str << '</bookViews>'
end | ruby | def to_xml_string(str = '')
return if empty?
str << "<bookViews>"
each { |view| view.to_xml_string(str) }
str << '</bookViews>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"return",
"if",
"empty?",
"str",
"<<",
"\"<bookViews>\"",
"each",
"{",
"|",
"view",
"|",
"view",
".",
"to_xml_string",
"(",
"str",
")",
"}",
"str",
"<<",
"'</bookViews>'",
"end"
] | creates the book views object
Serialize to xml
@param [String] str
@return [String] | [
"creates",
"the",
"book",
"views",
"object",
"Serialize",
"to",
"xml"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/workbook_views.rb#L13-L18 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/col.rb | Axlsx.Col.update_width | def update_width(cell, fixed_width=nil, use_autowidth=true)
if fixed_width.is_a? Numeric
self.width = fixed_width
elsif use_autowidth
cell_width = cell.autowidth
self.width = cell_width unless (width || 0) > (cell_width || 0)
end
end | ruby | def update_width(cell, fixed_width=nil, use_autowidth=true)
if fixed_width.is_a? Numeric
self.width = fixed_width
elsif use_autowidth
cell_width = cell.autowidth
self.width = cell_width unless (width || 0) > (cell_width || 0)
end
end | [
"def",
"update_width",
"(",
"cell",
",",
"fixed_width",
"=",
"nil",
",",
"use_autowidth",
"=",
"true",
")",
"if",
"fixed_width",
".",
"is_a?",
"Numeric",
"self",
".",
"width",
"=",
"fixed_width",
"elsif",
"use_autowidth",
"cell_width",
"=",
"cell",
".",
"autowidth",
"self",
".",
"width",
"=",
"cell_width",
"unless",
"(",
"width",
"||",
"0",
")",
">",
"(",
"cell_width",
"||",
"0",
")",
"end",
"end"
] | updates the width for this col based on the cells autowidth and
an optionally specified fixed width
@param [Cell] cell The cell to use in updating this col's width
@param [Integer] fixed_width If this is specified the width is set
to this value and the cell's attributes are ignored.
@param [Boolean] use_autowidth If this is false, the cell's
autowidth value will be ignored. | [
"updates",
"the",
"width",
"for",
"this",
"col",
"based",
"on",
"the",
"cells",
"autowidth",
"and",
"an",
"optionally",
"specified",
"fixed",
"width"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/col.rb#L124-L131 | train |
randym/axlsx | lib/axlsx/util/parser.rb | Axlsx.Parser.parse_symbol | def parse_symbol attr_name, xpath
v = parse_value xpath
v = v.to_sym unless v.nil?
send("#{attr_name}=", v)
end | ruby | def parse_symbol attr_name, xpath
v = parse_value xpath
v = v.to_sym unless v.nil?
send("#{attr_name}=", v)
end | [
"def",
"parse_symbol",
"attr_name",
",",
"xpath",
"v",
"=",
"parse_value",
"xpath",
"v",
"=",
"v",
".",
"to_sym",
"unless",
"v",
".",
"nil?",
"send",
"(",
"\"#{attr_name}=\"",
",",
"v",
")",
"end"
] | parse convert and assign node text to symbol | [
"parse",
"convert",
"and",
"assign",
"node",
"text",
"to",
"symbol"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/parser.rb#L16-L20 | train |
randym/axlsx | lib/axlsx/util/parser.rb | Axlsx.Parser.parse_integer | def parse_integer attr_name, xpath
v = parse_value xpath
v = v.to_i if v.respond_to?(:to_i)
send("#{attr_name}=", v)
end | ruby | def parse_integer attr_name, xpath
v = parse_value xpath
v = v.to_i if v.respond_to?(:to_i)
send("#{attr_name}=", v)
end | [
"def",
"parse_integer",
"attr_name",
",",
"xpath",
"v",
"=",
"parse_value",
"xpath",
"v",
"=",
"v",
".",
"to_i",
"if",
"v",
".",
"respond_to?",
"(",
":to_i",
")",
"send",
"(",
"\"#{attr_name}=\"",
",",
"v",
")",
"end"
] | parse, convert and assign note text to integer | [
"parse",
"convert",
"and",
"assign",
"note",
"text",
"to",
"integer"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/parser.rb#L23-L27 | train |
randym/axlsx | lib/axlsx/util/parser.rb | Axlsx.Parser.parse_float | def parse_float attr_name, xpath
v = parse_value xpath
v = v.to_f if v.respond_to?(:to_f)
send("#{attr_name}=", v)
end | ruby | def parse_float attr_name, xpath
v = parse_value xpath
v = v.to_f if v.respond_to?(:to_f)
send("#{attr_name}=", v)
end | [
"def",
"parse_float",
"attr_name",
",",
"xpath",
"v",
"=",
"parse_value",
"xpath",
"v",
"=",
"v",
".",
"to_f",
"if",
"v",
".",
"respond_to?",
"(",
":to_f",
")",
"send",
"(",
"\"#{attr_name}=\"",
",",
"v",
")",
"end"
] | parse, convert and assign node text to float | [
"parse",
"convert",
"and",
"assign",
"node",
"text",
"to",
"float"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/parser.rb#L30-L34 | train |
randym/axlsx | lib/axlsx/util/parser.rb | Axlsx.Parser.parse_value | def parse_value xpath
node = parser_xml.xpath(xpath)
return nil if node.empty?
node.text.strip
end | ruby | def parse_value xpath
node = parser_xml.xpath(xpath)
return nil if node.empty?
node.text.strip
end | [
"def",
"parse_value",
"xpath",
"node",
"=",
"parser_xml",
".",
"xpath",
"(",
"xpath",
")",
"return",
"nil",
"if",
"node",
".",
"empty?",
"node",
".",
"text",
".",
"strip",
"end"
] | return node text based on xpath | [
"return",
"node",
"text",
"based",
"on",
"xpath"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/parser.rb#L37-L41 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/worksheet_drawing.rb | Axlsx.WorksheetDrawing.add_chart | def add_chart(chart_type, options)
@drawing ||= Drawing.new worksheet
drawing.add_chart(chart_type, options)
end | ruby | def add_chart(chart_type, options)
@drawing ||= Drawing.new worksheet
drawing.add_chart(chart_type, options)
end | [
"def",
"add_chart",
"(",
"chart_type",
",",
"options",
")",
"@drawing",
"||=",
"Drawing",
".",
"new",
"worksheet",
"drawing",
".",
"add_chart",
"(",
"chart_type",
",",
"options",
")",
"end"
] | adds a chart to the drawing object
@param [Class] chart_type The type of chart to add
@param [Hash] options Options to pass on to the drawing and chart
@see Worksheet#add_chart | [
"adds",
"a",
"chart",
"to",
"the",
"drawing",
"object"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet_drawing.rb#L25-L28 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/protected_ranges.rb | Axlsx.ProtectedRanges.add_range | def add_range(cells)
sqref = if cells.is_a?(String)
cells
elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
Axlsx::cell_range(cells, false)
end
self << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}")
last
end | ruby | def add_range(cells)
sqref = if cells.is_a?(String)
cells
elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
Axlsx::cell_range(cells, false)
end
self << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}")
last
end | [
"def",
"add_range",
"(",
"cells",
")",
"sqref",
"=",
"if",
"cells",
".",
"is_a?",
"(",
"String",
")",
"cells",
"elsif",
"cells",
".",
"is_a?",
"(",
"SimpleTypedList",
")",
"||",
"cells",
".",
"is_a?",
"(",
"Array",
")",
"Axlsx",
"::",
"cell_range",
"(",
"cells",
",",
"false",
")",
"end",
"self",
"<<",
"ProtectedRange",
".",
"new",
"(",
":sqref",
"=>",
"sqref",
",",
":name",
"=>",
"\"Range#{size}\"",
")",
"last",
"end"
] | Adds a protected range
@param [Array|String] cells A string range reference or array of cells that will be protected | [
"Adds",
"a",
"protected",
"range"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/protected_ranges.rb#L17-L25 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/protected_ranges.rb | Axlsx.ProtectedRanges.to_xml_string | def to_xml_string(str = '')
return if empty?
str << '<protectedRanges>'
each { |range| range.to_xml_string(str) }
str << '</protectedRanges>'
end | ruby | def to_xml_string(str = '')
return if empty?
str << '<protectedRanges>'
each { |range| range.to_xml_string(str) }
str << '</protectedRanges>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"return",
"if",
"empty?",
"str",
"<<",
"'<protectedRanges>'",
"each",
"{",
"|",
"range",
"|",
"range",
".",
"to_xml_string",
"(",
"str",
")",
"}",
"str",
"<<",
"'</protectedRanges>'",
"end"
] | Serializes the protected ranges
@param [String] str
@return [String] | [
"Serializes",
"the",
"protected",
"ranges"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/protected_ranges.rb#L30-L35 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb | Axlsx.AutoFilter.add_column | def add_column(col_id, filter_type, options = {})
columns << FilterColumn.new(col_id, filter_type, options)
columns.last
end | ruby | def add_column(col_id, filter_type, options = {})
columns << FilterColumn.new(col_id, filter_type, options)
columns.last
end | [
"def",
"add_column",
"(",
"col_id",
",",
"filter_type",
",",
"options",
"=",
"{",
"}",
")",
"columns",
"<<",
"FilterColumn",
".",
"new",
"(",
"col_id",
",",
"filter_type",
",",
"options",
")",
"columns",
".",
"last",
"end"
] | Adds a filter column. This is the recommended way to create and manage filter columns for your autofilter.
In addition to the require id and type parameters, options will be passed to the filter column during instantiation.
@param [String] col_id Zero-based index indicating the AutoFilter column to which this filter information applies.
@param [Symbol] filter_type A symbol representing one of the supported filter types.
@param [Hash] options a hash of options to pass into the generated filter
@return [FilterColumn] | [
"Adds",
"a",
"filter",
"column",
".",
"This",
"is",
"the",
"recommended",
"way",
"to",
"create",
"and",
"manage",
"filter",
"columns",
"for",
"your",
"autofilter",
".",
"In",
"addition",
"to",
"the",
"require",
"id",
"and",
"type",
"parameters",
"options",
"will",
"be",
"passed",
"to",
"the",
"filter",
"column",
"during",
"instantiation",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb#L45-L48 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb | Axlsx.AutoFilter.apply | def apply
first_cell, last_cell = range.split(':')
start_point = Axlsx::name_to_indices(first_cell)
end_point = Axlsx::name_to_indices(last_cell)
# The +1 is so we skip the header row with the filter drop downs
rows = worksheet.rows[(start_point.last+1)..end_point.last] || []
column_offset = start_point.first
columns.each do |column|
rows.each do |row|
next if row.hidden
column.apply(row, column_offset)
end
end
end | ruby | def apply
first_cell, last_cell = range.split(':')
start_point = Axlsx::name_to_indices(first_cell)
end_point = Axlsx::name_to_indices(last_cell)
# The +1 is so we skip the header row with the filter drop downs
rows = worksheet.rows[(start_point.last+1)..end_point.last] || []
column_offset = start_point.first
columns.each do |column|
rows.each do |row|
next if row.hidden
column.apply(row, column_offset)
end
end
end | [
"def",
"apply",
"first_cell",
",",
"last_cell",
"=",
"range",
".",
"split",
"(",
"':'",
")",
"start_point",
"=",
"Axlsx",
"::",
"name_to_indices",
"(",
"first_cell",
")",
"end_point",
"=",
"Axlsx",
"::",
"name_to_indices",
"(",
"last_cell",
")",
"# The +1 is so we skip the header row with the filter drop downs",
"rows",
"=",
"worksheet",
".",
"rows",
"[",
"(",
"start_point",
".",
"last",
"+",
"1",
")",
"..",
"end_point",
".",
"last",
"]",
"||",
"[",
"]",
"column_offset",
"=",
"start_point",
".",
"first",
"columns",
".",
"each",
"do",
"|",
"column",
"|",
"rows",
".",
"each",
"do",
"|",
"row",
"|",
"next",
"if",
"row",
".",
"hidden",
"column",
".",
"apply",
"(",
"row",
",",
"column_offset",
")",
"end",
"end",
"end"
] | actually performs the filtering of rows who's cells do not
match the filter. | [
"actually",
"performs",
"the",
"filtering",
"of",
"rows",
"who",
"s",
"cells",
"do",
"not",
"match",
"the",
"filter",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb#L52-L66 | train |
randym/axlsx | lib/axlsx/util/simple_typed_list.rb | Axlsx.SimpleTypedList.delete | def delete(v)
return unless include? v
raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v)
@list.delete v
end | ruby | def delete(v)
return unless include? v
raise ArgumentError, "Item is protected and cannot be deleted" if protected? index(v)
@list.delete v
end | [
"def",
"delete",
"(",
"v",
")",
"return",
"unless",
"include?",
"v",
"raise",
"ArgumentError",
",",
"\"Item is protected and cannot be deleted\"",
"if",
"protected?",
"index",
"(",
"v",
")",
"@list",
".",
"delete",
"v",
"end"
] | delete the item from the list
@param [Any] v The item to be deleted.
@raise [ArgumentError] if the item's index is protected by locking
@return [Any] The item deleted | [
"delete",
"the",
"item",
"from",
"the",
"list"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/simple_typed_list.rb#L108-L112 | train |
randym/axlsx | lib/axlsx/util/simple_typed_list.rb | Axlsx.SimpleTypedList.[]= | def []=(index, v)
DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
raise ArgumentError, "Item is protected and cannot be changed" if protected? index
@list[index] = v
v
end | ruby | def []=(index, v)
DataTypeValidator.validate :SimpleTypedList_insert, @allowed_types, v
raise ArgumentError, "Item is protected and cannot be changed" if protected? index
@list[index] = v
v
end | [
"def",
"[]=",
"(",
"index",
",",
"v",
")",
"DataTypeValidator",
".",
"validate",
":SimpleTypedList_insert",
",",
"@allowed_types",
",",
"v",
"raise",
"ArgumentError",
",",
"\"Item is protected and cannot be changed\"",
"if",
"protected?",
"index",
"@list",
"[",
"index",
"]",
"=",
"v",
"v",
"end"
] | positional assignment. Adds the item at the index specified
@param [Integer] index
@param [Any] v
@raise [ArgumentError] if the index is protected by locking
@raise [ArgumentError] if the item is not one of the allowed types | [
"positional",
"assignment",
".",
"Adds",
"the",
"item",
"at",
"the",
"index",
"specified"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/simple_typed_list.rb#L128-L133 | train |
randym/axlsx | lib/axlsx/util/serialized_attributes.rb | Axlsx.SerializedAttributes.serialized_tag | def serialized_tag(tagname, str, additional_attributes = {}, &block)
str << "<#{tagname} "
serialized_attributes(str, additional_attributes)
if block_given?
str << '>'
yield
str << "</#{tagname}>"
else
str << '/>'
end
end | ruby | def serialized_tag(tagname, str, additional_attributes = {}, &block)
str << "<#{tagname} "
serialized_attributes(str, additional_attributes)
if block_given?
str << '>'
yield
str << "</#{tagname}>"
else
str << '/>'
end
end | [
"def",
"serialized_tag",
"(",
"tagname",
",",
"str",
",",
"additional_attributes",
"=",
"{",
"}",
",",
"&",
"block",
")",
"str",
"<<",
"\"<#{tagname} \"",
"serialized_attributes",
"(",
"str",
",",
"additional_attributes",
")",
"if",
"block_given?",
"str",
"<<",
"'>'",
"yield",
"str",
"<<",
"\"</#{tagname}>\"",
"else",
"str",
"<<",
"'/>'",
"end",
"end"
] | creates a XML tag with serialized attributes
@see SerializedAttributes#serialized_attributes | [
"creates",
"a",
"XML",
"tag",
"with",
"serialized",
"attributes"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/serialized_attributes.rb#L34-L44 | train |
randym/axlsx | lib/axlsx/util/serialized_attributes.rb | Axlsx.SerializedAttributes.serialized_attributes | def serialized_attributes(str = '', additional_attributes = {})
attributes = declared_attributes.merge! additional_attributes
attributes.each do |key, value|
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
end
str
end | ruby | def serialized_attributes(str = '', additional_attributes = {})
attributes = declared_attributes.merge! additional_attributes
attributes.each do |key, value|
str << "#{Axlsx.camel(key, false)}=\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\" "
end
str
end | [
"def",
"serialized_attributes",
"(",
"str",
"=",
"''",
",",
"additional_attributes",
"=",
"{",
"}",
")",
"attributes",
"=",
"declared_attributes",
".",
"merge!",
"additional_attributes",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"str",
"<<",
"\"#{Axlsx.camel(key, false)}=\\\"#{Axlsx.camel(Axlsx.booleanize(value), false)}\\\" \"",
"end",
"str",
"end"
] | serializes the instance values of the defining object based on the
list of serializable attributes.
@param [String] str The string instance to append this
serialization to.
@param [Hash] additional_attributes An option key value hash for
defining values that are not serializable attributes list. | [
"serializes",
"the",
"instance",
"values",
"of",
"the",
"defining",
"object",
"based",
"on",
"the",
"list",
"of",
"serializable",
"attributes",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/serialized_attributes.rb#L52-L58 | train |
randym/axlsx | lib/axlsx/util/serialized_attributes.rb | Axlsx.SerializedAttributes.declared_attributes | def declared_attributes
instance_values.select do |key, value|
value != nil && self.class.xml_attributes.include?(key.to_sym)
end
end | ruby | def declared_attributes
instance_values.select do |key, value|
value != nil && self.class.xml_attributes.include?(key.to_sym)
end
end | [
"def",
"declared_attributes",
"instance_values",
".",
"select",
"do",
"|",
"key",
",",
"value",
"|",
"value",
"!=",
"nil",
"&&",
"self",
".",
"class",
".",
"xml_attributes",
".",
"include?",
"(",
"key",
".",
"to_sym",
")",
"end",
"end"
] | A hash of instance variables that have been declared with
seraialized_attributes and are not nil.
This requires ruby 1.9.3 or higher | [
"A",
"hash",
"of",
"instance",
"variables",
"that",
"have",
"been",
"declared",
"with",
"seraialized_attributes",
"and",
"are",
"not",
"nil",
".",
"This",
"requires",
"ruby",
"1",
".",
"9",
".",
"3",
"or",
"higher"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/serialized_attributes.rb#L63-L67 | train |
randym/axlsx | lib/axlsx/util/serialized_attributes.rb | Axlsx.SerializedAttributes.serialized_element_attributes | def serialized_element_attributes(str='', additional_attributes=[], &block)
attrs = self.class.xml_element_attributes + additional_attributes
values = instance_values
attrs.each do |attribute_name|
value = values[attribute_name.to_s]
next if value.nil?
value = yield value if block_given?
element_name = Axlsx.camel(attribute_name, false)
str << "<#{element_name}>#{value}</#{element_name}>"
end
str
end | ruby | def serialized_element_attributes(str='', additional_attributes=[], &block)
attrs = self.class.xml_element_attributes + additional_attributes
values = instance_values
attrs.each do |attribute_name|
value = values[attribute_name.to_s]
next if value.nil?
value = yield value if block_given?
element_name = Axlsx.camel(attribute_name, false)
str << "<#{element_name}>#{value}</#{element_name}>"
end
str
end | [
"def",
"serialized_element_attributes",
"(",
"str",
"=",
"''",
",",
"additional_attributes",
"=",
"[",
"]",
",",
"&",
"block",
")",
"attrs",
"=",
"self",
".",
"class",
".",
"xml_element_attributes",
"+",
"additional_attributes",
"values",
"=",
"instance_values",
"attrs",
".",
"each",
"do",
"|",
"attribute_name",
"|",
"value",
"=",
"values",
"[",
"attribute_name",
".",
"to_s",
"]",
"next",
"if",
"value",
".",
"nil?",
"value",
"=",
"yield",
"value",
"if",
"block_given?",
"element_name",
"=",
"Axlsx",
".",
"camel",
"(",
"attribute_name",
",",
"false",
")",
"str",
"<<",
"\"<#{element_name}>#{value}</#{element_name}>\"",
"end",
"str",
"end"
] | serialized instance values at text nodes on a camelized element of the
attribute name. You may pass in a block for evaluation against non nil
values. We use an array for element attributes becuase misordering will
break the xml and 1.8.7 does not support ordered hashes.
@param [String] str The string instance to which serialized data is appended
@param [Array] additional_attributes An array of additional attribute names.
@return [String] The serialized output. | [
"serialized",
"instance",
"values",
"at",
"text",
"nodes",
"on",
"a",
"camelized",
"element",
"of",
"the",
"attribute",
"name",
".",
"You",
"may",
"pass",
"in",
"a",
"block",
"for",
"evaluation",
"against",
"non",
"nil",
"values",
".",
"We",
"use",
"an",
"array",
"for",
"element",
"attributes",
"becuase",
"misordering",
"will",
"break",
"the",
"xml",
"and",
"1",
".",
"8",
".",
"7",
"does",
"not",
"support",
"ordered",
"hashes",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/util/serialized_attributes.rb#L76-L87 | train |
randym/axlsx | lib/axlsx/drawing/d_lbls.rb | Axlsx.DLbls.to_xml_string | def to_xml_string(str = '')
validate_attributes_for_chart_type
str << '<c:dLbls>'
%w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key|
next unless instance_values.keys.include?(key) && instance_values[key] != nil
str << "<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />"
end
str << '</c:dLbls>'
end | ruby | def to_xml_string(str = '')
validate_attributes_for_chart_type
str << '<c:dLbls>'
%w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key|
next unless instance_values.keys.include?(key) && instance_values[key] != nil
str << "<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />"
end
str << '</c:dLbls>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"validate_attributes_for_chart_type",
"str",
"<<",
"'<c:dLbls>'",
"%w(",
"d_lbl_pos",
"show_legend_key",
"show_val",
"show_cat_name",
"show_ser_name",
"show_percent",
"show_bubble_size",
"show_leader_lines",
")",
".",
"each",
"do",
"|",
"key",
"|",
"next",
"unless",
"instance_values",
".",
"keys",
".",
"include?",
"(",
"key",
")",
"&&",
"instance_values",
"[",
"key",
"]",
"!=",
"nil",
"str",
"<<",
"\"<c:#{Axlsx::camel(key, false)} val='#{instance_values[key]}' />\"",
"end",
"str",
"<<",
"'</c:dLbls>'",
"end"
] | serializes the data labels
@return [String] | [
"serializes",
"the",
"data",
"labels"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/d_lbls.rb#L71-L79 | train |
randym/axlsx | lib/axlsx/drawing/line_chart.rb | Axlsx.LineChart.node_name | def node_name
path = self.class.to_s
if i = path.rindex('::')
path = path[(i+2)..-1]
end
path[0] = path[0].chr.downcase
path
end | ruby | def node_name
path = self.class.to_s
if i = path.rindex('::')
path = path[(i+2)..-1]
end
path[0] = path[0].chr.downcase
path
end | [
"def",
"node_name",
"path",
"=",
"self",
".",
"class",
".",
"to_s",
"if",
"i",
"=",
"path",
".",
"rindex",
"(",
"'::'",
")",
"path",
"=",
"path",
"[",
"(",
"i",
"+",
"2",
")",
"..",
"-",
"1",
"]",
"end",
"path",
"[",
"0",
"]",
"=",
"path",
"[",
"0",
"]",
".",
"chr",
".",
"downcase",
"path",
"end"
] | The node name to use in serialization. As LineChart is used as the
base class for Liine3DChart we need to be sure to serialize the
chart based on the actual class type and not a fixed node name.
@return [String] | [
"The",
"node",
"name",
"to",
"use",
"in",
"serialization",
".",
"As",
"LineChart",
"is",
"used",
"as",
"the",
"base",
"class",
"for",
"Liine3DChart",
"we",
"need",
"to",
"be",
"sure",
"to",
"serialize",
"the",
"chart",
"based",
"on",
"the",
"actual",
"class",
"type",
"and",
"not",
"a",
"fixed",
"node",
"name",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/line_chart.rb#L66-L73 | train |
randym/axlsx | lib/axlsx/doc_props/app.rb | Axlsx.App.to_xml_string | def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">')
instance_values.each do |key, value|
node_name = Axlsx.camel(key)
str << "<#{node_name}>#{value}</#{node_name}>"
end
str << '</Properties>'
end | ruby | def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<Properties xmlns="' << APP_NS << '" xmlns:vt="' << APP_NS_VT << '">')
instance_values.each do |key, value|
node_name = Axlsx.camel(key)
str << "<#{node_name}>#{value}</#{node_name}>"
end
str << '</Properties>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"str",
"<<",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
"str",
"<<",
"(",
"'<Properties xmlns=\"'",
"<<",
"APP_NS",
"<<",
"'\" xmlns:vt=\"'",
"<<",
"APP_NS_VT",
"<<",
"'\">'",
")",
"instance_values",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"node_name",
"=",
"Axlsx",
".",
"camel",
"(",
"key",
")",
"str",
"<<",
"\"<#{node_name}>#{value}</#{node_name}>\"",
"end",
"str",
"<<",
"'</Properties>'",
"end"
] | Serialize the app.xml document
@return [String] | [
"Serialize",
"the",
"app",
".",
"xml",
"document"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/doc_props/app.rb#L223-L231 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/cell.rb | Axlsx.Cell.merge | def merge(target)
start, stop = if target.is_a?(String)
[self.r, target]
elsif(target.is_a?(Cell))
Axlsx.sort_cells([self, target]).map { |c| c.r }
end
self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
end | ruby | def merge(target)
start, stop = if target.is_a?(String)
[self.r, target]
elsif(target.is_a?(Cell))
Axlsx.sort_cells([self, target]).map { |c| c.r }
end
self.row.worksheet.merge_cells "#{start}:#{stop}" unless stop.nil?
end | [
"def",
"merge",
"(",
"target",
")",
"start",
",",
"stop",
"=",
"if",
"target",
".",
"is_a?",
"(",
"String",
")",
"[",
"self",
".",
"r",
",",
"target",
"]",
"elsif",
"(",
"target",
".",
"is_a?",
"(",
"Cell",
")",
")",
"Axlsx",
".",
"sort_cells",
"(",
"[",
"self",
",",
"target",
"]",
")",
".",
"map",
"{",
"|",
"c",
"|",
"c",
".",
"r",
"}",
"end",
"self",
".",
"row",
".",
"worksheet",
".",
"merge_cells",
"\"#{start}:#{stop}\"",
"unless",
"stop",
".",
"nil?",
"end"
] | Merges all the cells in a range created between this cell and the cell or string name for a cell provided
@see worksheet.merge_cells
@param [Cell, String] target The last cell, or str ref for the cell in the merge range | [
"Merges",
"all",
"the",
"cells",
"in",
"a",
"range",
"created",
"between",
"this",
"cell",
"and",
"the",
"cell",
"or",
"string",
"name",
"for",
"a",
"cell",
"provided"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/cell.rb#L308-L315 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/cell.rb | Axlsx.Cell.autowidth | def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
string_width('', font_size) + value.autowidth
elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
max_width = 0
value.to_s.split(/\r?\n/).each do |line|
width = string_width(line, font_size)
max_width = width if width > max_width
end
max_width
else
string_width(value, font_size)
end
end | ruby | def autowidth
return if is_formula? || value.nil?
if contains_rich_text?
string_width('', font_size) + value.autowidth
elsif styles.cellXfs[style].alignment && styles.cellXfs[style].alignment.wrap_text
max_width = 0
value.to_s.split(/\r?\n/).each do |line|
width = string_width(line, font_size)
max_width = width if width > max_width
end
max_width
else
string_width(value, font_size)
end
end | [
"def",
"autowidth",
"return",
"if",
"is_formula?",
"||",
"value",
".",
"nil?",
"if",
"contains_rich_text?",
"string_width",
"(",
"''",
",",
"font_size",
")",
"+",
"value",
".",
"autowidth",
"elsif",
"styles",
".",
"cellXfs",
"[",
"style",
"]",
".",
"alignment",
"&&",
"styles",
".",
"cellXfs",
"[",
"style",
"]",
".",
"alignment",
".",
"wrap_text",
"max_width",
"=",
"0",
"value",
".",
"to_s",
".",
"split",
"(",
"/",
"\\r",
"\\n",
"/",
")",
".",
"each",
"do",
"|",
"line",
"|",
"width",
"=",
"string_width",
"(",
"line",
",",
"font_size",
")",
"max_width",
"=",
"width",
"if",
"width",
">",
"max_width",
"end",
"max_width",
"else",
"string_width",
"(",
"value",
",",
"font_size",
")",
"end",
"end"
] | Attempts to determine the correct width for this cell's content
@return [Float] | [
"Attempts",
"to",
"determine",
"the",
"correct",
"width",
"for",
"this",
"cell",
"s",
"content"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/cell.rb#L354-L368 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/cell.rb | Axlsx.Cell.cell_type_from_value | def cell_type_from_value(v)
if v.is_a?(Date)
:date
elsif v.is_a?(Time)
:time
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
:boolean
elsif v.to_s =~ Axlsx::NUMERIC_REGEX
:integer
elsif v.to_s =~ Axlsx::FLOAT_REGEX
:float
elsif v.to_s =~ Axlsx::ISO_8601_REGEX
:iso_8601
elsif v.is_a? RichText
:richtext
else
:string
end
end | ruby | def cell_type_from_value(v)
if v.is_a?(Date)
:date
elsif v.is_a?(Time)
:time
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
:boolean
elsif v.to_s =~ Axlsx::NUMERIC_REGEX
:integer
elsif v.to_s =~ Axlsx::FLOAT_REGEX
:float
elsif v.to_s =~ Axlsx::ISO_8601_REGEX
:iso_8601
elsif v.is_a? RichText
:richtext
else
:string
end
end | [
"def",
"cell_type_from_value",
"(",
"v",
")",
"if",
"v",
".",
"is_a?",
"(",
"Date",
")",
":date",
"elsif",
"v",
".",
"is_a?",
"(",
"Time",
")",
":time",
"elsif",
"v",
".",
"is_a?",
"(",
"TrueClass",
")",
"||",
"v",
".",
"is_a?",
"(",
"FalseClass",
")",
":boolean",
"elsif",
"v",
".",
"to_s",
"=~",
"Axlsx",
"::",
"NUMERIC_REGEX",
":integer",
"elsif",
"v",
".",
"to_s",
"=~",
"Axlsx",
"::",
"FLOAT_REGEX",
":float",
"elsif",
"v",
".",
"to_s",
"=~",
"Axlsx",
"::",
"ISO_8601_REGEX",
":iso_8601",
"elsif",
"v",
".",
"is_a?",
"RichText",
":richtext",
"else",
":string",
"end",
"end"
] | Determines the cell type based on the cell value.
@note This is only used when a cell is created but no :type option is specified, the following rules apply:
1. If the value is an instance of Date, the type is set to :date
2. If the value is an instance of Time, the type is set to :time
3. If the value is an instance of TrueClass or FalseClass, the type is set to :boolean
4. :float and :integer types are determined by regular expression matching.
5. Anything that does not meet either of the above is determined to be :string.
@return [Symbol] The determined type | [
"Determines",
"the",
"cell",
"type",
"based",
"on",
"the",
"cell",
"value",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/cell.rb#L426-L444 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/cell.rb | Axlsx.Cell.cast_value | def cast_value(v)
return v if v.is_a?(RichText) || v.nil?
case type
when :date
self.style = STYLE_DATE if self.style == 0
v
when :time
self.style = STYLE_DATE if self.style == 0
if !v.is_a?(Time) && v.respond_to?(:to_time)
v.to_time
else
v
end
when :float
v.to_f
when :integer
v.to_i
when :boolean
v ? 1 : 0
when :iso_8601
#consumer is responsible for ensuring the iso_8601 format when specifying this type
v
else
v.to_s
end
end | ruby | def cast_value(v)
return v if v.is_a?(RichText) || v.nil?
case type
when :date
self.style = STYLE_DATE if self.style == 0
v
when :time
self.style = STYLE_DATE if self.style == 0
if !v.is_a?(Time) && v.respond_to?(:to_time)
v.to_time
else
v
end
when :float
v.to_f
when :integer
v.to_i
when :boolean
v ? 1 : 0
when :iso_8601
#consumer is responsible for ensuring the iso_8601 format when specifying this type
v
else
v.to_s
end
end | [
"def",
"cast_value",
"(",
"v",
")",
"return",
"v",
"if",
"v",
".",
"is_a?",
"(",
"RichText",
")",
"||",
"v",
".",
"nil?",
"case",
"type",
"when",
":date",
"self",
".",
"style",
"=",
"STYLE_DATE",
"if",
"self",
".",
"style",
"==",
"0",
"v",
"when",
":time",
"self",
".",
"style",
"=",
"STYLE_DATE",
"if",
"self",
".",
"style",
"==",
"0",
"if",
"!",
"v",
".",
"is_a?",
"(",
"Time",
")",
"&&",
"v",
".",
"respond_to?",
"(",
":to_time",
")",
"v",
".",
"to_time",
"else",
"v",
"end",
"when",
":float",
"v",
".",
"to_f",
"when",
":integer",
"v",
".",
"to_i",
"when",
":boolean",
"v",
"?",
"1",
":",
"0",
"when",
":iso_8601",
"#consumer is responsible for ensuring the iso_8601 format when specifying this type",
"v",
"else",
"v",
".",
"to_s",
"end",
"end"
] | Cast the value into this cells data type.
@note
About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
@see Axlsx#date1904 | [
"Cast",
"the",
"value",
"into",
"this",
"cells",
"data",
"type",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/cell.rb#L450-L475 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/auto_filter/filters.rb | Axlsx.Filters.apply | def apply(cell)
return false unless cell
filter_items.each do |filter|
return false if cell.value == filter.val
end
true
end | ruby | def apply(cell)
return false unless cell
filter_items.each do |filter|
return false if cell.value == filter.val
end
true
end | [
"def",
"apply",
"(",
"cell",
")",
"return",
"false",
"unless",
"cell",
"filter_items",
".",
"each",
"do",
"|",
"filter",
"|",
"return",
"false",
"if",
"cell",
".",
"value",
"==",
"filter",
".",
"val",
"end",
"true",
"end"
] | Tells us if the row of the cell provided should be filterd as it
does not meet any of the specified filter_items or
date_group_items restrictions.
@param [Cell] cell The cell to test against items
TODO implement this for date filters as well! | [
"Tells",
"us",
"if",
"the",
"row",
"of",
"the",
"cell",
"provided",
"should",
"be",
"filterd",
"as",
"it",
"does",
"not",
"meet",
"any",
"of",
"the",
"specified",
"filter_items",
"or",
"date_group_items",
"restrictions",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/filters.rb#L43-L49 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/auto_filter/filters.rb | Axlsx.Filters.to_xml_string | def to_xml_string(str = '')
str << "<filters #{serialized_attributes}>"
filter_items.each { |filter| filter.to_xml_string(str) }
date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) }
str << '</filters>'
end | ruby | def to_xml_string(str = '')
str << "<filters #{serialized_attributes}>"
filter_items.each { |filter| filter.to_xml_string(str) }
date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) }
str << '</filters>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"str",
"<<",
"\"<filters #{serialized_attributes}>\"",
"filter_items",
".",
"each",
"{",
"|",
"filter",
"|",
"filter",
".",
"to_xml_string",
"(",
"str",
")",
"}",
"date_group_items",
".",
"each",
"{",
"|",
"date_group_item",
"|",
"date_group_item",
".",
"to_xml_string",
"(",
"str",
")",
"}",
"str",
"<<",
"'</filters>'",
"end"
] | Serialize the object to xml | [
"Serialize",
"the",
"object",
"to",
"xml"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/filters.rb#L77-L82 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/auto_filter/filters.rb | Axlsx.Filters.date_group_items= | def date_group_items=(options)
options.each do |date_group|
raise ArgumentError, "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group.is_a?(Hash)
date_group_items << DateGroupItem.new(date_group)
end
end | ruby | def date_group_items=(options)
options.each do |date_group|
raise ArgumentError, "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group.is_a?(Hash)
date_group_items << DateGroupItem.new(date_group)
end
end | [
"def",
"date_group_items",
"=",
"(",
"options",
")",
"options",
".",
"each",
"do",
"|",
"date_group",
"|",
"raise",
"ArgumentError",
",",
"\"date_group_items should be an array of hashes specifying the options for each date_group_item\"",
"unless",
"date_group",
".",
"is_a?",
"(",
"Hash",
")",
"date_group_items",
"<<",
"DateGroupItem",
".",
"new",
"(",
"date_group",
")",
"end",
"end"
] | Date group items are date group filter items where you specify the
date_group and a value for that option as part of the auto_filter
@note This can be specified, but will not be applied to the date
values in your workbook at this time. | [
"Date",
"group",
"items",
"are",
"date",
"group",
"filter",
"items",
"where",
"you",
"specify",
"the",
"date_group",
"and",
"a",
"value",
"for",
"that",
"option",
"as",
"part",
"of",
"the",
"auto_filter"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/auto_filter/filters.rb#L98-L103 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/sheet_protection.rb | Axlsx.SheetProtection.create_password_hash | def create_password_hash(password)
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
password_as_string = password_as_hex.unpack("H*").first.upcase
password_as_string[2..3] + password_as_string[0..1]
end | ruby | def create_password_hash(password)
encoded_password = encode_password(password)
password_as_hex = [encoded_password].pack("v")
password_as_string = password_as_hex.unpack("H*").first.upcase
password_as_string[2..3] + password_as_string[0..1]
end | [
"def",
"create_password_hash",
"(",
"password",
")",
"encoded_password",
"=",
"encode_password",
"(",
"password",
")",
"password_as_hex",
"=",
"[",
"encoded_password",
"]",
".",
"pack",
"(",
"\"v\"",
")",
"password_as_string",
"=",
"password_as_hex",
".",
"unpack",
"(",
"\"H*\"",
")",
".",
"first",
".",
"upcase",
"password_as_string",
"[",
"2",
"..",
"3",
"]",
"+",
"password_as_string",
"[",
"0",
"..",
"1",
"]",
"end"
] | Creates a password hash for a given password
@return [String] | [
"Creates",
"a",
"password",
"hash",
"for",
"a",
"given",
"password"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/sheet_protection.rb#L85-L92 | train |
randym/axlsx | lib/axlsx/drawing/num_data.rb | Axlsx.NumData.data= | def data=(values=[])
@tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
values.each do |value|
value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
@pt << NumVal.new(:v => value)
end
end | ruby | def data=(values=[])
@tag_name = values.first.is_a?(Cell) ? :numCache : :numLit
values.each do |value|
value = value.is_formula? ? 0 : value.value if value.is_a?(Cell)
@pt << NumVal.new(:v => value)
end
end | [
"def",
"data",
"=",
"(",
"values",
"=",
"[",
"]",
")",
"@tag_name",
"=",
"values",
".",
"first",
".",
"is_a?",
"(",
"Cell",
")",
"?",
":numCache",
":",
":numLit",
"values",
".",
"each",
"do",
"|",
"value",
"|",
"value",
"=",
"value",
".",
"is_formula?",
"?",
"0",
":",
"value",
".",
"value",
"if",
"value",
".",
"is_a?",
"(",
"Cell",
")",
"@pt",
"<<",
"NumVal",
".",
"new",
"(",
":v",
"=>",
"value",
")",
"end",
"end"
] | Creates the val objects for this data set. I am not overly confident this is going to play nicely with time and data types.
@param [Array] values An array of cells or values. | [
"Creates",
"the",
"val",
"objects",
"for",
"this",
"data",
"set",
".",
"I",
"am",
"not",
"overly",
"confident",
"this",
"is",
"going",
"to",
"play",
"nicely",
"with",
"time",
"and",
"data",
"types",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/drawing/num_data.rb#L25-L31 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/table.rb | Axlsx.Table.name= | def name=(v)
DataTypeValidator.validate :table_name, [String], v
if v.is_a?(String)
@name = v
end
end | ruby | def name=(v)
DataTypeValidator.validate :table_name, [String], v
if v.is_a?(String)
@name = v
end
end | [
"def",
"name",
"=",
"(",
"v",
")",
"DataTypeValidator",
".",
"validate",
":table_name",
",",
"[",
"String",
"]",
",",
"v",
"if",
"v",
".",
"is_a?",
"(",
"String",
")",
"@name",
"=",
"v",
"end",
"end"
] | The name of the Table.
@param [String, Cell] v
@return [Title] | [
"The",
"name",
"of",
"the",
"Table",
"."
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/table.rb#L60-L65 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb | Axlsx.ConditionalFormattingRule.to_xml_string | def to_xml_string(str = '')
str << '<cfRule '
serialized_attributes str
str << '>'
str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
str << '</cfRule>'
end | ruby | def to_xml_string(str = '')
str << '<cfRule '
serialized_attributes str
str << '>'
str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
@color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
@data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
@icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
str << '</cfRule>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"str",
"<<",
"'<cfRule '",
"serialized_attributes",
"str",
"str",
"<<",
"'>'",
"str",
"<<",
"(",
"'<formula>'",
"<<",
"[",
"self",
".",
"formula",
"]",
".",
"join",
"(",
"'</formula><formula>'",
")",
"<<",
"'</formula>'",
")",
"if",
"@formula",
"@color_scale",
".",
"to_xml_string",
"(",
"str",
")",
"if",
"@color_scale",
"&&",
"@type",
"==",
":colorScale",
"@data_bar",
".",
"to_xml_string",
"(",
"str",
")",
"if",
"@data_bar",
"&&",
"@type",
"==",
":dataBar",
"@icon_set",
".",
"to_xml_string",
"(",
"str",
")",
"if",
"@icon_set",
"&&",
"@type",
"==",
":iconSet",
"str",
"<<",
"'</cfRule>'",
"end"
] | Serializes the conditional formatting rule
@param [String] str
@return [String] | [
"Serializes",
"the",
"conditional",
"formatting",
"rule"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb#L209-L218 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb | Axlsx.WorksheetHyperlink.ref= | def ref=(cell_reference)
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
Axlsx::validate_string cell_reference
@ref = cell_reference
end | ruby | def ref=(cell_reference)
cell_reference = cell_reference.r if cell_reference.is_a?(Cell)
Axlsx::validate_string cell_reference
@ref = cell_reference
end | [
"def",
"ref",
"=",
"(",
"cell_reference",
")",
"cell_reference",
"=",
"cell_reference",
".",
"r",
"if",
"cell_reference",
".",
"is_a?",
"(",
"Cell",
")",
"Axlsx",
"::",
"validate_string",
"cell_reference",
"@ref",
"=",
"cell_reference",
"end"
] | Sets the cell location of this hyperlink in the worksheet
@param [String|Cell] cell_reference The string reference or cell that defines where this hyperlink shows in the worksheet. | [
"Sets",
"the",
"cell",
"location",
"of",
"this",
"hyperlink",
"in",
"the",
"worksheet"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb#L42-L46 | train |
randym/axlsx | lib/axlsx/doc_props/core.rb | Axlsx.Core.to_xml_string | def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ')
str << ('xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ')
str << ('xmlns:xsi="' << CORE_NS_XSI << '">')
str << ('<dc:creator>' << self.creator << '</dc:creator>')
str << ('<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>')
str << '<cp:revision>0</cp:revision>'
str << '</cp:coreProperties>'
end | ruby | def to_xml_string(str = '')
str << '<?xml version="1.0" encoding="UTF-8"?>'
str << ('<cp:coreProperties xmlns:cp="' << CORE_NS << '" xmlns:dc="' << CORE_NS_DC << '" ')
str << ('xmlns:dcmitype="' << CORE_NS_DCMIT << '" xmlns:dcterms="' << CORE_NS_DCT << '" ')
str << ('xmlns:xsi="' << CORE_NS_XSI << '">')
str << ('<dc:creator>' << self.creator << '</dc:creator>')
str << ('<dcterms:created xsi:type="dcterms:W3CDTF">' << (created || Time.now).strftime('%Y-%m-%dT%H:%M:%S') << 'Z</dcterms:created>')
str << '<cp:revision>0</cp:revision>'
str << '</cp:coreProperties>'
end | [
"def",
"to_xml_string",
"(",
"str",
"=",
"''",
")",
"str",
"<<",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
"str",
"<<",
"(",
"'<cp:coreProperties xmlns:cp=\"'",
"<<",
"CORE_NS",
"<<",
"'\" xmlns:dc=\"'",
"<<",
"CORE_NS_DC",
"<<",
"'\" '",
")",
"str",
"<<",
"(",
"'xmlns:dcmitype=\"'",
"<<",
"CORE_NS_DCMIT",
"<<",
"'\" xmlns:dcterms=\"'",
"<<",
"CORE_NS_DCT",
"<<",
"'\" '",
")",
"str",
"<<",
"(",
"'xmlns:xsi=\"'",
"<<",
"CORE_NS_XSI",
"<<",
"'\">'",
")",
"str",
"<<",
"(",
"'<dc:creator>'",
"<<",
"self",
".",
"creator",
"<<",
"'</dc:creator>'",
")",
"str",
"<<",
"(",
"'<dcterms:created xsi:type=\"dcterms:W3CDTF\">'",
"<<",
"(",
"created",
"||",
"Time",
".",
"now",
")",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:%S'",
")",
"<<",
"'Z</dcterms:created>'",
")",
"str",
"<<",
"'<cp:revision>0</cp:revision>'",
"str",
"<<",
"'</cp:coreProperties>'",
"end"
] | serializes the core.xml document
@return [String] | [
"serializes",
"the",
"core",
".",
"xml",
"document"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/doc_props/core.rb#L26-L35 | train |
randym/axlsx | lib/axlsx/workbook/worksheet/merged_cells.rb | Axlsx.MergedCells.add | def add(cells)
self << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
Axlsx::cell_range(cells, false)
elsif cells.is_a?(Row)
Axlsx::cell_range(cells, false)
end
end | ruby | def add(cells)
self << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
Axlsx::cell_range(cells, false)
elsif cells.is_a?(Row)
Axlsx::cell_range(cells, false)
end
end | [
"def",
"add",
"(",
"cells",
")",
"self",
"<<",
"if",
"cells",
".",
"is_a?",
"(",
"String",
")",
"cells",
"elsif",
"cells",
".",
"is_a?",
"(",
"Array",
")",
"Axlsx",
"::",
"cell_range",
"(",
"cells",
",",
"false",
")",
"elsif",
"cells",
".",
"is_a?",
"(",
"Row",
")",
"Axlsx",
"::",
"cell_range",
"(",
"cells",
",",
"false",
")",
"end",
"end"
] | creates a new MergedCells object
@param [Worksheet] worksheet
adds cells to the merged cells collection
@param [Array||String] cells The cells to add to the merged cells
collection. This can be an array of actual cells or a string style
range like 'A1:C1' | [
"creates",
"a",
"new",
"MergedCells",
"object"
] | c593a08b2a929dac7aa8dc418b55e26b4c49dc34 | https://github.com/randym/axlsx/blob/c593a08b2a929dac7aa8dc418b55e26b4c49dc34/lib/axlsx/workbook/worksheet/merged_cells.rb#L17-L25 | train |
alexreisner/geocoder | lib/geocoder/lookups/ban_data_gouv_fr.rb | Geocoder::Lookup.BanDataGouvFr.search_geocode_ban_fr_params | def search_geocode_ban_fr_params(query)
params = {
q: query.sanitized_text
}
unless (limit = query.options[:limit]).nil? || !limit_param_is_valid?(limit)
params[:limit] = limit.to_i
end
unless (autocomplete = query.options[:autocomplete]).nil? || !autocomplete_param_is_valid?(autocomplete)
params[:autocomplete] = autocomplete.to_s
end
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
params[:type] = type.downcase
end
unless (postcode = query.options[:postcode]).nil? || !code_param_is_valid?(postcode)
params[:postcode] = postcode.to_s
end
unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode)
params[:citycode] = citycode.to_s
end
params
end | ruby | def search_geocode_ban_fr_params(query)
params = {
q: query.sanitized_text
}
unless (limit = query.options[:limit]).nil? || !limit_param_is_valid?(limit)
params[:limit] = limit.to_i
end
unless (autocomplete = query.options[:autocomplete]).nil? || !autocomplete_param_is_valid?(autocomplete)
params[:autocomplete] = autocomplete.to_s
end
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
params[:type] = type.downcase
end
unless (postcode = query.options[:postcode]).nil? || !code_param_is_valid?(postcode)
params[:postcode] = postcode.to_s
end
unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode)
params[:citycode] = citycode.to_s
end
params
end | [
"def",
"search_geocode_ban_fr_params",
"(",
"query",
")",
"params",
"=",
"{",
"q",
":",
"query",
".",
"sanitized_text",
"}",
"unless",
"(",
"limit",
"=",
"query",
".",
"options",
"[",
":limit",
"]",
")",
".",
"nil?",
"||",
"!",
"limit_param_is_valid?",
"(",
"limit",
")",
"params",
"[",
":limit",
"]",
"=",
"limit",
".",
"to_i",
"end",
"unless",
"(",
"autocomplete",
"=",
"query",
".",
"options",
"[",
":autocomplete",
"]",
")",
".",
"nil?",
"||",
"!",
"autocomplete_param_is_valid?",
"(",
"autocomplete",
")",
"params",
"[",
":autocomplete",
"]",
"=",
"autocomplete",
".",
"to_s",
"end",
"unless",
"(",
"type",
"=",
"query",
".",
"options",
"[",
":type",
"]",
")",
".",
"nil?",
"||",
"!",
"type_param_is_valid?",
"(",
"type",
")",
"params",
"[",
":type",
"]",
"=",
"type",
".",
"downcase",
"end",
"unless",
"(",
"postcode",
"=",
"query",
".",
"options",
"[",
":postcode",
"]",
")",
".",
"nil?",
"||",
"!",
"code_param_is_valid?",
"(",
"postcode",
")",
"params",
"[",
":postcode",
"]",
"=",
"postcode",
".",
"to_s",
"end",
"unless",
"(",
"citycode",
"=",
"query",
".",
"options",
"[",
":citycode",
"]",
")",
".",
"nil?",
"||",
"!",
"code_param_is_valid?",
"(",
"citycode",
")",
"params",
"[",
":citycode",
"]",
"=",
"citycode",
".",
"to_s",
"end",
"params",
"end"
] | SEARCH GEOCODING PARAMS
:q => required, full text search param)
:limit => force limit number of results returned by raw API
(default = 5) note : only first result is taken
in account in geocoder
:autocomplete => pass 0 to disable autocomplete treatment of :q
(default = 1)
:lat => force filter results around specific lat/lon
:lon => force filter results around specific lat/lon
:type => force filter the returned result type
(check results for a list of accepted types)
:postcode => force filter results on a specific city post code
:citycode => force filter results on a specific city UUID INSEE code
For up to date doc (in french only) : https://adresse.data.gouv.fr/api/ | [
"SEARCH",
"GEOCODING",
"PARAMS"
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/lookups/ban_data_gouv_fr.rb#L70-L90 | train |
alexreisner/geocoder | lib/geocoder/lookups/ban_data_gouv_fr.rb | Geocoder::Lookup.BanDataGouvFr.reverse_geocode_ban_fr_params | def reverse_geocode_ban_fr_params(query)
lat_lon = query.coordinates
params = {
lat: lat_lon.first,
lon: lat_lon.last
}
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
params[:type] = type.downcase
end
params
end | ruby | def reverse_geocode_ban_fr_params(query)
lat_lon = query.coordinates
params = {
lat: lat_lon.first,
lon: lat_lon.last
}
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
params[:type] = type.downcase
end
params
end | [
"def",
"reverse_geocode_ban_fr_params",
"(",
"query",
")",
"lat_lon",
"=",
"query",
".",
"coordinates",
"params",
"=",
"{",
"lat",
":",
"lat_lon",
".",
"first",
",",
"lon",
":",
"lat_lon",
".",
"last",
"}",
"unless",
"(",
"type",
"=",
"query",
".",
"options",
"[",
":type",
"]",
")",
".",
"nil?",
"||",
"!",
"type_param_is_valid?",
"(",
"type",
")",
"params",
"[",
":type",
"]",
"=",
"type",
".",
"downcase",
"end",
"params",
"end"
] | REVERSE GEOCODING PARAMS
:lat => required
:lon => required
:type => force returned results type
(check results for a list of accepted types) | [
"REVERSE",
"GEOCODING",
"PARAMS"
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/lookups/ban_data_gouv_fr.rb#L101-L111 | train |
alexreisner/geocoder | lib/geocoder/lookup.rb | Geocoder.Lookup.classify_name | def classify_name(filename)
filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join
end | ruby | def classify_name(filename)
filename.to_s.split("_").map{ |i| i[0...1].upcase + i[1..-1] }.join
end | [
"def",
"classify_name",
"(",
"filename",
")",
"filename",
".",
"to_s",
".",
"split",
"(",
"\"_\"",
")",
".",
"map",
"{",
"|",
"i",
"|",
"i",
"[",
"0",
"...",
"1",
"]",
".",
"upcase",
"+",
"i",
"[",
"1",
"..",
"-",
"1",
"]",
"}",
".",
"join",
"end"
] | Convert an "underscore" version of a name into a "class" version. | [
"Convert",
"an",
"underscore",
"version",
"of",
"a",
"name",
"into",
"a",
"class",
"version",
"."
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/lookup.rb#L114-L116 | train |
alexreisner/geocoder | lib/geocoder/lookups/maxmind.rb | Geocoder::Lookup.Maxmind.configured_service! | def configured_service!
if s = configuration[:service] and services.keys.include?(s)
return s
else
raise(
Geocoder::ConfigurationError,
"When using MaxMind you MUST specify a service name: " +
"Geocoder.configure(:maxmind => {:service => ...}), " +
"where '...' is one of: #{services.keys.inspect}"
)
end
end | ruby | def configured_service!
if s = configuration[:service] and services.keys.include?(s)
return s
else
raise(
Geocoder::ConfigurationError,
"When using MaxMind you MUST specify a service name: " +
"Geocoder.configure(:maxmind => {:service => ...}), " +
"where '...' is one of: #{services.keys.inspect}"
)
end
end | [
"def",
"configured_service!",
"if",
"s",
"=",
"configuration",
"[",
":service",
"]",
"and",
"services",
".",
"keys",
".",
"include?",
"(",
"s",
")",
"return",
"s",
"else",
"raise",
"(",
"Geocoder",
"::",
"ConfigurationError",
",",
"\"When using MaxMind you MUST specify a service name: \"",
"+",
"\"Geocoder.configure(:maxmind => {:service => ...}), \"",
"+",
"\"where '...' is one of: #{services.keys.inspect}\"",
")",
"end",
"end"
] | Return the name of the configured service, or raise an exception. | [
"Return",
"the",
"name",
"of",
"the",
"configured",
"service",
"or",
"raise",
"an",
"exception",
"."
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/lookups/maxmind.rb#L21-L32 | train |
alexreisner/geocoder | lib/geocoder/cache.rb | Geocoder.Cache.[] | def [](url)
interpret case
when store.respond_to?(:[])
store[key_for(url)]
when store.respond_to?(:get)
store.get key_for(url)
when store.respond_to?(:read)
store.read key_for(url)
end
end | ruby | def [](url)
interpret case
when store.respond_to?(:[])
store[key_for(url)]
when store.respond_to?(:get)
store.get key_for(url)
when store.respond_to?(:read)
store.read key_for(url)
end
end | [
"def",
"[]",
"(",
"url",
")",
"interpret",
"case",
"when",
"store",
".",
"respond_to?",
"(",
":[]",
")",
"store",
"[",
"key_for",
"(",
"url",
")",
"]",
"when",
"store",
".",
"respond_to?",
"(",
":get",
")",
"store",
".",
"get",
"key_for",
"(",
"url",
")",
"when",
"store",
".",
"respond_to?",
"(",
":read",
")",
"store",
".",
"read",
"key_for",
"(",
"url",
")",
"end",
"end"
] | Read from the Cache. | [
"Read",
"from",
"the",
"Cache",
"."
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/cache.rb#L12-L21 | train |
alexreisner/geocoder | lib/geocoder/cache.rb | Geocoder.Cache.[]= | def []=(url, value)
case
when store.respond_to?(:[]=)
store[key_for(url)] = value
when store.respond_to?(:set)
store.set key_for(url), value
when store.respond_to?(:write)
store.write key_for(url), value
end
end | ruby | def []=(url, value)
case
when store.respond_to?(:[]=)
store[key_for(url)] = value
when store.respond_to?(:set)
store.set key_for(url), value
when store.respond_to?(:write)
store.write key_for(url), value
end
end | [
"def",
"[]=",
"(",
"url",
",",
"value",
")",
"case",
"when",
"store",
".",
"respond_to?",
"(",
":[]=",
")",
"store",
"[",
"key_for",
"(",
"url",
")",
"]",
"=",
"value",
"when",
"store",
".",
"respond_to?",
"(",
":set",
")",
"store",
".",
"set",
"key_for",
"(",
"url",
")",
",",
"value",
"when",
"store",
".",
"respond_to?",
"(",
":write",
")",
"store",
".",
"write",
"key_for",
"(",
"url",
")",
",",
"value",
"end",
"end"
] | Write to the Cache. | [
"Write",
"to",
"the",
"Cache",
"."
] | e087dc2759264ee6f307b926bb2de4ec2406859e | https://github.com/alexreisner/geocoder/blob/e087dc2759264ee6f307b926bb2de4ec2406859e/lib/geocoder/cache.rb#L26-L35 | train |
plataformatec/simple_form | lib/simple_form/form_builder.rb | SimpleForm.FormBuilder.full_error | def full_error(attribute_name, options = {})
options = options.dup
options[:error_prefix] ||= if object.class.respond_to?(:human_attribute_name)
object.class.human_attribute_name(attribute_name.to_s)
else
attribute_name.to_s.humanize
end
error(attribute_name, options)
end | ruby | def full_error(attribute_name, options = {})
options = options.dup
options[:error_prefix] ||= if object.class.respond_to?(:human_attribute_name)
object.class.human_attribute_name(attribute_name.to_s)
else
attribute_name.to_s.humanize
end
error(attribute_name, options)
end | [
"def",
"full_error",
"(",
"attribute_name",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"options",
".",
"dup",
"options",
"[",
":error_prefix",
"]",
"||=",
"if",
"object",
".",
"class",
".",
"respond_to?",
"(",
":human_attribute_name",
")",
"object",
".",
"class",
".",
"human_attribute_name",
"(",
"attribute_name",
".",
"to_s",
")",
"else",
"attribute_name",
".",
"to_s",
".",
"humanize",
"end",
"error",
"(",
"attribute_name",
",",
"options",
")",
"end"
] | Return the error but also considering its name. This is used
when errors for a hidden field need to be shown.
== Examples
f.full_error :token #=> <span class="error">Token is invalid</span> | [
"Return",
"the",
"error",
"but",
"also",
"considering",
"its",
"name",
".",
"This",
"is",
"used",
"when",
"errors",
"for",
"a",
"hidden",
"field",
"need",
"to",
"be",
"shown",
"."
] | 4dd9261ebb392e46a9beeefe8d83081e7c6e56b5 | https://github.com/plataformatec/simple_form/blob/4dd9261ebb392e46a9beeefe8d83081e7c6e56b5/lib/simple_form/form_builder.rb#L272-L282 | train |
plataformatec/simple_form | lib/simple_form/form_builder.rb | SimpleForm.FormBuilder.lookup_model_names | def lookup_model_names #:nodoc:
@lookup_model_names ||= begin
child_index = options[:child_index]
names = object_name.to_s.scan(/(?!\d)\w+/).flatten
names.delete(child_index) if child_index
names.each { |name| name.gsub!('_attributes', '') }
names.freeze
end
end | ruby | def lookup_model_names #:nodoc:
@lookup_model_names ||= begin
child_index = options[:child_index]
names = object_name.to_s.scan(/(?!\d)\w+/).flatten
names.delete(child_index) if child_index
names.each { |name| name.gsub!('_attributes', '') }
names.freeze
end
end | [
"def",
"lookup_model_names",
"#:nodoc:",
"@lookup_model_names",
"||=",
"begin",
"child_index",
"=",
"options",
"[",
":child_index",
"]",
"names",
"=",
"object_name",
".",
"to_s",
".",
"scan",
"(",
"/",
"\\d",
"\\w",
"/",
")",
".",
"flatten",
"names",
".",
"delete",
"(",
"child_index",
")",
"if",
"child_index",
"names",
".",
"each",
"{",
"|",
"name",
"|",
"name",
".",
"gsub!",
"(",
"'_attributes'",
",",
"''",
")",
"}",
"names",
".",
"freeze",
"end",
"end"
] | Extract the model names from the object_name mess, ignoring numeric and
explicit child indexes.
Example:
route[blocks_attributes][0][blocks_learning_object_attributes][1][foo_attributes]
["route", "blocks", "blocks_learning_object", "foo"] | [
"Extract",
"the",
"model",
"names",
"from",
"the",
"object_name",
"mess",
"ignoring",
"numeric",
"and",
"explicit",
"child",
"indexes",
"."
] | 4dd9261ebb392e46a9beeefe8d83081e7c6e56b5 | https://github.com/plataformatec/simple_form/blob/4dd9261ebb392e46a9beeefe8d83081e7c6e56b5/lib/simple_form/form_builder.rb#L462-L470 | train |
plataformatec/simple_form | lib/simple_form/form_builder.rb | SimpleForm.FormBuilder.lookup_action | def lookup_action #:nodoc:
@lookup_action ||= begin
action = template.controller && template.controller.action_name
return unless action
action = action.to_s
ACTIONS[action] || action
end
end | ruby | def lookup_action #:nodoc:
@lookup_action ||= begin
action = template.controller && template.controller.action_name
return unless action
action = action.to_s
ACTIONS[action] || action
end
end | [
"def",
"lookup_action",
"#:nodoc:",
"@lookup_action",
"||=",
"begin",
"action",
"=",
"template",
".",
"controller",
"&&",
"template",
".",
"controller",
".",
"action_name",
"return",
"unless",
"action",
"action",
"=",
"action",
".",
"to_s",
"ACTIONS",
"[",
"action",
"]",
"||",
"action",
"end",
"end"
] | The action to be used in lookup. | [
"The",
"action",
"to",
"be",
"used",
"in",
"lookup",
"."
] | 4dd9261ebb392e46a9beeefe8d83081e7c6e56b5 | https://github.com/plataformatec/simple_form/blob/4dd9261ebb392e46a9beeefe8d83081e7c6e56b5/lib/simple_form/form_builder.rb#L473-L480 | train |
plataformatec/simple_form | lib/simple_form/form_builder.rb | SimpleForm.FormBuilder.find_input | def find_input(attribute_name, options = {}, &block)
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
if block_given?
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
else
find_mapping(input_type).new(self, attribute_name, column, input_type, options)
end
end | ruby | def find_input(attribute_name, options = {}, &block)
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
if block_given?
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
else
find_mapping(input_type).new(self, attribute_name, column, input_type, options)
end
end | [
"def",
"find_input",
"(",
"attribute_name",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"column",
"=",
"find_attribute_column",
"(",
"attribute_name",
")",
"input_type",
"=",
"default_input_type",
"(",
"attribute_name",
",",
"column",
",",
"options",
")",
"if",
"block_given?",
"SimpleForm",
"::",
"Inputs",
"::",
"BlockInput",
".",
"new",
"(",
"self",
",",
"attribute_name",
",",
"column",
",",
"input_type",
",",
"options",
",",
"block",
")",
"else",
"find_mapping",
"(",
"input_type",
")",
".",
"new",
"(",
"self",
",",
"attribute_name",
",",
"column",
",",
"input_type",
",",
"options",
")",
"end",
"end"
] | Find an input based on the attribute name. | [
"Find",
"an",
"input",
"based",
"on",
"the",
"attribute",
"name",
"."
] | 4dd9261ebb392e46a9beeefe8d83081e7c6e56b5 | https://github.com/plataformatec/simple_form/blob/4dd9261ebb392e46a9beeefe8d83081e7c6e56b5/lib/simple_form/form_builder.rb#L530-L539 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.valid_elf_file? | def valid_elf_file?(path)
# A light-weight way to check if is a valid ELF file
# Checks at least one phdr should present.
File.open(path) { |f| ELFTools::ELFFile.new(f).each_segments.first }
true
rescue ELFTools::ELFError
false
end | ruby | def valid_elf_file?(path)
# A light-weight way to check if is a valid ELF file
# Checks at least one phdr should present.
File.open(path) { |f| ELFTools::ELFFile.new(f).each_segments.first }
true
rescue ELFTools::ELFError
false
end | [
"def",
"valid_elf_file?",
"(",
"path",
")",
"# A light-weight way to check if is a valid ELF file",
"# Checks at least one phdr should present.",
"File",
".",
"open",
"(",
"path",
")",
"{",
"|",
"f",
"|",
"ELFTools",
"::",
"ELFFile",
".",
"new",
"(",
"f",
")",
".",
"each_segments",
".",
"first",
"}",
"true",
"rescue",
"ELFTools",
"::",
"ELFError",
"false",
"end"
] | Checks if the file of given path is a valid ELF file.
@param [String] path Path to target file.
@return [Boolean] If the file is an ELF or not.
@example
Helper.valid_elf_file?('/etc/passwd')
#=> false
Helper.valid_elf_file?('/lib64/ld-linux-x86-64.so.2')
#=> true | [
"Checks",
"if",
"the",
"file",
"of",
"given",
"path",
"is",
"a",
"valid",
"ELF",
"file",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L60-L67 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.build_id_of | def build_id_of(path)
File.open(path) { |f| ELFTools::ELFFile.new(f).build_id }
end | ruby | def build_id_of(path)
File.open(path) { |f| ELFTools::ELFFile.new(f).build_id }
end | [
"def",
"build_id_of",
"(",
"path",
")",
"File",
".",
"open",
"(",
"path",
")",
"{",
"|",
"f",
"|",
"ELFTools",
"::",
"ELFFile",
".",
"new",
"(",
"f",
")",
".",
"build_id",
"}",
"end"
] | Get the Build ID of target ELF.
@param [String] path Absolute file path.
@return [String] Target build id.
@example
Helper.build_id_of('/lib/x86_64-linux-gnu/libc-2.23.so')
#=> '60131540dadc6796cab33388349e6e4e68692053' | [
"Get",
"the",
"Build",
"ID",
"of",
"target",
"ELF",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L88-L90 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.colorize | def colorize(str, sev: :normal_s)
return str unless color_enabled?
cc = COLOR_CODE
color = cc.key?(sev) ? cc[sev] : ''
"#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}"
end | ruby | def colorize(str, sev: :normal_s)
return str unless color_enabled?
cc = COLOR_CODE
color = cc.key?(sev) ? cc[sev] : ''
"#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}"
end | [
"def",
"colorize",
"(",
"str",
",",
"sev",
":",
":normal_s",
")",
"return",
"str",
"unless",
"color_enabled?",
"cc",
"=",
"COLOR_CODE",
"color",
"=",
"cc",
".",
"key?",
"(",
"sev",
")",
"?",
"cc",
"[",
"sev",
"]",
":",
"''",
"\"#{color}#{str.sub(cc[:esc_m], color)}#{cc[:esc_m]}\"",
"end"
] | Wrap string with color codes for pretty inspect.
@param [String] str Contents to colorize.
@param [Symbol] sev Specify which kind of color to use, valid symbols are defined in {.COLOR_CODE}.
@return [String] String wrapped with color codes. | [
"Wrap",
"string",
"with",
"color",
"codes",
"for",
"pretty",
"inspect",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L122-L128 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.url_request | def url_request(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
raise ArgumentError, "Fail to get response of #{url}" unless %w[200 302].include?(response.code)
response.code == '302' ? response['location'] : response.body
rescue NoMethodError, SocketError, ArgumentError => e
OneGadget::Logger.error(e.message)
nil
end | ruby | def url_request(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
raise ArgumentError, "Fail to get response of #{url}" unless %w[200 302].include?(response.code)
response.code == '302' ? response['location'] : response.body
rescue NoMethodError, SocketError, ArgumentError => e
OneGadget::Logger.error(e.message)
nil
end | [
"def",
"url_request",
"(",
"url",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"url",
")",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"http",
".",
"use_ssl",
"=",
"true",
"http",
".",
"verify_mode",
"=",
"::",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"uri",
".",
"request_uri",
")",
"response",
"=",
"http",
".",
"request",
"(",
"request",
")",
"raise",
"ArgumentError",
",",
"\"Fail to get response of #{url}\"",
"unless",
"%w[",
"200",
"302",
"]",
".",
"include?",
"(",
"response",
".",
"code",
")",
"response",
".",
"code",
"==",
"'302'",
"?",
"response",
"[",
"'location'",
"]",
":",
"response",
".",
"body",
"rescue",
"NoMethodError",
",",
"SocketError",
",",
"ArgumentError",
"=>",
"e",
"OneGadget",
"::",
"Logger",
".",
"error",
"(",
"e",
".",
"message",
")",
"nil",
"end"
] | Get request.
@param [String] url The url.
@return [String]
The request response body.
If the response is +302 Found+, returns the location in header. | [
"Get",
"request",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L173-L188 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.architecture | def architecture(file)
return :invalid unless File.exist?(file)
f = File.open(file)
str = ELFTools::ELFFile.new(f).machine
{
'Advanced Micro Devices X86-64' => :amd64,
'Intel 80386' => :i386,
'ARM' => :arm,
'AArch64' => :aarch64,
'MIPS R3000' => :mips
}[str] || :unknown
rescue ELFTools::ELFError # not a valid ELF
:invalid
ensure
f&.close
end | ruby | def architecture(file)
return :invalid unless File.exist?(file)
f = File.open(file)
str = ELFTools::ELFFile.new(f).machine
{
'Advanced Micro Devices X86-64' => :amd64,
'Intel 80386' => :i386,
'ARM' => :arm,
'AArch64' => :aarch64,
'MIPS R3000' => :mips
}[str] || :unknown
rescue ELFTools::ELFError # not a valid ELF
:invalid
ensure
f&.close
end | [
"def",
"architecture",
"(",
"file",
")",
"return",
":invalid",
"unless",
"File",
".",
"exist?",
"(",
"file",
")",
"f",
"=",
"File",
".",
"open",
"(",
"file",
")",
"str",
"=",
"ELFTools",
"::",
"ELFFile",
".",
"new",
"(",
"f",
")",
".",
"machine",
"{",
"'Advanced Micro Devices X86-64'",
"=>",
":amd64",
",",
"'Intel 80386'",
"=>",
":i386",
",",
"'ARM'",
"=>",
":arm",
",",
"'AArch64'",
"=>",
":aarch64",
",",
"'MIPS R3000'",
"=>",
":mips",
"}",
"[",
"str",
"]",
"||",
":unknown",
"rescue",
"ELFTools",
"::",
"ELFError",
"# not a valid ELF",
":invalid",
"ensure",
"f",
"&.",
"close",
"end"
] | Fetch the ELF archiecture of +file+.
@param [String] file The target ELF filename.
@return [Symbol]
Currently supports amd64, i386, arm, aarch64, and mips.
@example
Helper.architecture('/bin/cat')
#=> :amd64 | [
"Fetch",
"the",
"ELF",
"archiecture",
"of",
"+",
"file",
"+",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L197-L213 | train |
david942j/one_gadget | lib/one_gadget/helper.rb | OneGadget.Helper.find_objdump | def find_objdump(arch)
[
which('objdump'),
which(arch_specific_objdump(arch))
].find { |bin| objdump_arch_supported?(bin, arch) }
end | ruby | def find_objdump(arch)
[
which('objdump'),
which(arch_specific_objdump(arch))
].find { |bin| objdump_arch_supported?(bin, arch) }
end | [
"def",
"find_objdump",
"(",
"arch",
")",
"[",
"which",
"(",
"'objdump'",
")",
",",
"which",
"(",
"arch_specific_objdump",
"(",
"arch",
")",
")",
"]",
".",
"find",
"{",
"|",
"bin",
"|",
"objdump_arch_supported?",
"(",
"bin",
",",
"arch",
")",
"}",
"end"
] | Find objdump that supports architecture +arch+.
@param [String] arch
@return [String?]
@example
Helper.find_objdump(:amd64)
#=> '/usr/bin/objdump'
Helper.find_objdump(:aarch64)
#=> '/usr/bin/aarch64-linux-gnu-objdump' | [
"Find",
"objdump",
"that",
"supports",
"architecture",
"+",
"arch",
"+",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/helper.rb#L278-L283 | train |
david942j/one_gadget | lib/one_gadget/abi.rb | OneGadget.ABI.stack_register? | def stack_register?(reg)
%w[esp ebp rsp rbp sp x29].include?(reg)
end | ruby | def stack_register?(reg)
%w[esp ebp rsp rbp sp x29].include?(reg)
end | [
"def",
"stack_register?",
"(",
"reg",
")",
"%w[",
"esp",
"ebp",
"rsp",
"rbp",
"sp",
"x29",
"]",
".",
"include?",
"(",
"reg",
")",
"end"
] | Checks if the register is a stack-related pointer.
@param [String] reg
Register's name.
@return [Boolean] | [
"Checks",
"if",
"the",
"register",
"is",
"a",
"stack",
"-",
"related",
"pointer",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/abi.rb#L47-L49 | train |
david942j/one_gadget | lib/one_gadget/logger.rb | OneGadget.Logger.ask_update | def ask_update(msg: '')
name = 'one_gadget'
cmd = OneGadget::Helper.colorize("gem update #{name} && gem cleanup #{name}")
OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n")
end | ruby | def ask_update(msg: '')
name = 'one_gadget'
cmd = OneGadget::Helper.colorize("gem update #{name} && gem cleanup #{name}")
OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n")
end | [
"def",
"ask_update",
"(",
"msg",
":",
"''",
")",
"name",
"=",
"'one_gadget'",
"cmd",
"=",
"OneGadget",
"::",
"Helper",
".",
"colorize",
"(",
"\"gem update #{name} && gem cleanup #{name}\"",
")",
"OneGadget",
"::",
"Logger",
".",
"info",
"(",
"msg",
"+",
"\"\\n\"",
"+",
"\"Update with: $ #{cmd}\"",
"+",
"\"\\n\"",
")",
"end"
] | Show the message of ask user to update gem.
@return [void] | [
"Show",
"the",
"message",
"of",
"ask",
"user",
"to",
"update",
"gem",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/logger.rb#L40-L44 | train |
david942j/one_gadget | lib/one_gadget/cli.rb | OneGadget.CLI.work | def work(argv)
@options = DEFAULT_OPTIONS.dup
parser.parse!(argv)
return show("OneGadget Version #{OneGadget::VERSION}") if @options[:version]
return info_build_id(@options[:info]) if @options[:info]
libc_file = argv.pop
build_id = @options[:build_id]
level = @options[:level]
return error('Either FILE or BuildID can be passed') if libc_file && @options[:build_id]
return show(parser.help) && false unless build_id || libc_file
gadgets = if build_id
OneGadget.gadgets(build_id: build_id, details: true, level: level)
else # libc_file
OneGadget.gadgets(file: libc_file, details: true, force_file: @options[:force_file], level: level)
end
handle_gadgets(gadgets, libc_file)
end | ruby | def work(argv)
@options = DEFAULT_OPTIONS.dup
parser.parse!(argv)
return show("OneGadget Version #{OneGadget::VERSION}") if @options[:version]
return info_build_id(@options[:info]) if @options[:info]
libc_file = argv.pop
build_id = @options[:build_id]
level = @options[:level]
return error('Either FILE or BuildID can be passed') if libc_file && @options[:build_id]
return show(parser.help) && false unless build_id || libc_file
gadgets = if build_id
OneGadget.gadgets(build_id: build_id, details: true, level: level)
else # libc_file
OneGadget.gadgets(file: libc_file, details: true, force_file: @options[:force_file], level: level)
end
handle_gadgets(gadgets, libc_file)
end | [
"def",
"work",
"(",
"argv",
")",
"@options",
"=",
"DEFAULT_OPTIONS",
".",
"dup",
"parser",
".",
"parse!",
"(",
"argv",
")",
"return",
"show",
"(",
"\"OneGadget Version #{OneGadget::VERSION}\"",
")",
"if",
"@options",
"[",
":version",
"]",
"return",
"info_build_id",
"(",
"@options",
"[",
":info",
"]",
")",
"if",
"@options",
"[",
":info",
"]",
"libc_file",
"=",
"argv",
".",
"pop",
"build_id",
"=",
"@options",
"[",
":build_id",
"]",
"level",
"=",
"@options",
"[",
":level",
"]",
"return",
"error",
"(",
"'Either FILE or BuildID can be passed'",
")",
"if",
"libc_file",
"&&",
"@options",
"[",
":build_id",
"]",
"return",
"show",
"(",
"parser",
".",
"help",
")",
"&&",
"false",
"unless",
"build_id",
"||",
"libc_file",
"gadgets",
"=",
"if",
"build_id",
"OneGadget",
".",
"gadgets",
"(",
"build_id",
":",
"build_id",
",",
"details",
":",
"true",
",",
"level",
":",
"level",
")",
"else",
"# libc_file",
"OneGadget",
".",
"gadgets",
"(",
"file",
":",
"libc_file",
",",
"details",
":",
"true",
",",
"force_file",
":",
"@options",
"[",
":force_file",
"]",
",",
"level",
":",
"level",
")",
"end",
"handle_gadgets",
"(",
"gadgets",
",",
"libc_file",
")",
"end"
] | Main method of CLI.
@param [Array<String>] argv
Command line arguments.
@return [Boolean]
Whether the command execute successfully.
@example
CLI.work(%w[--help])
# usage message
#=> true
CLI.work(%w[--version])
# version message
#=> true
@example
CLI.work([])
# usage message
#=> false
@example
CLI.work(%w[-b b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0 -r])
# 324293 324386 1090444
#=> true | [
"Main",
"method",
"of",
"CLI",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/cli.rb#L39-L57 | train |
david942j/one_gadget | lib/one_gadget/cli.rb | OneGadget.CLI.handle_gadgets | def handle_gadgets(gadgets, libc_file)
return false if gadgets.empty? # error occurs when fetching gadgets
return handle_script(gadgets, @options[:script]) if @options[:script]
return handle_near(libc_file, gadgets, @options[:near]) if @options[:near]
display_gadgets(gadgets, @options[:raw])
end | ruby | def handle_gadgets(gadgets, libc_file)
return false if gadgets.empty? # error occurs when fetching gadgets
return handle_script(gadgets, @options[:script]) if @options[:script]
return handle_near(libc_file, gadgets, @options[:near]) if @options[:near]
display_gadgets(gadgets, @options[:raw])
end | [
"def",
"handle_gadgets",
"(",
"gadgets",
",",
"libc_file",
")",
"return",
"false",
"if",
"gadgets",
".",
"empty?",
"# error occurs when fetching gadgets",
"return",
"handle_script",
"(",
"gadgets",
",",
"@options",
"[",
":script",
"]",
")",
"if",
"@options",
"[",
":script",
"]",
"return",
"handle_near",
"(",
"libc_file",
",",
"gadgets",
",",
"@options",
"[",
":near",
"]",
")",
"if",
"@options",
"[",
":near",
"]",
"display_gadgets",
"(",
"gadgets",
",",
"@options",
"[",
":raw",
"]",
")",
"end"
] | Decides how to display fetched gadgets according to options.
@param [Array<OneGadget::Gadget::Gadget>] gadgets
@param [String] libc_file
@return [Boolean] | [
"Decides",
"how",
"to",
"display",
"fetched",
"gadgets",
"according",
"to",
"options",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/cli.rb#L63-L69 | train |
david942j/one_gadget | lib/one_gadget/cli.rb | OneGadget.CLI.info_build_id | def info_build_id(id)
result = OneGadget::Gadget.builds_info(id)
return false if result.nil? # invalid form or BuildID not found
OneGadget::Logger.info("Information of #{id}:\n#{result.join("\n")}")
true
end | ruby | def info_build_id(id)
result = OneGadget::Gadget.builds_info(id)
return false if result.nil? # invalid form or BuildID not found
OneGadget::Logger.info("Information of #{id}:\n#{result.join("\n")}")
true
end | [
"def",
"info_build_id",
"(",
"id",
")",
"result",
"=",
"OneGadget",
"::",
"Gadget",
".",
"builds_info",
"(",
"id",
")",
"return",
"false",
"if",
"result",
".",
"nil?",
"# invalid form or BuildID not found",
"OneGadget",
"::",
"Logger",
".",
"info",
"(",
"\"Information of #{id}:\\n#{result.join(\"\\n\")}\"",
")",
"true",
"end"
] | Displays libc information given BuildID.
@param [String] id
@return [Boolean]
+false+ is returned if no information found.
@example
CLI.info_build_id('b417c')
# [OneGadget] Information of b417c:
# spec/data/libc-2.27-b417c0ba7cc5cf06d1d1bed6652cedb9253c60d0.so
# Advanced Micro Devices X86-64
# GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27.
# Copyright (C) 2018 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions.
# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
# Compiled by GNU CC version 7.3.0.
# libc ABIs: UNIQUE IFUNC
# For bug reporting instructions, please see:
# <https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
#=> true | [
"Displays",
"libc",
"information",
"given",
"BuildID",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/cli.rb#L92-L98 | train |
david942j/one_gadget | lib/one_gadget/cli.rb | OneGadget.CLI.parser | def parser
@parser ||= OptionParser.new do |opts|
opts.banner = USAGE
opts.on('-b', '--build-id BuildID', 'BuildID[sha1] of libc.') do |b|
@options[:build_id] = b
end
opts.on('-f', '--[no-]force-file', 'Force search gadgets in file instead of build id first.') do |f|
@options[:force_file] = f
end
opts.on('-l', '--level OUTPUT_LEVEL', Integer, 'The output level.',
'OneGadget automatically selects gadgets with higher successful probability.',
'Increase this level to ask OneGadget show more gadgets it found.',
'Default: 0') do |l|
@options[:level] = l
end
opts.on('-n', '--near FUNCTIONS/FILE', 'Order gadgets by their distance to the given functions'\
' or to the GOT functions of the given file.') do |n|
@options[:near] = n
end
opts.on('-r', '--[no-]raw', 'Output gadgets offset only, split with one space.') do |v|
@options[:raw] = v
end
opts.on('-s', '--script exploit-script', 'Run exploit script with all possible gadgets.',
'The script will be run as \'exploit-script $offset\'.') do |s|
@options[:script] = s
end
opts.on('--info BuildID', 'Show version information given BuildID.') do |b|
@options[:info] = b
end
opts.on('--version', 'Current gem version.') do |v|
@options[:version] = v
end
end
end | ruby | def parser
@parser ||= OptionParser.new do |opts|
opts.banner = USAGE
opts.on('-b', '--build-id BuildID', 'BuildID[sha1] of libc.') do |b|
@options[:build_id] = b
end
opts.on('-f', '--[no-]force-file', 'Force search gadgets in file instead of build id first.') do |f|
@options[:force_file] = f
end
opts.on('-l', '--level OUTPUT_LEVEL', Integer, 'The output level.',
'OneGadget automatically selects gadgets with higher successful probability.',
'Increase this level to ask OneGadget show more gadgets it found.',
'Default: 0') do |l|
@options[:level] = l
end
opts.on('-n', '--near FUNCTIONS/FILE', 'Order gadgets by their distance to the given functions'\
' or to the GOT functions of the given file.') do |n|
@options[:near] = n
end
opts.on('-r', '--[no-]raw', 'Output gadgets offset only, split with one space.') do |v|
@options[:raw] = v
end
opts.on('-s', '--script exploit-script', 'Run exploit script with all possible gadgets.',
'The script will be run as \'exploit-script $offset\'.') do |s|
@options[:script] = s
end
opts.on('--info BuildID', 'Show version information given BuildID.') do |b|
@options[:info] = b
end
opts.on('--version', 'Current gem version.') do |v|
@options[:version] = v
end
end
end | [
"def",
"parser",
"@parser",
"||=",
"OptionParser",
".",
"new",
"do",
"|",
"opts",
"|",
"opts",
".",
"banner",
"=",
"USAGE",
"opts",
".",
"on",
"(",
"'-b'",
",",
"'--build-id BuildID'",
",",
"'BuildID[sha1] of libc.'",
")",
"do",
"|",
"b",
"|",
"@options",
"[",
":build_id",
"]",
"=",
"b",
"end",
"opts",
".",
"on",
"(",
"'-f'",
",",
"'--[no-]force-file'",
",",
"'Force search gadgets in file instead of build id first.'",
")",
"do",
"|",
"f",
"|",
"@options",
"[",
":force_file",
"]",
"=",
"f",
"end",
"opts",
".",
"on",
"(",
"'-l'",
",",
"'--level OUTPUT_LEVEL'",
",",
"Integer",
",",
"'The output level.'",
",",
"'OneGadget automatically selects gadgets with higher successful probability.'",
",",
"'Increase this level to ask OneGadget show more gadgets it found.'",
",",
"'Default: 0'",
")",
"do",
"|",
"l",
"|",
"@options",
"[",
":level",
"]",
"=",
"l",
"end",
"opts",
".",
"on",
"(",
"'-n'",
",",
"'--near FUNCTIONS/FILE'",
",",
"'Order gadgets by their distance to the given functions'",
"' or to the GOT functions of the given file.'",
")",
"do",
"|",
"n",
"|",
"@options",
"[",
":near",
"]",
"=",
"n",
"end",
"opts",
".",
"on",
"(",
"'-r'",
",",
"'--[no-]raw'",
",",
"'Output gadgets offset only, split with one space.'",
")",
"do",
"|",
"v",
"|",
"@options",
"[",
":raw",
"]",
"=",
"v",
"end",
"opts",
".",
"on",
"(",
"'-s'",
",",
"'--script exploit-script'",
",",
"'Run exploit script with all possible gadgets.'",
",",
"'The script will be run as \\'exploit-script $offset\\'.'",
")",
"do",
"|",
"s",
"|",
"@options",
"[",
":script",
"]",
"=",
"s",
"end",
"opts",
".",
"on",
"(",
"'--info BuildID'",
",",
"'Show version information given BuildID.'",
")",
"do",
"|",
"b",
"|",
"@options",
"[",
":info",
"]",
"=",
"b",
"end",
"opts",
".",
"on",
"(",
"'--version'",
",",
"'Current gem version.'",
")",
"do",
"|",
"v",
"|",
"@options",
"[",
":version",
"]",
"=",
"v",
"end",
"end",
"end"
] | The option parser.
@return [OptionParser] | [
"The",
"option",
"parser",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/cli.rb#L102-L143 | train |
david942j/one_gadget | lib/one_gadget/cli.rb | OneGadget.CLI.display_gadgets | def display_gadgets(gadgets, raw)
if raw
show(gadgets.map(&:offset).join(' '))
else
show(gadgets.map(&:inspect).join("\n"))
end
end | ruby | def display_gadgets(gadgets, raw)
if raw
show(gadgets.map(&:offset).join(' '))
else
show(gadgets.map(&:inspect).join("\n"))
end
end | [
"def",
"display_gadgets",
"(",
"gadgets",
",",
"raw",
")",
"if",
"raw",
"show",
"(",
"gadgets",
".",
"map",
"(",
":offset",
")",
".",
"join",
"(",
"' '",
")",
")",
"else",
"show",
"(",
"gadgets",
".",
"map",
"(",
":inspect",
")",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"end",
"end"
] | Writes gadgets to stdout.
@param [Array<OneGadget::Gadget::Gadget>] gadgets
@param [Boolean] raw
In raw mode, only the offset of gadgets are printed.
@return [true] | [
"Writes",
"gadgets",
"to",
"stdout",
"."
] | ff6ef04541e83441bfe3c2664a6febd1640f4263 | https://github.com/david942j/one_gadget/blob/ff6ef04541e83441bfe3c2664a6febd1640f4263/lib/one_gadget/cli.rb#L177-L183 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.logger | def logger(logger, level = :info, format = :apache)
default_options[:logger] = logger
default_options[:log_level] = level
default_options[:log_format] = format
end | ruby | def logger(logger, level = :info, format = :apache)
default_options[:logger] = logger
default_options[:log_level] = level
default_options[:log_format] = format
end | [
"def",
"logger",
"(",
"logger",
",",
"level",
"=",
":info",
",",
"format",
"=",
":apache",
")",
"default_options",
"[",
":logger",
"]",
"=",
"logger",
"default_options",
"[",
":log_level",
"]",
"=",
"level",
"default_options",
"[",
":log_format",
"]",
"=",
"format",
"end"
] | Turns on logging
class Foo
include HTTParty
logger Logger.new('http_logger'), :info, :apache
end | [
"Turns",
"on",
"logging"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L73-L77 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.http_proxy | def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
default_options[:http_proxyaddr] = addr
default_options[:http_proxyport] = port
default_options[:http_proxyuser] = user
default_options[:http_proxypass] = pass
end | ruby | def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
default_options[:http_proxyaddr] = addr
default_options[:http_proxyport] = port
default_options[:http_proxyuser] = user
default_options[:http_proxypass] = pass
end | [
"def",
"http_proxy",
"(",
"addr",
"=",
"nil",
",",
"port",
"=",
"nil",
",",
"user",
"=",
"nil",
",",
"pass",
"=",
"nil",
")",
"default_options",
"[",
":http_proxyaddr",
"]",
"=",
"addr",
"default_options",
"[",
":http_proxyport",
"]",
"=",
"port",
"default_options",
"[",
":http_proxyuser",
"]",
"=",
"user",
"default_options",
"[",
":http_proxypass",
"]",
"=",
"pass",
"end"
] | Allows setting http proxy information to be used
class Foo
include HTTParty
http_proxy 'http://foo.com', 80, 'user', 'pass'
end | [
"Allows",
"setting",
"http",
"proxy",
"information",
"to",
"be",
"used"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L95-L100 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.default_params | def default_params(h = {})
raise ArgumentError, 'Default params must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
default_options[:default_params] ||= {}
default_options[:default_params].merge!(h)
end | ruby | def default_params(h = {})
raise ArgumentError, 'Default params must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
default_options[:default_params] ||= {}
default_options[:default_params].merge!(h)
end | [
"def",
"default_params",
"(",
"h",
"=",
"{",
"}",
")",
"raise",
"ArgumentError",
",",
"'Default params must be an object which responds to #to_hash'",
"unless",
"h",
".",
"respond_to?",
"(",
":to_hash",
")",
"default_options",
"[",
":default_params",
"]",
"||=",
"{",
"}",
"default_options",
"[",
":default_params",
"]",
".",
"merge!",
"(",
"h",
")",
"end"
] | Allows setting default parameters to be appended to each request.
Great for api keys and such.
class Foo
include HTTParty
default_params api_key: 'secret', another: 'foo'
end | [
"Allows",
"setting",
"default",
"parameters",
"to",
"be",
"appended",
"to",
"each",
"request",
".",
"Great",
"for",
"api",
"keys",
"and",
"such",
"."
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L163-L167 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.headers | def headers(h = nil)
if h
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
default_options[:headers] ||= {}
default_options[:headers].merge!(h.to_hash)
else
default_options[:headers] || {}
end
end | ruby | def headers(h = nil)
if h
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
default_options[:headers] ||= {}
default_options[:headers].merge!(h.to_hash)
else
default_options[:headers] || {}
end
end | [
"def",
"headers",
"(",
"h",
"=",
"nil",
")",
"if",
"h",
"raise",
"ArgumentError",
",",
"'Headers must be an object which responds to #to_hash'",
"unless",
"h",
".",
"respond_to?",
"(",
":to_hash",
")",
"default_options",
"[",
":headers",
"]",
"||=",
"{",
"}",
"default_options",
"[",
":headers",
"]",
".",
"merge!",
"(",
"h",
".",
"to_hash",
")",
"else",
"default_options",
"[",
":headers",
"]",
"||",
"{",
"}",
"end",
"end"
] | Allows setting HTTP headers to be used for each request.
class Foo
include HTTParty
headers 'Accept' => 'text/html'
end | [
"Allows",
"setting",
"HTTP",
"headers",
"to",
"be",
"used",
"for",
"each",
"request",
"."
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L233-L241 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.connection_adapter | def connection_adapter(custom_adapter = nil, options = nil)
if custom_adapter.nil?
default_options[:connection_adapter]
else
default_options[:connection_adapter] = custom_adapter
default_options[:connection_adapter_options] = options
end
end | ruby | def connection_adapter(custom_adapter = nil, options = nil)
if custom_adapter.nil?
default_options[:connection_adapter]
else
default_options[:connection_adapter] = custom_adapter
default_options[:connection_adapter_options] = options
end
end | [
"def",
"connection_adapter",
"(",
"custom_adapter",
"=",
"nil",
",",
"options",
"=",
"nil",
")",
"if",
"custom_adapter",
".",
"nil?",
"default_options",
"[",
":connection_adapter",
"]",
"else",
"default_options",
"[",
":connection_adapter",
"]",
"=",
"custom_adapter",
"default_options",
"[",
":connection_adapter_options",
"]",
"=",
"options",
"end",
"end"
] | Allows setting a custom connection_adapter for the http connections
@example
class Foo
include HTTParty
connection_adapter Proc.new {|uri, options| ... }
end
@example provide optional configuration for your connection_adapter
class Foo
include HTTParty
connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}
end
@see HTTParty::ConnectionAdapter | [
"Allows",
"setting",
"a",
"custom",
"connection_adapter",
"for",
"the",
"http",
"connections"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L485-L492 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.get | def get(path, options = {}, &block)
perform_request Net::HTTP::Get, path, options, &block
end | ruby | def get(path, options = {}, &block)
perform_request Net::HTTP::Get, path, options, &block
end | [
"def",
"get",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Get",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Allows making a get request to a url.
class Foo
include HTTParty
end
# Simple get with full url
Foo.get('http://foo.com/resource.json')
# Simple get with full url and query parameters
# ie: http://foo.com/resource.json?limit=10
Foo.get('http://foo.com/resource.json', query: {limit: 10}) | [
"Allows",
"making",
"a",
"get",
"request",
"to",
"a",
"url",
"."
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L506-L508 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.post | def post(path, options = {}, &block)
perform_request Net::HTTP::Post, path, options, &block
end | ruby | def post(path, options = {}, &block)
perform_request Net::HTTP::Post, path, options, &block
end | [
"def",
"post",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Post",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Allows making a post request to a url.
class Foo
include HTTParty
end
# Simple post with full url and setting the body
Foo.post('http://foo.com/resources', body: {bar: 'baz'})
# Simple post with full url using :query option,
# which appends the parameters to the URI.
Foo.post('http://foo.com/resources', query: {bar: 'baz'}) | [
"Allows",
"making",
"a",
"post",
"request",
"to",
"a",
"url",
"."
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L522-L524 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.patch | def patch(path, options = {}, &block)
perform_request Net::HTTP::Patch, path, options, &block
end | ruby | def patch(path, options = {}, &block)
perform_request Net::HTTP::Patch, path, options, &block
end | [
"def",
"patch",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Patch",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a PATCH request to a path | [
"Perform",
"a",
"PATCH",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L527-L529 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.put | def put(path, options = {}, &block)
perform_request Net::HTTP::Put, path, options, &block
end | ruby | def put(path, options = {}, &block)
perform_request Net::HTTP::Put, path, options, &block
end | [
"def",
"put",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Put",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a PUT request to a path | [
"Perform",
"a",
"PUT",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L532-L534 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.delete | def delete(path, options = {}, &block)
perform_request Net::HTTP::Delete, path, options, &block
end | ruby | def delete(path, options = {}, &block)
perform_request Net::HTTP::Delete, path, options, &block
end | [
"def",
"delete",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Delete",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a DELETE request to a path | [
"Perform",
"a",
"DELETE",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L537-L539 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.move | def move(path, options = {}, &block)
perform_request Net::HTTP::Move, path, options, &block
end | ruby | def move(path, options = {}, &block)
perform_request Net::HTTP::Move, path, options, &block
end | [
"def",
"move",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Move",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a MOVE request to a path | [
"Perform",
"a",
"MOVE",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L542-L544 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.copy | def copy(path, options = {}, &block)
perform_request Net::HTTP::Copy, path, options, &block
end | ruby | def copy(path, options = {}, &block)
perform_request Net::HTTP::Copy, path, options, &block
end | [
"def",
"copy",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Copy",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a COPY request to a path | [
"Perform",
"a",
"COPY",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L547-L549 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.head | def head(path, options = {}, &block)
ensure_method_maintained_across_redirects options
perform_request Net::HTTP::Head, path, options, &block
end | ruby | def head(path, options = {}, &block)
ensure_method_maintained_across_redirects options
perform_request Net::HTTP::Head, path, options, &block
end | [
"def",
"head",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"ensure_method_maintained_across_redirects",
"options",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Head",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a HEAD request to a path | [
"Perform",
"a",
"HEAD",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L552-L555 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.options | def options(path, options = {}, &block)
perform_request Net::HTTP::Options, path, options, &block
end | ruby | def options(path, options = {}, &block)
perform_request Net::HTTP::Options, path, options, &block
end | [
"def",
"options",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Options",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform an OPTIONS request to a path | [
"Perform",
"an",
"OPTIONS",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L558-L560 | train |
jnunemaker/httparty | lib/httparty.rb | HTTParty.ClassMethods.mkcol | def mkcol(path, options = {}, &block)
perform_request Net::HTTP::Mkcol, path, options, &block
end | ruby | def mkcol(path, options = {}, &block)
perform_request Net::HTTP::Mkcol, path, options, &block
end | [
"def",
"mkcol",
"(",
"path",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"perform_request",
"Net",
"::",
"HTTP",
"::",
"Mkcol",
",",
"path",
",",
"options",
",",
"block",
"end"
] | Perform a MKCOL request to a path | [
"Perform",
"a",
"MKCOL",
"request",
"to",
"a",
"path"
] | b4099defba01231d2faaaa2660476f867e096bfb | https://github.com/jnunemaker/httparty/blob/b4099defba01231d2faaaa2660476f867e096bfb/lib/httparty.rb#L563-L565 | train |
sferik/twitter | lib/twitter/utils.rb | Twitter.Utils.flat_pmap | def flat_pmap(enumerable)
return to_enum(:flat_pmap, enumerable) unless block_given?
pmap(enumerable, &Proc.new).flatten(1)
end | ruby | def flat_pmap(enumerable)
return to_enum(:flat_pmap, enumerable) unless block_given?
pmap(enumerable, &Proc.new).flatten(1)
end | [
"def",
"flat_pmap",
"(",
"enumerable",
")",
"return",
"to_enum",
"(",
":flat_pmap",
",",
"enumerable",
")",
"unless",
"block_given?",
"pmap",
"(",
"enumerable",
",",
"Proc",
".",
"new",
")",
".",
"flatten",
"(",
"1",
")",
"end"
] | Returns a new array with the concatenated results of running block once for every element in enumerable.
If no block is given, an enumerator is returned instead.
@param enumerable [Enumerable]
@return [Array, Enumerator] | [
"Returns",
"a",
"new",
"array",
"with",
"the",
"concatenated",
"results",
"of",
"running",
"block",
"once",
"for",
"every",
"element",
"in",
"enumerable",
".",
"If",
"no",
"block",
"is",
"given",
"an",
"enumerator",
"is",
"returned",
"instead",
"."
] | 844818cad07ce490ccb9d8542ebb6b4fc7a61cb4 | https://github.com/sferik/twitter/blob/844818cad07ce490ccb9d8542ebb6b4fc7a61cb4/lib/twitter/utils.rb#L10-L13 | train |
sferik/twitter | lib/twitter/utils.rb | Twitter.Utils.pmap | def pmap(enumerable)
return to_enum(:pmap, enumerable) unless block_given?
if enumerable.count == 1
enumerable.collect { |object| yield(object) }
else
enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
end
end | ruby | def pmap(enumerable)
return to_enum(:pmap, enumerable) unless block_given?
if enumerable.count == 1
enumerable.collect { |object| yield(object) }
else
enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
end
end | [
"def",
"pmap",
"(",
"enumerable",
")",
"return",
"to_enum",
"(",
":pmap",
",",
"enumerable",
")",
"unless",
"block_given?",
"if",
"enumerable",
".",
"count",
"==",
"1",
"enumerable",
".",
"collect",
"{",
"|",
"object",
"|",
"yield",
"(",
"object",
")",
"}",
"else",
"enumerable",
".",
"collect",
"{",
"|",
"object",
"|",
"Thread",
".",
"new",
"{",
"yield",
"(",
"object",
")",
"}",
"}",
".",
"collect",
"(",
":value",
")",
"end",
"end"
] | Returns a new array with the results of running block once for every element in enumerable.
If no block is given, an enumerator is returned instead.
@param enumerable [Enumerable]
@return [Array, Enumerator] | [
"Returns",
"a",
"new",
"array",
"with",
"the",
"results",
"of",
"running",
"block",
"once",
"for",
"every",
"element",
"in",
"enumerable",
".",
"If",
"no",
"block",
"is",
"given",
"an",
"enumerator",
"is",
"returned",
"instead",
"."
] | 844818cad07ce490ccb9d8542ebb6b4fc7a61cb4 | https://github.com/sferik/twitter/blob/844818cad07ce490ccb9d8542ebb6b4fc7a61cb4/lib/twitter/utils.rb#L20-L27 | train |
sferik/twitter | lib/twitter/search_results.rb | Twitter.SearchResults.query_string_to_hash | def query_string_to_hash(query_string)
query = CGI.parse(URI.parse(query_string).query)
Hash[query.collect { |key, value| [key.to_sym, value.first] }]
end | ruby | def query_string_to_hash(query_string)
query = CGI.parse(URI.parse(query_string).query)
Hash[query.collect { |key, value| [key.to_sym, value.first] }]
end | [
"def",
"query_string_to_hash",
"(",
"query_string",
")",
"query",
"=",
"CGI",
".",
"parse",
"(",
"URI",
".",
"parse",
"(",
"query_string",
")",
".",
"query",
")",
"Hash",
"[",
"query",
".",
"collect",
"{",
"|",
"key",
",",
"value",
"|",
"[",
"key",
".",
"to_sym",
",",
"value",
".",
"first",
"]",
"}",
"]",
"end"
] | Converts query string to a hash
@param query_string [String] The query string of a URL.
@return [Hash] The query string converted to a hash (with symbol keys).
@example Convert query string to a hash
query_string_to_hash("foo=bar&baz=qux") #=> {:foo=>"bar", :baz=>"qux"} | [
"Converts",
"query",
"string",
"to",
"a",
"hash"
] | 844818cad07ce490ccb9d8542ebb6b4fc7a61cb4 | https://github.com/sferik/twitter/blob/844818cad07ce490ccb9d8542ebb6b4fc7a61cb4/lib/twitter/search_results.rb#L72-L75 | train |
sferik/twitter | lib/twitter/creatable.rb | Twitter.Creatable.created_at | def created_at
time = @attrs[:created_at]
return if time.nil?
time = Time.parse(time) unless time.is_a?(Time)
time.utc
end | ruby | def created_at
time = @attrs[:created_at]
return if time.nil?
time = Time.parse(time) unless time.is_a?(Time)
time.utc
end | [
"def",
"created_at",
"time",
"=",
"@attrs",
"[",
":created_at",
"]",
"return",
"if",
"time",
".",
"nil?",
"time",
"=",
"Time",
".",
"parse",
"(",
"time",
")",
"unless",
"time",
".",
"is_a?",
"(",
"Time",
")",
"time",
".",
"utc",
"end"
] | Time when the object was created on Twitter
@return [Time] | [
"Time",
"when",
"the",
"object",
"was",
"created",
"on",
"Twitter"
] | 844818cad07ce490ccb9d8542ebb6b4fc7a61cb4 | https://github.com/sferik/twitter/blob/844818cad07ce490ccb9d8542ebb6b4fc7a61cb4/lib/twitter/creatable.rb#L11-L16 | train |
doorkeeper-gem/doorkeeper | lib/doorkeeper/models/access_token_mixin.rb | Doorkeeper.AccessTokenMixin.as_json | def as_json(_options = {})
{
resource_owner_id: resource_owner_id,
scope: scopes,
expires_in: expires_in_seconds,
application: { uid: application.try(:uid) },
created_at: created_at.to_i,
}
end | ruby | def as_json(_options = {})
{
resource_owner_id: resource_owner_id,
scope: scopes,
expires_in: expires_in_seconds,
application: { uid: application.try(:uid) },
created_at: created_at.to_i,
}
end | [
"def",
"as_json",
"(",
"_options",
"=",
"{",
"}",
")",
"{",
"resource_owner_id",
":",
"resource_owner_id",
",",
"scope",
":",
"scopes",
",",
"expires_in",
":",
"expires_in_seconds",
",",
"application",
":",
"{",
"uid",
":",
"application",
".",
"try",
"(",
":uid",
")",
"}",
",",
"created_at",
":",
"created_at",
".",
"to_i",
",",
"}",
"end"
] | JSON representation of the Access Token instance.
@return [Hash] hash with token data | [
"JSON",
"representation",
"of",
"the",
"Access",
"Token",
"instance",
"."
] | f1be81891c3d54a42928c1b9e03c5d6833b8af87 | https://github.com/doorkeeper-gem/doorkeeper/blob/f1be81891c3d54a42928c1b9e03c5d6833b8af87/lib/doorkeeper/models/access_token_mixin.rb#L205-L213 | train |
doorkeeper-gem/doorkeeper | lib/doorkeeper/models/application_mixin.rb | Doorkeeper.ApplicationMixin.secret_matches? | def secret_matches?(input)
# return false if either is nil, since secure_compare depends on strings
# but Application secrets MAY be nil depending on confidentiality.
return false if input.nil? || secret.nil?
# When matching the secret by comparer function, all is well.
return true if secret_strategy.secret_matches?(input, secret)
# When fallback lookup is enabled, ensure applications
# with plain secrets can still be found
if fallback_secret_strategy
fallback_secret_strategy.secret_matches?(input, secret)
else
false
end
end | ruby | def secret_matches?(input)
# return false if either is nil, since secure_compare depends on strings
# but Application secrets MAY be nil depending on confidentiality.
return false if input.nil? || secret.nil?
# When matching the secret by comparer function, all is well.
return true if secret_strategy.secret_matches?(input, secret)
# When fallback lookup is enabled, ensure applications
# with plain secrets can still be found
if fallback_secret_strategy
fallback_secret_strategy.secret_matches?(input, secret)
else
false
end
end | [
"def",
"secret_matches?",
"(",
"input",
")",
"# return false if either is nil, since secure_compare depends on strings",
"# but Application secrets MAY be nil depending on confidentiality.",
"return",
"false",
"if",
"input",
".",
"nil?",
"||",
"secret",
".",
"nil?",
"# When matching the secret by comparer function, all is well.",
"return",
"true",
"if",
"secret_strategy",
".",
"secret_matches?",
"(",
"input",
",",
"secret",
")",
"# When fallback lookup is enabled, ensure applications",
"# with plain secrets can still be found",
"if",
"fallback_secret_strategy",
"fallback_secret_strategy",
".",
"secret_matches?",
"(",
"input",
",",
"secret",
")",
"else",
"false",
"end",
"end"
] | Check whether the given plain text secret matches our stored secret
@param input [#to_s] Plain secret provided by user
(any object that responds to `#to_s`)
@return [true] Whether the given secret matches the stored secret
of this application. | [
"Check",
"whether",
"the",
"given",
"plain",
"text",
"secret",
"matches",
"our",
"stored",
"secret"
] | f1be81891c3d54a42928c1b9e03c5d6833b8af87 | https://github.com/doorkeeper-gem/doorkeeper/blob/f1be81891c3d54a42928c1b9e03c5d6833b8af87/lib/doorkeeper/models/application_mixin.rb#L78-L93 | train |
doorkeeper-gem/doorkeeper | lib/doorkeeper/config.rb | Doorkeeper.Config.validate_reuse_access_token_value | def validate_reuse_access_token_value
strategy = token_secret_strategy
return if !reuse_access_token || strategy.allows_restoring_secrets?
::Rails.logger.warn(
"You have configured both reuse_access_token " \
"AND strategy strategy '#{strategy}' that cannot restore tokens. " \
"This combination is unsupported. reuse_access_token will be disabled"
)
@reuse_access_token = false
end | ruby | def validate_reuse_access_token_value
strategy = token_secret_strategy
return if !reuse_access_token || strategy.allows_restoring_secrets?
::Rails.logger.warn(
"You have configured both reuse_access_token " \
"AND strategy strategy '#{strategy}' that cannot restore tokens. " \
"This combination is unsupported. reuse_access_token will be disabled"
)
@reuse_access_token = false
end | [
"def",
"validate_reuse_access_token_value",
"strategy",
"=",
"token_secret_strategy",
"return",
"if",
"!",
"reuse_access_token",
"||",
"strategy",
".",
"allows_restoring_secrets?",
"::",
"Rails",
".",
"logger",
".",
"warn",
"(",
"\"You have configured both reuse_access_token \"",
"\"AND strategy strategy '#{strategy}' that cannot restore tokens. \"",
"\"This combination is unsupported. reuse_access_token will be disabled\"",
")",
"@reuse_access_token",
"=",
"false",
"end"
] | Determine whether +reuse_access_token+ and a non-restorable
+token_secret_strategy+ have both been activated.
In that case, disable reuse_access_token value and warn the user. | [
"Determine",
"whether",
"+",
"reuse_access_token",
"+",
"and",
"a",
"non",
"-",
"restorable",
"+",
"token_secret_strategy",
"+",
"have",
"both",
"been",
"activated",
"."
] | f1be81891c3d54a42928c1b9e03c5d6833b8af87 | https://github.com/doorkeeper-gem/doorkeeper/blob/f1be81891c3d54a42928c1b9e03c5d6833b8af87/lib/doorkeeper/config.rb#L460-L470 | train |
mikel/mail | lib/mail/network/delivery_methods/smtp.rb | Mail.SMTP.ssl_context | def ssl_context
openssl_verify_mode = settings[:openssl_verify_mode]
if openssl_verify_mode.kind_of?(String)
openssl_verify_mode = OpenSSL::SSL.const_get("VERIFY_#{openssl_verify_mode.upcase}")
end
context = Net::SMTP.default_ssl_context
context.verify_mode = openssl_verify_mode if openssl_verify_mode
context.ca_path = settings[:ca_path] if settings[:ca_path]
context.ca_file = settings[:ca_file] if settings[:ca_file]
context
end | ruby | def ssl_context
openssl_verify_mode = settings[:openssl_verify_mode]
if openssl_verify_mode.kind_of?(String)
openssl_verify_mode = OpenSSL::SSL.const_get("VERIFY_#{openssl_verify_mode.upcase}")
end
context = Net::SMTP.default_ssl_context
context.verify_mode = openssl_verify_mode if openssl_verify_mode
context.ca_path = settings[:ca_path] if settings[:ca_path]
context.ca_file = settings[:ca_file] if settings[:ca_file]
context
end | [
"def",
"ssl_context",
"openssl_verify_mode",
"=",
"settings",
"[",
":openssl_verify_mode",
"]",
"if",
"openssl_verify_mode",
".",
"kind_of?",
"(",
"String",
")",
"openssl_verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
".",
"const_get",
"(",
"\"VERIFY_#{openssl_verify_mode.upcase}\"",
")",
"end",
"context",
"=",
"Net",
"::",
"SMTP",
".",
"default_ssl_context",
"context",
".",
"verify_mode",
"=",
"openssl_verify_mode",
"if",
"openssl_verify_mode",
"context",
".",
"ca_path",
"=",
"settings",
"[",
":ca_path",
"]",
"if",
"settings",
"[",
":ca_path",
"]",
"context",
".",
"ca_file",
"=",
"settings",
"[",
":ca_file",
"]",
"if",
"settings",
"[",
":ca_file",
"]",
"context",
"end"
] | Allow SSL context to be configured via settings, for Ruby >= 1.9
Just returns openssl verify mode for Ruby 1.8.x | [
"Allow",
"SSL",
"context",
"to",
"be",
"configured",
"via",
"settings",
"for",
"Ruby",
">",
"=",
"1",
".",
"9",
"Just",
"returns",
"openssl",
"verify",
"mode",
"for",
"Ruby",
"1",
".",
"8",
".",
"x"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/network/delivery_methods/smtp.rb#L135-L147 | train |
mikel/mail | lib/mail/attachments_list.rb | Mail.AttachmentsList.[] | def [](index_value)
if index_value.is_a?(Integer)
self.fetch(index_value)
else
self.select { |a| a.filename == index_value }.first
end
end | ruby | def [](index_value)
if index_value.is_a?(Integer)
self.fetch(index_value)
else
self.select { |a| a.filename == index_value }.first
end
end | [
"def",
"[]",
"(",
"index_value",
")",
"if",
"index_value",
".",
"is_a?",
"(",
"Integer",
")",
"self",
".",
"fetch",
"(",
"index_value",
")",
"else",
"self",
".",
"select",
"{",
"|",
"a",
"|",
"a",
".",
"filename",
"==",
"index_value",
"}",
".",
"first",
"end",
"end"
] | Returns the attachment by filename or at index.
mail.attachments['test.png'] = File.read('test.png')
mail.attachments['test.jpg'] = File.read('test.jpg')
mail.attachments['test.png'].filename #=> 'test.png'
mail.attachments[1].filename #=> 'test.jpg' | [
"Returns",
"the",
"attachment",
"by",
"filename",
"or",
"at",
"index",
"."
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/attachments_list.rb#L32-L38 | train |
mikel/mail | lib/mail/network/retriever_methods/pop3.rb | Mail.POP3.find | def find(options = nil, &block)
options = validate_options(options)
start do |pop3|
mails = pop3.mails
pop3.reset # Clears all "deleted" marks. This prevents non-explicit/accidental deletions due to server settings.
mails.sort! { |m1, m2| m2.number <=> m1.number } if options[:what] == :last
mails = mails.first(options[:count]) if options[:count].is_a? Integer
if options[:what].to_sym == :last && options[:order].to_sym == :desc ||
options[:what].to_sym == :first && options[:order].to_sym == :asc ||
mails.reverse!
end
if block_given?
mails.each do |mail|
new_message = Mail.new(mail.pop)
new_message.mark_for_delete = true if options[:delete_after_find]
yield new_message
mail.delete if options[:delete_after_find] && new_message.is_marked_for_delete? # Delete if still marked for delete
end
else
emails = []
mails.each do |mail|
emails << Mail.new(mail.pop)
mail.delete if options[:delete_after_find]
end
emails.size == 1 && options[:count] == 1 ? emails.first : emails
end
end
end | ruby | def find(options = nil, &block)
options = validate_options(options)
start do |pop3|
mails = pop3.mails
pop3.reset # Clears all "deleted" marks. This prevents non-explicit/accidental deletions due to server settings.
mails.sort! { |m1, m2| m2.number <=> m1.number } if options[:what] == :last
mails = mails.first(options[:count]) if options[:count].is_a? Integer
if options[:what].to_sym == :last && options[:order].to_sym == :desc ||
options[:what].to_sym == :first && options[:order].to_sym == :asc ||
mails.reverse!
end
if block_given?
mails.each do |mail|
new_message = Mail.new(mail.pop)
new_message.mark_for_delete = true if options[:delete_after_find]
yield new_message
mail.delete if options[:delete_after_find] && new_message.is_marked_for_delete? # Delete if still marked for delete
end
else
emails = []
mails.each do |mail|
emails << Mail.new(mail.pop)
mail.delete if options[:delete_after_find]
end
emails.size == 1 && options[:count] == 1 ? emails.first : emails
end
end
end | [
"def",
"find",
"(",
"options",
"=",
"nil",
",",
"&",
"block",
")",
"options",
"=",
"validate_options",
"(",
"options",
")",
"start",
"do",
"|",
"pop3",
"|",
"mails",
"=",
"pop3",
".",
"mails",
"pop3",
".",
"reset",
"# Clears all \"deleted\" marks. This prevents non-explicit/accidental deletions due to server settings.",
"mails",
".",
"sort!",
"{",
"|",
"m1",
",",
"m2",
"|",
"m2",
".",
"number",
"<=>",
"m1",
".",
"number",
"}",
"if",
"options",
"[",
":what",
"]",
"==",
":last",
"mails",
"=",
"mails",
".",
"first",
"(",
"options",
"[",
":count",
"]",
")",
"if",
"options",
"[",
":count",
"]",
".",
"is_a?",
"Integer",
"if",
"options",
"[",
":what",
"]",
".",
"to_sym",
"==",
":last",
"&&",
"options",
"[",
":order",
"]",
".",
"to_sym",
"==",
":desc",
"||",
"options",
"[",
":what",
"]",
".",
"to_sym",
"==",
":first",
"&&",
"options",
"[",
":order",
"]",
".",
"to_sym",
"==",
":asc",
"||",
"mails",
".",
"reverse!",
"end",
"if",
"block_given?",
"mails",
".",
"each",
"do",
"|",
"mail",
"|",
"new_message",
"=",
"Mail",
".",
"new",
"(",
"mail",
".",
"pop",
")",
"new_message",
".",
"mark_for_delete",
"=",
"true",
"if",
"options",
"[",
":delete_after_find",
"]",
"yield",
"new_message",
"mail",
".",
"delete",
"if",
"options",
"[",
":delete_after_find",
"]",
"&&",
"new_message",
".",
"is_marked_for_delete?",
"# Delete if still marked for delete",
"end",
"else",
"emails",
"=",
"[",
"]",
"mails",
".",
"each",
"do",
"|",
"mail",
"|",
"emails",
"<<",
"Mail",
".",
"new",
"(",
"mail",
".",
"pop",
")",
"mail",
".",
"delete",
"if",
"options",
"[",
":delete_after_find",
"]",
"end",
"emails",
".",
"size",
"==",
"1",
"&&",
"options",
"[",
":count",
"]",
"==",
"1",
"?",
"emails",
".",
"first",
":",
"emails",
"end",
"end",
"end"
] | Find emails in a POP3 mailbox. Without any options, the 5 last received emails are returned.
Possible options:
what: last or first emails. The default is :first.
order: order of emails returned. Possible values are :asc or :desc. Default value is :asc.
count: number of emails to retrieve. The default value is 10. A value of 1 returns an
instance of Message, not an array of Message instances.
delete_after_find: flag for whether to delete each retreived email after find. Default
is false. Use #find_and_delete if you would like this to default to true. | [
"Find",
"emails",
"in",
"a",
"POP3",
"mailbox",
".",
"Without",
"any",
"options",
"the",
"5",
"last",
"received",
"emails",
"are",
"returned",
"."
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/network/retriever_methods/pop3.rb#L60-L91 | train |
mikel/mail | lib/mail/network/retriever_methods/pop3.rb | Mail.POP3.delete_all | def delete_all
start do |pop3|
unless pop3.mails.empty?
pop3.delete_all
pop3.finish
end
end
end | ruby | def delete_all
start do |pop3|
unless pop3.mails.empty?
pop3.delete_all
pop3.finish
end
end
end | [
"def",
"delete_all",
"start",
"do",
"|",
"pop3",
"|",
"unless",
"pop3",
".",
"mails",
".",
"empty?",
"pop3",
".",
"delete_all",
"pop3",
".",
"finish",
"end",
"end",
"end"
] | Delete all emails from a POP3 server | [
"Delete",
"all",
"emails",
"from",
"a",
"POP3",
"server"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/network/retriever_methods/pop3.rb#L94-L101 | train |
mikel/mail | lib/mail/fields/common_address_field.rb | Mail.CommonAddressField.addresses | def addresses
list = element.addresses.map { |a| a.address }
Mail::AddressContainer.new(self, list)
end | ruby | def addresses
list = element.addresses.map { |a| a.address }
Mail::AddressContainer.new(self, list)
end | [
"def",
"addresses",
"list",
"=",
"element",
".",
"addresses",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"address",
"}",
"Mail",
"::",
"AddressContainer",
".",
"new",
"(",
"self",
",",
"list",
")",
"end"
] | Returns the address string of all the addresses in the address list | [
"Returns",
"the",
"address",
"string",
"of",
"all",
"the",
"addresses",
"in",
"the",
"address",
"list"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/fields/common_address_field.rb#L46-L49 | train |
mikel/mail | lib/mail/fields/common_address_field.rb | Mail.CommonAddressField.formatted | def formatted
list = element.addresses.map { |a| a.format }
Mail::AddressContainer.new(self, list)
end | ruby | def formatted
list = element.addresses.map { |a| a.format }
Mail::AddressContainer.new(self, list)
end | [
"def",
"formatted",
"list",
"=",
"element",
".",
"addresses",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"format",
"}",
"Mail",
"::",
"AddressContainer",
".",
"new",
"(",
"self",
",",
"list",
")",
"end"
] | Returns the formatted string of all the addresses in the address list | [
"Returns",
"the",
"formatted",
"string",
"of",
"all",
"the",
"addresses",
"in",
"the",
"address",
"list"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/fields/common_address_field.rb#L52-L55 | train |
mikel/mail | lib/mail/fields/common_address_field.rb | Mail.CommonAddressField.display_names | def display_names
list = element.addresses.map { |a| a.display_name }
Mail::AddressContainer.new(self, list)
end | ruby | def display_names
list = element.addresses.map { |a| a.display_name }
Mail::AddressContainer.new(self, list)
end | [
"def",
"display_names",
"list",
"=",
"element",
".",
"addresses",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"display_name",
"}",
"Mail",
"::",
"AddressContainer",
".",
"new",
"(",
"self",
",",
"list",
")",
"end"
] | Returns the display name of all the addresses in the address list | [
"Returns",
"the",
"display",
"name",
"of",
"all",
"the",
"addresses",
"in",
"the",
"address",
"list"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/fields/common_address_field.rb#L58-L61 | train |
mikel/mail | lib/mail/fields/common_address_field.rb | Mail.CommonAddressField.decoded_group_addresses | def decoded_group_addresses
groups.map { |k,v| v.map { |a| a.decoded } }.flatten
end | ruby | def decoded_group_addresses
groups.map { |k,v| v.map { |a| a.decoded } }.flatten
end | [
"def",
"decoded_group_addresses",
"groups",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"decoded",
"}",
"}",
".",
"flatten",
"end"
] | Returns a list of decoded group addresses | [
"Returns",
"a",
"list",
"of",
"decoded",
"group",
"addresses"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/fields/common_address_field.rb#L80-L82 | train |
mikel/mail | lib/mail/fields/common_address_field.rb | Mail.CommonAddressField.encoded_group_addresses | def encoded_group_addresses
groups.map { |k,v| v.map { |a| a.encoded } }.flatten
end | ruby | def encoded_group_addresses
groups.map { |k,v| v.map { |a| a.encoded } }.flatten
end | [
"def",
"encoded_group_addresses",
"groups",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"map",
"{",
"|",
"a",
"|",
"a",
".",
"encoded",
"}",
"}",
".",
"flatten",
"end"
] | Returns a list of encoded group addresses | [
"Returns",
"a",
"list",
"of",
"encoded",
"group",
"addresses"
] | fb53fb369eb2bf0494ac70675970c90cdcc3f495 | https://github.com/mikel/mail/blob/fb53fb369eb2bf0494ac70675970c90cdcc3f495/lib/mail/fields/common_address_field.rb#L85-L87 | train |
Subsets and Splits