id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
17,900
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb
|
OoxmlParser.DocxShapeProperties.parse
|
def parse(node)
@fill_color = DocxColor.new(parent: self).parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'xfrm'
@shape_size = DocxShapeSize.new(parent: self).parse(node_child)
when 'prstGeom'
@preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
when 'txbx'
@text_box = TextBox.parse_list(node_child)
when 'ln'
@line = DocxShapeLine.new(parent: self).parse(node_child)
when 'blipFill'
@blip_fill = BlipFill.new(parent: self).parse(node_child)
when 'custGeom'
@preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
@preset_geometry.name = :custom
@custom_geometry = OOXMLCustomGeometry.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
@fill_color = DocxColor.new(parent: self).parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'xfrm'
@shape_size = DocxShapeSize.new(parent: self).parse(node_child)
when 'prstGeom'
@preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
when 'txbx'
@text_box = TextBox.parse_list(node_child)
when 'ln'
@line = DocxShapeLine.new(parent: self).parse(node_child)
when 'blipFill'
@blip_fill = BlipFill.new(parent: self).parse(node_child)
when 'custGeom'
@preset_geometry = PresetGeometry.new(parent: self).parse(node_child)
@preset_geometry.name = :custom
@custom_geometry = OOXMLCustomGeometry.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"@fill_color",
"=",
"DocxColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'xfrm'",
"@shape_size",
"=",
"DocxShapeSize",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'prstGeom'",
"@preset_geometry",
"=",
"PresetGeometry",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'txbx'",
"@text_box",
"=",
"TextBox",
".",
"parse_list",
"(",
"node_child",
")",
"when",
"'ln'",
"@line",
"=",
"DocxShapeLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'blipFill'",
"@blip_fill",
"=",
"BlipFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'custGeom'",
"@preset_geometry",
"=",
"PresetGeometry",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"@preset_geometry",
".",
"name",
"=",
":custom",
"@custom_geometry",
"=",
"OOXMLCustomGeometry",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse DocxShapeProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxShapeProperties] result of parsing
|
[
"Parse",
"DocxShapeProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties.rb#L26-L47
|
17,901
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb
|
OoxmlParser.ColorProperties.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'alpha'
@alpha = (node_child.attribute('val').value.to_f / 1_000.0).round
when 'lumMod'
@luminance_modulation = node_child.attribute('val').value.to_f / 100_000.0
when 'lumOff'
@luminance_offset = node_child.attribute('val').value.to_f / 100_000.0
when 'tint'
@tint = node_child.attribute('val').value.to_f / 100_000.0
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'alpha'
@alpha = (node_child.attribute('val').value.to_f / 1_000.0).round
when 'lumMod'
@luminance_modulation = node_child.attribute('val').value.to_f / 100_000.0
when 'lumOff'
@luminance_offset = node_child.attribute('val').value.to_f / 100_000.0
when 'tint'
@tint = node_child.attribute('val').value.to_f / 100_000.0
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'alpha'",
"@alpha",
"=",
"(",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
".",
"to_f",
"/",
"1_000.0",
")",
".",
"round",
"when",
"'lumMod'",
"@luminance_modulation",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
".",
"to_f",
"/",
"100_000.0",
"when",
"'lumOff'",
"@luminance_offset",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
".",
"to_f",
"/",
"100_000.0",
"when",
"'tint'",
"@tint",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
".",
"to_f",
"/",
"100_000.0",
"end",
"end",
"self",
"end"
] |
Parse ColorProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [ColorProperties] result of parsing
|
[
"Parse",
"ColorProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/color_properties.rb#L10-L24
|
17,902
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb
|
OoxmlParser.DocxShapeLine.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = OoxmlSize.new(value.value.to_f, :emu)
when 'cap'
@cap = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'solidFill'
@color_scheme = DocxColorScheme.new(parent: self).parse(node_child)
when 'noFill'
@width = OoxmlSize.new(0)
when 'headEnd'
@head_end = LineEnd.new(parent: self).parse(node_child)
when 'tailEnd'
@tail_end = LineEnd.new(parent: self).parse(node_child)
when 'prstDash'
@dash = ValuedChild.new(:symbol, parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = OoxmlSize.new(value.value.to_f, :emu)
when 'cap'
@cap = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'solidFill'
@color_scheme = DocxColorScheme.new(parent: self).parse(node_child)
when 'noFill'
@width = OoxmlSize.new(0)
when 'headEnd'
@head_end = LineEnd.new(parent: self).parse(node_child)
when 'tailEnd'
@tail_end = LineEnd.new(parent: self).parse(node_child)
when 'prstDash'
@dash = ValuedChild.new(:symbol, parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'w'",
"@width",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"when",
"'cap'",
"@cap",
"=",
"value_to_symbol",
"(",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'solidFill'",
"@color_scheme",
"=",
"DocxColorScheme",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'noFill'",
"@width",
"=",
"OoxmlSize",
".",
"new",
"(",
"0",
")",
"when",
"'headEnd'",
"@head_end",
"=",
"LineEnd",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tailEnd'",
"@tail_end",
"=",
"LineEnd",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'prstDash'",
"@dash",
"=",
"ValuedChild",
".",
"new",
"(",
":symbol",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse DocxShapeLine object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxShapeLine] result of parsing
|
[
"Parse",
"DocxShapeLine",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_line.rb#L33-L58
|
17,903
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/table/table_properties.rb
|
OoxmlParser.TableProperties.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tableStyleId'
@table_style_id = node_child.text
when 'tblBorders'
@table_borders = TableBorders.new(parent: self).parse(node_child)
when 'tblStyle'
# TODO: Incorrect but to keep compatibility
@table_style_element = TableStyle.new(parent: self).parse(node_child)
when 'tblW'
@table_width = OoxmlSize.new.parse(node_child)
when 'jc'
@jc = node_child.attribute('val').text.to_sym
when 'shd'
@shade = Shade.new(parent: self).parse(node_child)
when 'solidFill'
@fill = PresentationFill.new(parent: self).parse(node)
when 'tblLook'
@table_look = TableLook.new(parent: self).parse(node_child)
when 'tblInd'
@table_indent = OoxmlSize.new(node_child.attribute('w').text.to_f)
when 'tblpPr'
@table_positon = TablePosition.new(parent: self).parse(node_child)
when 'tblCellMar'
@table_cell_margin = TableMargins.new(parent: table_properties).parse(node_child)
when 'tblStyleColBandSize'
@table_style_column_band_size = TableStyleColumnBandSize.new(parent: self).parse(node_child)
when 'tblStyleRowBandSize'
@table_style_row_band_size = TableStyleRowBandSize.new(parent: self).parse(node_child)
when 'tblLayout'
@table_layout = TableLayout.new(parent: self).parse(node_child)
when 'tblCellSpacing'
@table_cell_spacing = OoxmlSize.new.parse(node_child)
when 'tblCaption'
@caption = ValuedChild.new(:string, parent: self).parse(node_child)
when 'tblDescription'
@description = ValuedChild.new(:string, parent: self).parse(node_child)
end
end
@table_look = TableLook.new(parent: self).parse(node) if @table_look.nil?
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tableStyleId'
@table_style_id = node_child.text
when 'tblBorders'
@table_borders = TableBorders.new(parent: self).parse(node_child)
when 'tblStyle'
# TODO: Incorrect but to keep compatibility
@table_style_element = TableStyle.new(parent: self).parse(node_child)
when 'tblW'
@table_width = OoxmlSize.new.parse(node_child)
when 'jc'
@jc = node_child.attribute('val').text.to_sym
when 'shd'
@shade = Shade.new(parent: self).parse(node_child)
when 'solidFill'
@fill = PresentationFill.new(parent: self).parse(node)
when 'tblLook'
@table_look = TableLook.new(parent: self).parse(node_child)
when 'tblInd'
@table_indent = OoxmlSize.new(node_child.attribute('w').text.to_f)
when 'tblpPr'
@table_positon = TablePosition.new(parent: self).parse(node_child)
when 'tblCellMar'
@table_cell_margin = TableMargins.new(parent: table_properties).parse(node_child)
when 'tblStyleColBandSize'
@table_style_column_band_size = TableStyleColumnBandSize.new(parent: self).parse(node_child)
when 'tblStyleRowBandSize'
@table_style_row_band_size = TableStyleRowBandSize.new(parent: self).parse(node_child)
when 'tblLayout'
@table_layout = TableLayout.new(parent: self).parse(node_child)
when 'tblCellSpacing'
@table_cell_spacing = OoxmlSize.new.parse(node_child)
when 'tblCaption'
@caption = ValuedChild.new(:string, parent: self).parse(node_child)
when 'tblDescription'
@description = ValuedChild.new(:string, parent: self).parse(node_child)
end
end
@table_look = TableLook.new(parent: self).parse(node) if @table_look.nil?
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'tableStyleId'",
"@table_style_id",
"=",
"node_child",
".",
"text",
"when",
"'tblBorders'",
"@table_borders",
"=",
"TableBorders",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblStyle'",
"# TODO: Incorrect but to keep compatibility",
"@table_style_element",
"=",
"TableStyle",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblW'",
"@table_width",
"=",
"OoxmlSize",
".",
"new",
".",
"parse",
"(",
"node_child",
")",
"when",
"'jc'",
"@jc",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"text",
".",
"to_sym",
"when",
"'shd'",
"@shade",
"=",
"Shade",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'solidFill'",
"@fill",
"=",
"PresentationFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"when",
"'tblLook'",
"@table_look",
"=",
"TableLook",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblInd'",
"@table_indent",
"=",
"OoxmlSize",
".",
"new",
"(",
"node_child",
".",
"attribute",
"(",
"'w'",
")",
".",
"text",
".",
"to_f",
")",
"when",
"'tblpPr'",
"@table_positon",
"=",
"TablePosition",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblCellMar'",
"@table_cell_margin",
"=",
"TableMargins",
".",
"new",
"(",
"parent",
":",
"table_properties",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblStyleColBandSize'",
"@table_style_column_band_size",
"=",
"TableStyleColumnBandSize",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblStyleRowBandSize'",
"@table_style_row_band_size",
"=",
"TableStyleRowBandSize",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblLayout'",
"@table_layout",
"=",
"TableLayout",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblCellSpacing'",
"@table_cell_spacing",
"=",
"OoxmlSize",
".",
"new",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblCaption'",
"@caption",
"=",
"ValuedChild",
".",
"new",
"(",
":string",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tblDescription'",
"@description",
"=",
"ValuedChild",
".",
"new",
"(",
":string",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"@table_look",
"=",
"TableLook",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"if",
"@table_look",
".",
"nil?",
"self",
"end"
] |
Parse TableProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [TableProperties] result of parsing
|
[
"Parse",
"TableProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/table_properties.rb#L47-L89
|
17,904
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data.rb
|
OoxmlParser.CommonSlideData.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'spTree'
@shape_tree = ShapeTree.new(parent: self).parse(node_child)
when 'bg'
@background = Background.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'spTree'
@shape_tree = ShapeTree.new(parent: self).parse(node_child)
when 'bg'
@background = Background.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'spTree'",
"@shape_tree",
"=",
"ShapeTree",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bg'",
"@background",
"=",
"Background",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse CommonSlideData object
@param node [Nokogiri::XML:Element] node to parse
@return [CommonSlideData] result of parsing
|
[
"Parse",
"CommonSlideData",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/common_slide_data.rb#L14-L24
|
17,905
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line.rb
|
OoxmlParser.TableCellLine.parse
|
def parse(node)
@fill = PresentationFill.new(parent: self).parse(node)
@line_join = LineJoin.new(parent: self).parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = OoxmlSize.new(value.value.to_f, :emu)
when 'algn'
@align = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'headEnd'
@head_end = LineEnd.new(parent: self).parse(node_child)
when 'tailEnd'
@tail_end = LineEnd.new(parent: self).parse(node_child)
when 'ln'
return TableCellLine.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
@fill = PresentationFill.new(parent: self).parse(node)
@line_join = LineJoin.new(parent: self).parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = OoxmlSize.new(value.value.to_f, :emu)
when 'algn'
@align = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'headEnd'
@head_end = LineEnd.new(parent: self).parse(node_child)
when 'tailEnd'
@tail_end = LineEnd.new(parent: self).parse(node_child)
when 'ln'
return TableCellLine.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"@fill",
"=",
"PresentationFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"@line_join",
"=",
"LineJoin",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'w'",
"@width",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"when",
"'algn'",
"@align",
"=",
"value_to_symbol",
"(",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'headEnd'",
"@head_end",
"=",
"LineEnd",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tailEnd'",
"@tail_end",
"=",
"LineEnd",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'ln'",
"return",
"TableCellLine",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse TableCellLine object
@param node [Nokogiri::XML:Element] node to parse
@return [TableCellLine] result of parsing
|
[
"Parse",
"TableCellLine",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/row/cell/properties/table_cell_line.rb#L16-L39
|
17,906
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb
|
OoxmlParser.DocxShape.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'nvSpPr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
when 'spPr'
@properties = DocxShapeProperties.new(parent: self).parse(node_child)
when 'txbx'
@text_body = OOXMLTextBox.new(parent: self).parse(node_child)
when 'txBody'
@text_body = TextBody.new(parent: self).parse(node_child)
when 'bodyPr'
@body_properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'nvSpPr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
when 'spPr'
@properties = DocxShapeProperties.new(parent: self).parse(node_child)
when 'txbx'
@text_body = OOXMLTextBox.new(parent: self).parse(node_child)
when 'txBody'
@text_body = TextBody.new(parent: self).parse(node_child)
when 'bodyPr'
@body_properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'nvSpPr'",
"@non_visual_properties",
"=",
"NonVisualShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'spPr'",
"@properties",
"=",
"DocxShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'txbx'",
"@text_body",
"=",
"OOXMLTextBox",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'txBody'",
"@text_body",
"=",
"TextBody",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bodyPr'",
"@body_properties",
"=",
"OOXMLShapeBodyProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse DocxShape object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxShape] result of parsing
|
[
"Parse",
"DocxShape",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape.rb#L26-L42
|
17,907
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb
|
OoxmlParser.SDTContent.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'p'
@elements << DocxParagraph.new(parent: self).parse(node_child)
when 'r'
@elements << ParagraphRun.new(parent: self).parse(node_child)
when 'tbl'
@elements << Table.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'p'
@elements << DocxParagraph.new(parent: self).parse(node_child)
when 'r'
@elements << ParagraphRun.new(parent: self).parse(node_child)
when 'tbl'
@elements << Table.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'p'",
"@elements",
"<<",
"DocxParagraph",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'r'",
"@elements",
"<<",
"ParagraphRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tbl'",
"@elements",
"<<",
"Table",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse SDTContent object
@param node [Nokogiri::XML:Element] node to parse
@return [SDTContent] result of parsing
|
[
"Parse",
"SDTContent",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/sdt/sdt_content.rb#L15-L27
|
17,908
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing.rb
|
OoxmlParser.CommonTiming.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'dur'
@duration = value.value
when 'restart'
@restart = value.value
when 'id'
@id = value.value
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'stCondLst'
@start_conditions = ConditionList.new(parent: self).parse(node_child)
when 'endCondLst'
@end_conditions = ConditionList.new(parent: self).parse(node_child)
when 'childTnLst'
@children = TimeNode.parse_list(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'dur'
@duration = value.value
when 'restart'
@restart = value.value
when 'id'
@id = value.value
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'stCondLst'
@start_conditions = ConditionList.new(parent: self).parse(node_child)
when 'endCondLst'
@end_conditions = ConditionList.new(parent: self).parse(node_child)
when 'childTnLst'
@children = TimeNode.parse_list(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'dur'",
"@duration",
"=",
"value",
".",
"value",
"when",
"'restart'",
"@restart",
"=",
"value",
".",
"value",
"when",
"'id'",
"@id",
"=",
"value",
".",
"value",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'stCondLst'",
"@start_conditions",
"=",
"ConditionList",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'endCondLst'",
"@end_conditions",
"=",
"ConditionList",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'childTnLst'",
"@children",
"=",
"TimeNode",
".",
"parse_list",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse CommonTiming object
@param node [Nokogiri::XML:Element] node to parse
@return [CommonTiming] result of parsing
|
[
"Parse",
"CommonTiming",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing/time_node/common_timing.rb#L16-L39
|
17,909
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/ooxml_custom_geometry.rb
|
OoxmlParser.OOXMLCustomGeometry.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'pathLst'
node_child.xpath('a:path', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').each do |path_node|
@paths_list << DocxShapeLinePath.new(parent: self).parse(path_node)
end
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'pathLst'
node_child.xpath('a:path', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').each do |path_node|
@paths_list << DocxShapeLinePath.new(parent: self).parse(path_node)
end
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'pathLst'",
"node_child",
".",
"xpath",
"(",
"'a:path'",
",",
"'xmlns:a'",
"=>",
"'http://schemas.openxmlformats.org/drawingml/2006/main'",
")",
".",
"each",
"do",
"|",
"path_node",
"|",
"@paths_list",
"<<",
"DocxShapeLinePath",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"path_node",
")",
"end",
"end",
"end",
"self",
"end"
] |
Parse OOXMLCustomGeometry object
@param node [Nokogiri::XML:Element] node to parse
@return [OOXMLCustomGeometry] result of parsing
|
[
"Parse",
"OOXMLCustomGeometry",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/ooxml_custom_geometry.rb#L15-L25
|
17,910
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb
|
OoxmlParser.OldDocxPicture.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'shape'
@type = :shape
@data = OldDocxShape.new(parent: self).parse(node_child)
when 'group'
@type = :group
@data = OldDocxGroup.new(parent: self).parse(node_child)
when 'style'
@style_number = node_child.attribute('val').value.to_i
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'shape'
@type = :shape
@data = OldDocxShape.new(parent: self).parse(node_child)
when 'group'
@type = :group
@data = OldDocxGroup.new(parent: self).parse(node_child)
when 'style'
@style_number = node_child.attribute('val').value.to_i
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'shape'",
"@type",
"=",
":shape",
"@data",
"=",
"OldDocxShape",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'group'",
"@type",
"=",
":group",
"@data",
"=",
"OldDocxGroup",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'style'",
"@style_number",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
".",
"to_i",
"end",
"end",
"self",
"end"
] |
Parse OldDocxPicture object
@param node [Nokogiri::XML:Element] node to parse
@return [OldDocxPicture] result of parsing
|
[
"Parse",
"OldDocxPicture",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/old_docx_picture.rb#L12-L26
|
17,911
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula.rb
|
OoxmlParser.DocxFormula.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'r'
@formula_run << MathRun.new(parent: self).parse(node_child)
when 'box', 'borderBox'
@formula_run << Box.new(parent: self).parse(node_child)
when 'func'
@formula_run << Function.new(parent: self).parse(node_child)
when 'rad'
@formula_run << Radical.new(parent: self).parse(node_child)
when 'e', 'eqArr'
@formula_run << DocxFormula.new(parent: self).parse(node_child)
when 'nary'
@formula_run << Nary.new(parent: self).parse(node_child)
when 'd'
@formula_run << Delimiter.new(parent: self).parse(node_child)
when 'sSubSup', 'sSup', 'sSub'
@formula_run << Index.new(parent: self).parse(node_child)
when 'f'
@formula_run << Fraction.new(parent: self).parse(node_child)
when 'm'
@formula_run << Matrix.new(parent: self).parse(node_child)
when 'bar'
@formula_run << Bar.new(parent: self).parse(node_child)
when 'acc'
@formula_run << Accent.new(parent: self).parse(node_child)
when 'groupChr'
@formula_run << GroupChar.new(parent: self).parse(node_child)
when 'argPr'
@argument_properties = ArgumentProperties.new(parent: self).parse(node_child)
when 'sPre'
@formula_run << PreSubSuperscript.new(parent: self).parse(node_child)
when 'limUpp', 'limLow'
@formula_run << Limit.new(parent: self).parse(node_child)
end
end
return nil if @formula_run.empty?
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'r'
@formula_run << MathRun.new(parent: self).parse(node_child)
when 'box', 'borderBox'
@formula_run << Box.new(parent: self).parse(node_child)
when 'func'
@formula_run << Function.new(parent: self).parse(node_child)
when 'rad'
@formula_run << Radical.new(parent: self).parse(node_child)
when 'e', 'eqArr'
@formula_run << DocxFormula.new(parent: self).parse(node_child)
when 'nary'
@formula_run << Nary.new(parent: self).parse(node_child)
when 'd'
@formula_run << Delimiter.new(parent: self).parse(node_child)
when 'sSubSup', 'sSup', 'sSub'
@formula_run << Index.new(parent: self).parse(node_child)
when 'f'
@formula_run << Fraction.new(parent: self).parse(node_child)
when 'm'
@formula_run << Matrix.new(parent: self).parse(node_child)
when 'bar'
@formula_run << Bar.new(parent: self).parse(node_child)
when 'acc'
@formula_run << Accent.new(parent: self).parse(node_child)
when 'groupChr'
@formula_run << GroupChar.new(parent: self).parse(node_child)
when 'argPr'
@argument_properties = ArgumentProperties.new(parent: self).parse(node_child)
when 'sPre'
@formula_run << PreSubSuperscript.new(parent: self).parse(node_child)
when 'limUpp', 'limLow'
@formula_run << Limit.new(parent: self).parse(node_child)
end
end
return nil if @formula_run.empty?
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'r'",
"@formula_run",
"<<",
"MathRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'box'",
",",
"'borderBox'",
"@formula_run",
"<<",
"Box",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'func'",
"@formula_run",
"<<",
"Function",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'rad'",
"@formula_run",
"<<",
"Radical",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'e'",
",",
"'eqArr'",
"@formula_run",
"<<",
"DocxFormula",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'nary'",
"@formula_run",
"<<",
"Nary",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'d'",
"@formula_run",
"<<",
"Delimiter",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'sSubSup'",
",",
"'sSup'",
",",
"'sSub'",
"@formula_run",
"<<",
"Index",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'f'",
"@formula_run",
"<<",
"Fraction",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'m'",
"@formula_run",
"<<",
"Matrix",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bar'",
"@formula_run",
"<<",
"Bar",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'acc'",
"@formula_run",
"<<",
"Accent",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'groupChr'",
"@formula_run",
"<<",
"GroupChar",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'argPr'",
"@argument_properties",
"=",
"ArgumentProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'sPre'",
"@formula_run",
"<<",
"PreSubSuperscript",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'limUpp'",
",",
"'limLow'",
"@formula_run",
"<<",
"Limit",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"return",
"nil",
"if",
"@formula_run",
".",
"empty?",
"self",
"end"
] |
Parse DocxFormula object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxFormula] result of parsing
|
[
"Parse",
"DocxFormula",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula.rb#L31-L71
|
17,912
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/non_visual_shape_properties.rb
|
OoxmlParser.NonVisualShapeProperties.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'cNvPr'
@common_properties = CommonNonVisualProperties.new(parent: self).parse(node_child)
when 'nvPr'
@non_visual_properties = NonVisualProperties.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'cNvPr'
@common_properties = CommonNonVisualProperties.new(parent: self).parse(node_child)
when 'nvPr'
@non_visual_properties = NonVisualProperties.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'cNvPr'",
"@common_properties",
"=",
"CommonNonVisualProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'nvPr'",
"@non_visual_properties",
"=",
"NonVisualProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse NonVisualShapeProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [NonVisualShapeProperties] result of parsing
|
[
"Parse",
"NonVisualShapeProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/non_visual_shape_properties.rb#L10-L20
|
17,913
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb
|
OoxmlParser.XlsxColumnProperties.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'min'
@from = value.value.to_i
when 'max'
@to = value.value.to_i
when 'style'
@style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
when 'width'
@width = value.value.to_f - 0.7109375
when 'customWidth'
@custom_width = option_enabled?(node, 'customWidth')
when 'bestFit'
@best_fit = attribute_enabled?(value)
when 'hidden'
@hidden = attribute_enabled?(value)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'min'
@from = value.value.to_i
when 'max'
@to = value.value.to_i
when 'style'
@style = root_object.style_sheet.cell_xfs.xf_array[value.value.to_i]
when 'width'
@width = value.value.to_f - 0.7109375
when 'customWidth'
@custom_width = option_enabled?(node, 'customWidth')
when 'bestFit'
@best_fit = attribute_enabled?(value)
when 'hidden'
@hidden = attribute_enabled?(value)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'min'",
"@from",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'max'",
"@to",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'style'",
"@style",
"=",
"root_object",
".",
"style_sheet",
".",
"cell_xfs",
".",
"xf_array",
"[",
"value",
".",
"value",
".",
"to_i",
"]",
"when",
"'width'",
"@width",
"=",
"value",
".",
"value",
".",
"to_f",
"-",
"0.7109375",
"when",
"'customWidth'",
"@custom_width",
"=",
"option_enabled?",
"(",
"node",
",",
"'customWidth'",
")",
"when",
"'bestFit'",
"@best_fit",
"=",
"attribute_enabled?",
"(",
"value",
")",
"when",
"'hidden'",
"@hidden",
"=",
"attribute_enabled?",
"(",
"value",
")",
"end",
"end",
"self",
"end"
] |
Parse XlsxColumnProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxColumnProperties] result of parsing
|
[
"Parse",
"XlsxColumnProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_column_properties.rb#L17-L37
|
17,914
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb
|
OoxmlParser.OOXMLTextBox.parse
|
def parse(node)
text_box_content_node = node.xpath('w:txbxContent').first
text_box_content_node.xpath('*').each_with_index do |node_child, index|
case node_child.name
when 'p'
@elements << DocxParagraph.new(parent: self).parse(node_child, index)
when 'tbl'
@elements << Table.new(parent: self).parse(node_child, index)
when 'bodyPr'
@properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
text_box_content_node = node.xpath('w:txbxContent').first
text_box_content_node.xpath('*').each_with_index do |node_child, index|
case node_child.name
when 'p'
@elements << DocxParagraph.new(parent: self).parse(node_child, index)
when 'tbl'
@elements << Table.new(parent: self).parse(node_child, index)
when 'bodyPr'
@properties = OOXMLShapeBodyProperties.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"text_box_content_node",
"=",
"node",
".",
"xpath",
"(",
"'w:txbxContent'",
")",
".",
"first",
"text_box_content_node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each_with_index",
"do",
"|",
"node_child",
",",
"index",
"|",
"case",
"node_child",
".",
"name",
"when",
"'p'",
"@elements",
"<<",
"DocxParagraph",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
",",
"index",
")",
"when",
"'tbl'",
"@elements",
"<<",
"Table",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
",",
"index",
")",
"when",
"'bodyPr'",
"@properties",
"=",
"OOXMLShapeBodyProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse OOXMLTextBox object
@param node [Nokogiri::XML:Element] node to parse
@return [OOXMLTextBox] result of parsing
|
[
"Parse",
"OOXMLTextBox",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/docx_shape/ooxml_text_box.rb#L14-L27
|
17,915
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style/document_style_helper.rb
|
OoxmlParser.DocumentStyleHelper.document_style_by_name
|
def document_style_by_name(name)
root_object.document_styles.each do |style|
return style if style.name == name
end
nil
end
|
ruby
|
def document_style_by_name(name)
root_object.document_styles.each do |style|
return style if style.name == name
end
nil
end
|
[
"def",
"document_style_by_name",
"(",
"name",
")",
"root_object",
".",
"document_styles",
".",
"each",
"do",
"|",
"style",
"|",
"return",
"style",
"if",
"style",
".",
"name",
"==",
"name",
"end",
"nil",
"end"
] |
Return document style by its name
@param name [String] name of style
@return [DocumentStyle, nil]
|
[
"Return",
"document",
"style",
"by",
"its",
"name"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style/document_style_helper.rb#L7-L12
|
17,916
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style/document_style_helper.rb
|
OoxmlParser.DocumentStyleHelper.document_style_by_id
|
def document_style_by_id(id)
root_object.document_styles.each do |style|
return style if style.style_id == id
end
nil
end
|
ruby
|
def document_style_by_id(id)
root_object.document_styles.each do |style|
return style if style.style_id == id
end
nil
end
|
[
"def",
"document_style_by_id",
"(",
"id",
")",
"root_object",
".",
"document_styles",
".",
"each",
"do",
"|",
"style",
"|",
"return",
"style",
"if",
"style",
".",
"style_id",
"==",
"id",
"end",
"nil",
"end"
] |
Return document style by its id
@param id [String] id of style
@return [DocumentStyle, nil]
|
[
"Return",
"document",
"style",
"by",
"its",
"id"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style/document_style_helper.rb#L17-L22
|
17,917
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/box.rb
|
OoxmlParser.Box.parse
|
def parse(node)
@borders = true if node.name == 'borderBox'
@element = MathRun.new(parent: self).parse(node)
self
end
|
ruby
|
def parse(node)
@borders = true if node.name == 'borderBox'
@element = MathRun.new(parent: self).parse(node)
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"@borders",
"=",
"true",
"if",
"node",
".",
"name",
"==",
"'borderBox'",
"@element",
"=",
"MathRun",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"self",
"end"
] |
Parse Box object
@param node [Nokogiri::XML:Element] node to parse
@return [Box] result of parsing
|
[
"Parse",
"Box",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/docx_formula/box.rb#L14-L18
|
17,918
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb
|
OoxmlParser.ImageFill.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blip'
@file_reference = FileReference.new(parent: self).parse(node_child)
when 'tile'
@tile = Tile.new(OOXMLCoordinates.parse(node_child, x_attr: 'tx', y_attr: 'ty'),
OOXMLCoordinates.parse(node_child, x_attr: 'sx', y_attr: 'sy'),
parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'blip'
@file_reference = FileReference.new(parent: self).parse(node_child)
when 'tile'
@tile = Tile.new(OOXMLCoordinates.parse(node_child, x_attr: 'tx', y_attr: 'ty'),
OOXMLCoordinates.parse(node_child, x_attr: 'sx', y_attr: 'sy'),
parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'blip'",
"@file_reference",
"=",
"FileReference",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tile'",
"@tile",
"=",
"Tile",
".",
"new",
"(",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"x_attr",
":",
"'tx'",
",",
"y_attr",
":",
"'ty'",
")",
",",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"x_attr",
":",
"'sx'",
",",
"y_attr",
":",
"'sy'",
")",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse ImageFill object
@param node [Nokogiri::XML:Element] node to parse
@return [ImageFill] result of parsing
|
[
"Parse",
"ImageFill",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/image_fill.rb#L16-L28
|
17,919
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing.rb
|
OoxmlParser.Timing.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tnLst'
@time_node_list = TimeNode.parse_list(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'tnLst'
@time_node_list = TimeNode.parse_list(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'tnLst'",
"@time_node_list",
"=",
"TimeNode",
".",
"parse_list",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse Timing object
@param node [Nokogiri::XML:Element] node to parse
@return [Timing] result of parsing
|
[
"Parse",
"Timing",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/slide/timing.rb#L17-L25
|
17,920
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/style_parametres.rb
|
OoxmlParser.StyleParametres.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'name'
@name = node_child.attribute('val').value
when 'qFormat'
@q_format = option_enabled?(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'name'
@name = node_child.attribute('val').value
when 'qFormat'
@q_format = option_enabled?(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'name'",
"@name",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'qFormat'",
"@q_format",
"=",
"option_enabled?",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse StyleParametres data
@param [Nokogiri::XML:Element] node with StyleParametres data
@return [StyleParametres] value of Columns data
|
[
"Parse",
"StyleParametres",
"data"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/docx_paragraph/style_parametres.rb#L19-L29
|
17,921
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb
|
OoxmlParser.Spacing.parse
|
def parse(node)
node.xpath('*').each do |spacing_node_child|
case spacing_node_child.name
when 'lnSpc'
self.line = Spacing.parse_spacing_value(spacing_node_child)
self.line_rule = Spacing.parse_spacing_rule(spacing_node_child)
when 'spcBef'
self.before = Spacing.parse_spacing_value(spacing_node_child)
when 'spcAft'
self.after = Spacing.parse_spacing_value(spacing_node_child)
end
end
end
|
ruby
|
def parse(node)
node.xpath('*').each do |spacing_node_child|
case spacing_node_child.name
when 'lnSpc'
self.line = Spacing.parse_spacing_value(spacing_node_child)
self.line_rule = Spacing.parse_spacing_rule(spacing_node_child)
when 'spcBef'
self.before = Spacing.parse_spacing_value(spacing_node_child)
when 'spcAft'
self.after = Spacing.parse_spacing_value(spacing_node_child)
end
end
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"spacing_node_child",
"|",
"case",
"spacing_node_child",
".",
"name",
"when",
"'lnSpc'",
"self",
".",
"line",
"=",
"Spacing",
".",
"parse_spacing_value",
"(",
"spacing_node_child",
")",
"self",
".",
"line_rule",
"=",
"Spacing",
".",
"parse_spacing_rule",
"(",
"spacing_node_child",
")",
"when",
"'spcBef'",
"self",
".",
"before",
"=",
"Spacing",
".",
"parse_spacing_value",
"(",
"spacing_node_child",
")",
"when",
"'spcAft'",
"self",
".",
"after",
"=",
"Spacing",
".",
"parse_spacing_value",
"(",
"spacing_node_child",
")",
"end",
"end",
"end"
] |
Parse data for Spacing
@param [Nokogiri::XML:Element] node with Spacing
@return [Nothing]
|
[
"Parse",
"data",
"for",
"Spacing"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/paragrpah_properties/spacing.rb#L71-L83
|
17,922
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/gradient_stop.rb
|
OoxmlParser.GradientStop.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'pos'
@position = value.value.to_i / 1_000
end
end
node.xpath('*').each do |node_child|
@color = case node_child.name
when 'prstClr'
ValuedChild.new(:string, parent: self).parse(node_child)
else
Color.new(parent: self).parse_color(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'pos'
@position = value.value.to_i / 1_000
end
end
node.xpath('*').each do |node_child|
@color = case node_child.name
when 'prstClr'
ValuedChild.new(:string, parent: self).parse(node_child)
else
Color.new(parent: self).parse_color(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'pos'",
"@position",
"=",
"value",
".",
"value",
".",
"to_i",
"/",
"1_000",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"@color",
"=",
"case",
"node_child",
".",
"name",
"when",
"'prstClr'",
"ValuedChild",
".",
"new",
"(",
":string",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"else",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse GradientStop object
@param node [Nokogiri::XML:Element] node to parse
@return [GradientStop] result of parsing
|
[
"Parse",
"GradientStop",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill/gradient_color/gradient_stop.rb#L8-L25
|
17,923
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/blip_fill/blip/alpha_mod_fix.rb
|
OoxmlParser.AlphaModFix.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'amt'
@amount = OoxmlSize.new(value.value.to_f, :one_1000th_percent)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'amt'
@amount = OoxmlSize.new(value.value.to_f, :one_1000th_percent)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'amt'",
"@amount",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":one_1000th_percent",
")",
"end",
"end",
"self",
"end"
] |
Parse AlphaModFix object
@param node [Nokogiri::XML:Element] node to parse
@return [AlphaModFix] result of parsing
|
[
"Parse",
"AlphaModFix",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_properties/blip_fill/blip/alpha_mod_fix.rb#L9-L17
|
17,924
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb
|
OoxmlParser.TablePart.parse
|
def parse(node)
link_to_table_part_xml = OOXMLDocumentObject.get_link_from_rels(node.attribute('id').value)
doc = parse_xml(OOXMLDocumentObject.path_to_folder + link_to_table_part_xml.gsub('..', 'xl'))
table_node = doc.xpath('xmlns:table').first
table_node.attributes.each do |key, value|
case key
when 'name'
@name = value.value.to_s
when 'displayName'
@display_name = value.value.to_s
when 'ref'
@reference = Coordinates.parser_coordinates_range value.value.to_s
end
end
table_node.xpath('*').each do |node_child|
case node_child.name
when 'autoFilter'
@autofilter = Autofilter.new(parent: self).parse(node_child)
when 'extLst'
@extension_list = ExtensionList.new(parent: self).parse(node_child)
when 'tableColumns'
@table_columns = TableColumns.new(parent: self).parse(node_child)
when 'tableStyleInfo'
@table_style_info = TableStyleInfo.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
link_to_table_part_xml = OOXMLDocumentObject.get_link_from_rels(node.attribute('id').value)
doc = parse_xml(OOXMLDocumentObject.path_to_folder + link_to_table_part_xml.gsub('..', 'xl'))
table_node = doc.xpath('xmlns:table').first
table_node.attributes.each do |key, value|
case key
when 'name'
@name = value.value.to_s
when 'displayName'
@display_name = value.value.to_s
when 'ref'
@reference = Coordinates.parser_coordinates_range value.value.to_s
end
end
table_node.xpath('*').each do |node_child|
case node_child.name
when 'autoFilter'
@autofilter = Autofilter.new(parent: self).parse(node_child)
when 'extLst'
@extension_list = ExtensionList.new(parent: self).parse(node_child)
when 'tableColumns'
@table_columns = TableColumns.new(parent: self).parse(node_child)
when 'tableStyleInfo'
@table_style_info = TableStyleInfo.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"link_to_table_part_xml",
"=",
"OOXMLDocumentObject",
".",
"get_link_from_rels",
"(",
"node",
".",
"attribute",
"(",
"'id'",
")",
".",
"value",
")",
"doc",
"=",
"parse_xml",
"(",
"OOXMLDocumentObject",
".",
"path_to_folder",
"+",
"link_to_table_part_xml",
".",
"gsub",
"(",
"'..'",
",",
"'xl'",
")",
")",
"table_node",
"=",
"doc",
".",
"xpath",
"(",
"'xmlns:table'",
")",
".",
"first",
"table_node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'name'",
"@name",
"=",
"value",
".",
"value",
".",
"to_s",
"when",
"'displayName'",
"@display_name",
"=",
"value",
".",
"value",
".",
"to_s",
"when",
"'ref'",
"@reference",
"=",
"Coordinates",
".",
"parser_coordinates_range",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"table_node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'autoFilter'",
"@autofilter",
"=",
"Autofilter",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'extLst'",
"@extension_list",
"=",
"ExtensionList",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tableColumns'",
"@table_columns",
"=",
"TableColumns",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tableStyleInfo'",
"@table_style_info",
"=",
"TableStyleInfo",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse TablePart object
@param node [Nokogiri::XML:Element] node to parse
@return [TablePart] result of parsing
|
[
"Parse",
"TablePart",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/table_part.rb#L19-L46
|
17,925
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb
|
OoxmlParser.SheetView.parse
|
def parse(node)
node.attributes.each_key do |key|
case key
when 'showGridLines'
@show_gridlines = attribute_enabled?(node, key)
when 'showRowColHeaders'
@show_row_column_headers = attribute_enabled?(node, key)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'pane'
@pane = Pane.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each_key do |key|
case key
when 'showGridLines'
@show_gridlines = attribute_enabled?(node, key)
when 'showRowColHeaders'
@show_row_column_headers = attribute_enabled?(node, key)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'pane'
@pane = Pane.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each_key",
"do",
"|",
"key",
"|",
"case",
"key",
"when",
"'showGridLines'",
"@show_gridlines",
"=",
"attribute_enabled?",
"(",
"node",
",",
"key",
")",
"when",
"'showRowColHeaders'",
"@show_row_column_headers",
"=",
"attribute_enabled?",
"(",
"node",
",",
"key",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'pane'",
"@pane",
"=",
"Pane",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse SheetView object
@param node [Nokogiri::XML:Element] node to parse
@return [SheetView] result of parsing
|
[
"Parse",
"SheetView",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/sheet_view.rb#L20-L37
|
17,926
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_position.rb
|
OoxmlParser.DocxDrawingPosition.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'relativeFrom'
@relative_from = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'posOffset', 'pctPosHOffset', 'pctPosVOffset'
@offset = OoxmlSize.new(node_child.text.to_f, :emu)
when 'align'
@align = node_child.text.to_sym
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'relativeFrom'
@relative_from = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'posOffset', 'pctPosHOffset', 'pctPosVOffset'
@offset = OoxmlSize.new(node_child.text.to_f, :emu)
when 'align'
@align = node_child.text.to_sym
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'relativeFrom'",
"@relative_from",
"=",
"value_to_symbol",
"(",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'posOffset'",
",",
"'pctPosHOffset'",
",",
"'pctPosVOffset'",
"@offset",
"=",
"OoxmlSize",
".",
"new",
"(",
"node_child",
".",
"text",
".",
"to_f",
",",
":emu",
")",
"when",
"'align'",
"@align",
"=",
"node_child",
".",
"text",
".",
"to_sym",
"end",
"end",
"self",
"end"
] |
Parse DocxDrawingPosition object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxDrawingPosition] result of parsing
|
[
"Parse",
"DocxDrawingPosition",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_drawing_position.rb#L9-L26
|
17,927
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb
|
OoxmlParser.OldDocxShape.parse
|
def parse(node)
@properties = OldDocxShapeProperties.new(parent: self).parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'textbox'
@text_box = TextBox.parse_list(node_child, parent: self)
when 'imagedata'
@file_reference = FileReference.new(parent: self).parse(node_child)
when 'fill'
@fill = OldDocxShapeFill.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
@properties = OldDocxShapeProperties.new(parent: self).parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'textbox'
@text_box = TextBox.parse_list(node_child, parent: self)
when 'imagedata'
@file_reference = FileReference.new(parent: self).parse(node_child)
when 'fill'
@fill = OldDocxShapeFill.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"@properties",
"=",
"OldDocxShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'textbox'",
"@text_box",
"=",
"TextBox",
".",
"parse_list",
"(",
"node_child",
",",
"parent",
":",
"self",
")",
"when",
"'imagedata'",
"@file_reference",
"=",
"FileReference",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'fill'",
"@fill",
"=",
"OldDocxShapeFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse OldDocxShape object
@param node [Nokogiri::XML:Element] node to parse
@return [OldDocxShape] result of parsing
|
[
"Parse",
"OldDocxShape",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/picture/shape/old_docx_shape.rb#L12-L25
|
17,928
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/formula.rb
|
OoxmlParser.Formula.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'ref'
@reference = Coordinates.parser_coordinates_range(value.value.to_s)
when 'si'
@string_index = value.value.to_i
when 't'
@type = value.value.to_s
end
end
@value = node.text unless node.text.empty?
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'ref'
@reference = Coordinates.parser_coordinates_range(value.value.to_s)
when 'si'
@string_index = value.value.to_i
when 't'
@type = value.value.to_s
end
end
@value = node.text unless node.text.empty?
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'ref'",
"@reference",
"=",
"Coordinates",
".",
"parser_coordinates_range",
"(",
"value",
".",
"value",
".",
"to_s",
")",
"when",
"'si'",
"@string_index",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'t'",
"@type",
"=",
"value",
".",
"value",
".",
"to_s",
"end",
"end",
"@value",
"=",
"node",
".",
"text",
"unless",
"node",
".",
"text",
".",
"empty?",
"self",
"end"
] |
Parse Formula object
@param node [Nokogiri::XML:Element] node to parse
@return [Formula] parsed object
|
[
"Parse",
"Formula",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell/formula.rb#L16-L30
|
17,929
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/relationships.rb
|
OoxmlParser.Relationships.parse_file
|
def parse_file(file_path)
node = parse_xml(file_path)
node.xpath('*').each do |node_child|
case node_child.name
when 'Relationships'
parse(node_child)
end
end
self
end
|
ruby
|
def parse_file(file_path)
node = parse_xml(file_path)
node.xpath('*').each do |node_child|
case node_child.name
when 'Relationships'
parse(node_child)
end
end
self
end
|
[
"def",
"parse_file",
"(",
"file_path",
")",
"node",
"=",
"parse_xml",
"(",
"file_path",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'Relationships'",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse .rels file
@param file_path [String] path to file
@return [Relationships]
|
[
"Parse",
".",
"rels",
"file"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/relationships.rb#L34-L43
|
17,930
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/relationships.rb
|
OoxmlParser.Relationships.target_by_type
|
def target_by_type(type)
result = []
@relationship.each do |cur_rels|
result << cur_rels.target if cur_rels.type.include?(type)
end
result
end
|
ruby
|
def target_by_type(type)
result = []
@relationship.each do |cur_rels|
result << cur_rels.target if cur_rels.type.include?(type)
end
result
end
|
[
"def",
"target_by_type",
"(",
"type",
")",
"result",
"=",
"[",
"]",
"@relationship",
".",
"each",
"do",
"|",
"cur_rels",
"|",
"result",
"<<",
"cur_rels",
".",
"target",
"if",
"cur_rels",
".",
"type",
".",
"include?",
"(",
"type",
")",
"end",
"result",
"end"
] |
Get target names by type
@param type [String] type of target
@return [Array<String>] target names
|
[
"Get",
"target",
"names",
"by",
"type"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/relationships.rb#L58-L64
|
17,931
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering/abstract_numbering/numbering_level.rb
|
OoxmlParser.NumberingLevel.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'ilvl'
@ilvl = value.value.to_f
end
end
node.xpath('*').each do |num_level_child|
case num_level_child.name
when 'start'
@start = ValuedChild.new(:integer, parent: self).parse(num_level_child)
when 'numFmt'
@numbering_format = NumberingFormat.new(parent: self).parse(num_level_child)
when 'lvlText'
@text = LevelText.new(parent: self).parse(num_level_child)
when 'lvlJc'
@justification = LevelJustification.new(parent: self).parse(num_level_child)
when 'pPr'
@paragraph_properties = ParagraphProperties.new(parent: self).parse(num_level_child)
when 'rPr'
@run_properties = RunProperties.new(parent: self).parse(num_level_child)
when 'suff'
@suffix = @suffix.parse(num_level_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'ilvl'
@ilvl = value.value.to_f
end
end
node.xpath('*').each do |num_level_child|
case num_level_child.name
when 'start'
@start = ValuedChild.new(:integer, parent: self).parse(num_level_child)
when 'numFmt'
@numbering_format = NumberingFormat.new(parent: self).parse(num_level_child)
when 'lvlText'
@text = LevelText.new(parent: self).parse(num_level_child)
when 'lvlJc'
@justification = LevelJustification.new(parent: self).parse(num_level_child)
when 'pPr'
@paragraph_properties = ParagraphProperties.new(parent: self).parse(num_level_child)
when 'rPr'
@run_properties = RunProperties.new(parent: self).parse(num_level_child)
when 'suff'
@suffix = @suffix.parse(num_level_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'ilvl'",
"@ilvl",
"=",
"value",
".",
"value",
".",
"to_f",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"num_level_child",
"|",
"case",
"num_level_child",
".",
"name",
"when",
"'start'",
"@start",
"=",
"ValuedChild",
".",
"new",
"(",
":integer",
",",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'numFmt'",
"@numbering_format",
"=",
"NumberingFormat",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'lvlText'",
"@text",
"=",
"LevelText",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'lvlJc'",
"@justification",
"=",
"LevelJustification",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'pPr'",
"@paragraph_properties",
"=",
"ParagraphProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'rPr'",
"@run_properties",
"=",
"RunProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"num_level_child",
")",
"when",
"'suff'",
"@suffix",
"=",
"@suffix",
".",
"parse",
"(",
"num_level_child",
")",
"end",
"end",
"self",
"end"
] |
Parse Numbering Level data
@param [Nokogiri::XML:Element] node with Numbering Level data
@return [NumberingLevel] value of Numbering Level data
|
[
"Parse",
"Numbering",
"Level",
"data"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/numbering/abstract_numbering/numbering_level.rb#L34-L62
|
17,932
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs.rb
|
OoxmlParser.CellXfs.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'count'
@count = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'xf'
@xf_array << Xf.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'count'
@count = value.value.to_i
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'xf'
@xf_array << Xf.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'count'",
"@count",
"=",
"value",
".",
"value",
".",
"to_i",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'xf'",
"@xf_array",
"<<",
"Xf",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse CellXfs data
@param [Nokogiri::XML:Element] node with CellXfs data
@return [CellXfs] value of CellXfs data
|
[
"Parse",
"CellXfs",
"data"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/cell_xfs.rb#L18-L33
|
17,933
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb
|
OoxmlParser.DocxBlip.parse
|
def parse(node)
blip_node = node.xpath('a:blip', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
return self if blip_node.nil?
@file_reference = FileReference.new(parent: self).parse(blip_node)
self
end
|
ruby
|
def parse(node)
blip_node = node.xpath('a:blip', 'xmlns:a' => 'http://schemas.openxmlformats.org/drawingml/2006/main').first
return self if blip_node.nil?
@file_reference = FileReference.new(parent: self).parse(blip_node)
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"blip_node",
"=",
"node",
".",
"xpath",
"(",
"'a:blip'",
",",
"'xmlns:a'",
"=>",
"'http://schemas.openxmlformats.org/drawingml/2006/main'",
")",
".",
"first",
"return",
"self",
"if",
"blip_node",
".",
"nil?",
"@file_reference",
"=",
"FileReference",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"blip_node",
")",
"self",
"end"
] |
Parse DocxBlip object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxBlip] result of parsing
|
[
"Parse",
"DocxBlip",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/picture/docx_blip.rb#L18-L24
|
17,934
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb
|
OoxmlParser.GraphicFrame.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'xfrm'
@transform = DocxShapeSize.new(parent: self).parse(node_child)
when 'graphic'
graphic_data = []
node_child.xpath('*').each do |node_child_child|
case node_child_child.name
when 'graphicData'
node_child_child.xpath('*').each do |graphic_node_child|
case graphic_node_child.name
when 'tbl'
graphic_data << Table.new(parent: self).parse(graphic_node_child)
when 'chart'
OOXMLDocumentObject.add_to_xmls_stack(OOXMLDocumentObject.get_link_from_rels(graphic_node_child.attribute('id').value))
graphic_data << Chart.parse(parent: self)
OOXMLDocumentObject.xmls_stack.pop
when 'oleObj'
graphic_data << OleObject.new(parent: self).parse(graphic_node_child)
end
end
end
end
@graphic_data = graphic_data
when 'nvGraphicFramePr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'xfrm'
@transform = DocxShapeSize.new(parent: self).parse(node_child)
when 'graphic'
graphic_data = []
node_child.xpath('*').each do |node_child_child|
case node_child_child.name
when 'graphicData'
node_child_child.xpath('*').each do |graphic_node_child|
case graphic_node_child.name
when 'tbl'
graphic_data << Table.new(parent: self).parse(graphic_node_child)
when 'chart'
OOXMLDocumentObject.add_to_xmls_stack(OOXMLDocumentObject.get_link_from_rels(graphic_node_child.attribute('id').value))
graphic_data << Chart.parse(parent: self)
OOXMLDocumentObject.xmls_stack.pop
when 'oleObj'
graphic_data << OleObject.new(parent: self).parse(graphic_node_child)
end
end
end
end
@graphic_data = graphic_data
when 'nvGraphicFramePr'
@non_visual_properties = NonVisualShapeProperties.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'xfrm'",
"@transform",
"=",
"DocxShapeSize",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'graphic'",
"graphic_data",
"=",
"[",
"]",
"node_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child_child",
"|",
"case",
"node_child_child",
".",
"name",
"when",
"'graphicData'",
"node_child_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"graphic_node_child",
"|",
"case",
"graphic_node_child",
".",
"name",
"when",
"'tbl'",
"graphic_data",
"<<",
"Table",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"graphic_node_child",
")",
"when",
"'chart'",
"OOXMLDocumentObject",
".",
"add_to_xmls_stack",
"(",
"OOXMLDocumentObject",
".",
"get_link_from_rels",
"(",
"graphic_node_child",
".",
"attribute",
"(",
"'id'",
")",
".",
"value",
")",
")",
"graphic_data",
"<<",
"Chart",
".",
"parse",
"(",
"parent",
":",
"self",
")",
"OOXMLDocumentObject",
".",
"xmls_stack",
".",
"pop",
"when",
"'oleObj'",
"graphic_data",
"<<",
"OleObject",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"graphic_node_child",
")",
"end",
"end",
"end",
"end",
"@graphic_data",
"=",
"graphic_data",
"when",
"'nvGraphicFramePr'",
"@non_visual_properties",
"=",
"NonVisualShapeProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse GraphicFrame object
@param node [Nokogiri::XML:Element] node to parse
@return [GraphicFrame] result of parsing
|
[
"Parse",
"GraphicFrame",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/pptx_parser/pptx_data/presentation/slide/graphic_frame/graphic_frame.rb#L16-L46
|
17,935
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb
|
OoxmlParser.DocxShapeSize.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'rot'
@rotation = value.value.to_f
when 'flipH'
@flip_horizontal = attribute_enabled?(value)
when 'flipV'
@flip_vertical = attribute_enabled?(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'off'
@offset = OOXMLCoordinates.parse(node_child, unit: :emu)
when 'ext'
@extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
when 'chOff'
@child_offset = OOXMLCoordinates.parse(node_child, unit: :emu)
when 'chExt'
@child_extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'rot'
@rotation = value.value.to_f
when 'flipH'
@flip_horizontal = attribute_enabled?(value)
when 'flipV'
@flip_vertical = attribute_enabled?(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'off'
@offset = OOXMLCoordinates.parse(node_child, unit: :emu)
when 'ext'
@extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
when 'chOff'
@child_offset = OOXMLCoordinates.parse(node_child, unit: :emu)
when 'chExt'
@child_extent = OOXMLCoordinates.parse(node_child, x_attr: 'cx', y_attr: 'cy', unit: :emu)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'rot'",
"@rotation",
"=",
"value",
".",
"value",
".",
"to_f",
"when",
"'flipH'",
"@flip_horizontal",
"=",
"attribute_enabled?",
"(",
"value",
")",
"when",
"'flipV'",
"@flip_vertical",
"=",
"attribute_enabled?",
"(",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'off'",
"@offset",
"=",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"unit",
":",
":emu",
")",
"when",
"'ext'",
"@extent",
"=",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"x_attr",
":",
"'cx'",
",",
"y_attr",
":",
"'cy'",
",",
"unit",
":",
":emu",
")",
"when",
"'chOff'",
"@child_offset",
"=",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"unit",
":",
":emu",
")",
"when",
"'chExt'",
"@child_extent",
"=",
"OOXMLCoordinates",
".",
"parse",
"(",
"node_child",
",",
"x_attr",
":",
"'cx'",
",",
"y_attr",
":",
"'cy'",
",",
"unit",
":",
":emu",
")",
"end",
"end",
"self",
"end"
] |
Parse DocxShapeSize object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxShapeSize] result of parsing
|
[
"Parse",
"DocxShapeSize",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/docx_shape_size.rb#L17-L41
|
17,936
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_wrap_drawing.rb
|
OoxmlParser.DocxWrapDrawing.parse
|
def parse(node)
unless node.attribute('behindDoc').nil?
@wrap_text = :behind if node.attribute('behindDoc').value == '1'
@wrap_text = :infront if node.attribute('behindDoc').value == '0'
end
node.xpath('*').each do |node_child|
case node_child.name
when 'wrapSquare'
@wrap_text = :square
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapTight'
@wrap_text = :tight
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapThrough'
@wrap_text = :through
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapTopAndBottom'
@wrap_text = :topbottom
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
end
end
self
end
|
ruby
|
def parse(node)
unless node.attribute('behindDoc').nil?
@wrap_text = :behind if node.attribute('behindDoc').value == '1'
@wrap_text = :infront if node.attribute('behindDoc').value == '0'
end
node.xpath('*').each do |node_child|
case node_child.name
when 'wrapSquare'
@wrap_text = :square
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapTight'
@wrap_text = :tight
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapThrough'
@wrap_text = :through
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
when 'wrapTopAndBottom'
@wrap_text = :topbottom
@distance_from_text = DocxDrawingDistanceFromText.new(parent: self).parse(node_child)
break
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"unless",
"node",
".",
"attribute",
"(",
"'behindDoc'",
")",
".",
"nil?",
"@wrap_text",
"=",
":behind",
"if",
"node",
".",
"attribute",
"(",
"'behindDoc'",
")",
".",
"value",
"==",
"'1'",
"@wrap_text",
"=",
":infront",
"if",
"node",
".",
"attribute",
"(",
"'behindDoc'",
")",
".",
"value",
"==",
"'0'",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'wrapSquare'",
"@wrap_text",
"=",
":square",
"@distance_from_text",
"=",
"DocxDrawingDistanceFromText",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"break",
"when",
"'wrapTight'",
"@wrap_text",
"=",
":tight",
"@distance_from_text",
"=",
"DocxDrawingDistanceFromText",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"break",
"when",
"'wrapThrough'",
"@wrap_text",
"=",
":through",
"@distance_from_text",
"=",
"DocxDrawingDistanceFromText",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"break",
"when",
"'wrapTopAndBottom'",
"@wrap_text",
"=",
":topbottom",
"@distance_from_text",
"=",
"DocxDrawingDistanceFromText",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"break",
"end",
"end",
"self",
"end"
] |
Parse DocxWrapDrawing object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxWrapDrawing] result of parsing
|
[
"Parse",
"DocxWrapDrawing",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/drawing_properties/docx_wrap_drawing.rb#L14-L40
|
17,937
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path.rb
|
OoxmlParser.DocxShapeLinePath.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = value.value.to_f
when 'h'
@height = value.value.to_f
when 'stroke'
@stroke = value.value.to_f
end
end
node.xpath('*').each do |node_child|
@elements << DocxShapeLineElement.new(parent: self).parse(node_child)
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'w'
@width = value.value.to_f
when 'h'
@height = value.value.to_f
when 'stroke'
@stroke = value.value.to_f
end
end
node.xpath('*').each do |node_child|
@elements << DocxShapeLineElement.new(parent: self).parse(node_child)
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'w'",
"@width",
"=",
"value",
".",
"value",
".",
"to_f",
"when",
"'h'",
"@height",
"=",
"value",
".",
"value",
".",
"to_f",
"when",
"'stroke'",
"@stroke",
"=",
"value",
".",
"value",
".",
"to_f",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"@elements",
"<<",
"DocxShapeLineElement",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"self",
"end"
] |
Parse DocxShapeLinePath object
@param node [Nokogiri::XML:Element] node to parse
@return [DocxShapeLinePath] result of parsing
|
[
"Parse",
"DocxShapeLinePath",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/alternate_content/drawing/graphic/shape/shape_properties/custom_geometry/docx_custom_geometry/docx_shape_line_path.rb#L15-L30
|
17,938
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/colors/presentation_fill.rb
|
OoxmlParser.PresentationFill.parse
|
def parse(node)
return nil if node.xpath('*').empty?
node.xpath('*').each do |node_child|
case node_child.name
when 'gradFill'
@type = :gradient
@color = GradientColor.new(parent: self).parse(node_child)
when 'solidFill'
@type = :solid
@color = Color.new(parent: self).parse_color(node_child.xpath('*').first)
when 'blipFill'
@type = :image
@image = ImageFill.new(parent: self).parse(node_child)
when 'pattFill'
@type = :pattern
@pattern = PresentationPattern.new(parent: self).parse(node_child)
when 'noFill'
@type = :noneColor
@color = :none
end
end
return nil if @type.nil?
self
end
|
ruby
|
def parse(node)
return nil if node.xpath('*').empty?
node.xpath('*').each do |node_child|
case node_child.name
when 'gradFill'
@type = :gradient
@color = GradientColor.new(parent: self).parse(node_child)
when 'solidFill'
@type = :solid
@color = Color.new(parent: self).parse_color(node_child.xpath('*').first)
when 'blipFill'
@type = :image
@image = ImageFill.new(parent: self).parse(node_child)
when 'pattFill'
@type = :pattern
@pattern = PresentationPattern.new(parent: self).parse(node_child)
when 'noFill'
@type = :noneColor
@color = :none
end
end
return nil if @type.nil?
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"return",
"nil",
"if",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"empty?",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'gradFill'",
"@type",
"=",
":gradient",
"@color",
"=",
"GradientColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'solidFill'",
"@type",
"=",
":solid",
"@color",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_color",
"(",
"node_child",
".",
"xpath",
"(",
"'*'",
")",
".",
"first",
")",
"when",
"'blipFill'",
"@type",
"=",
":image",
"@image",
"=",
"ImageFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pattFill'",
"@type",
"=",
":pattern",
"@pattern",
"=",
"PresentationPattern",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'noFill'",
"@type",
"=",
":noneColor",
"@color",
"=",
":none",
"end",
"end",
"return",
"nil",
"if",
"@type",
".",
"nil?",
"self",
"end"
] |
Parse PresentationFill object
@param node [Nokogiri::XML:Element] node to parse
@return [PresentationFill] result of parsing
|
[
"Parse",
"PresentationFill",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/colors/presentation_fill.rb#L11-L36
|
17,939
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb
|
OoxmlParser.ParagraphProperties.parse
|
def parse(node)
@spacing.parse(node)
node.attributes.each do |key, value|
case key
when 'algn'
@align = value_to_symbol(value)
when 'lvl'
@level = value.value.to_i
when 'indent'
@indent = OoxmlSize.new(value.value.to_f, :emu)
when 'marR'
@margin_right = OoxmlSize.new(value.value.to_f, :emu)
when 'marL'
@margin_left = OoxmlSize.new(value.value.to_f, :emu)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'buSzPct'
@numbering.size = node_child.attribute('val').value
when 'buFont'
@numbering.font = node_child.attribute('typeface').value
when 'buChar'
@numbering.symbol = node_child.attribute('char').value
when 'buAutoNum'
@numbering.type = node_child.attribute('type').value.to_sym
@numbering.start_at = node_child.attribute('startAt').value if node_child.attribute('startAt')
when 'framePr'
@frame_properties = FrameProperties.new(parent: self).parse(node_child)
when 'tabs'
@tabs = Tabs.new(parent: self).parse(node_child)
when 'tabLst'
@tabs = Tabs.new(parent: self).parse(node_child)
when 'ind'
@indent = Indents.new(parent: self).parse(node_child)
when 'rPr'
@run_properties = RunProperties.new(parent: self).parse(node_child)
when 'pBdr'
@paragraph_borders = ParagraphBorders.new(parent: self).parse(node_child)
when 'keepNext'
@keep_next = true
when 'sectPr'
@section_properties = PageProperties.new(parent: self).parse(node_child, @parent, DocxParagraphRun.new)
when 'spacing'
@spacing = ParagraphSpacing.new(parent: self).parse(node_child)
when 'jc'
@justification = value_to_symbol(node_child.attribute('val'))
when 'contextualSpacing'
@contextual_spacing = option_enabled?(node_child)
end
end
self
end
|
ruby
|
def parse(node)
@spacing.parse(node)
node.attributes.each do |key, value|
case key
when 'algn'
@align = value_to_symbol(value)
when 'lvl'
@level = value.value.to_i
when 'indent'
@indent = OoxmlSize.new(value.value.to_f, :emu)
when 'marR'
@margin_right = OoxmlSize.new(value.value.to_f, :emu)
when 'marL'
@margin_left = OoxmlSize.new(value.value.to_f, :emu)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'buSzPct'
@numbering.size = node_child.attribute('val').value
when 'buFont'
@numbering.font = node_child.attribute('typeface').value
when 'buChar'
@numbering.symbol = node_child.attribute('char').value
when 'buAutoNum'
@numbering.type = node_child.attribute('type').value.to_sym
@numbering.start_at = node_child.attribute('startAt').value if node_child.attribute('startAt')
when 'framePr'
@frame_properties = FrameProperties.new(parent: self).parse(node_child)
when 'tabs'
@tabs = Tabs.new(parent: self).parse(node_child)
when 'tabLst'
@tabs = Tabs.new(parent: self).parse(node_child)
when 'ind'
@indent = Indents.new(parent: self).parse(node_child)
when 'rPr'
@run_properties = RunProperties.new(parent: self).parse(node_child)
when 'pBdr'
@paragraph_borders = ParagraphBorders.new(parent: self).parse(node_child)
when 'keepNext'
@keep_next = true
when 'sectPr'
@section_properties = PageProperties.new(parent: self).parse(node_child, @parent, DocxParagraphRun.new)
when 'spacing'
@spacing = ParagraphSpacing.new(parent: self).parse(node_child)
when 'jc'
@justification = value_to_symbol(node_child.attribute('val'))
when 'contextualSpacing'
@contextual_spacing = option_enabled?(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"@spacing",
".",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'algn'",
"@align",
"=",
"value_to_symbol",
"(",
"value",
")",
"when",
"'lvl'",
"@level",
"=",
"value",
".",
"value",
".",
"to_i",
"when",
"'indent'",
"@indent",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"when",
"'marR'",
"@margin_right",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"when",
"'marL'",
"@margin_left",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'buSzPct'",
"@numbering",
".",
"size",
"=",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
".",
"value",
"when",
"'buFont'",
"@numbering",
".",
"font",
"=",
"node_child",
".",
"attribute",
"(",
"'typeface'",
")",
".",
"value",
"when",
"'buChar'",
"@numbering",
".",
"symbol",
"=",
"node_child",
".",
"attribute",
"(",
"'char'",
")",
".",
"value",
"when",
"'buAutoNum'",
"@numbering",
".",
"type",
"=",
"node_child",
".",
"attribute",
"(",
"'type'",
")",
".",
"value",
".",
"to_sym",
"@numbering",
".",
"start_at",
"=",
"node_child",
".",
"attribute",
"(",
"'startAt'",
")",
".",
"value",
"if",
"node_child",
".",
"attribute",
"(",
"'startAt'",
")",
"when",
"'framePr'",
"@frame_properties",
"=",
"FrameProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tabs'",
"@tabs",
"=",
"Tabs",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tabLst'",
"@tabs",
"=",
"Tabs",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'ind'",
"@indent",
"=",
"Indents",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'rPr'",
"@run_properties",
"=",
"RunProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pBdr'",
"@paragraph_borders",
"=",
"ParagraphBorders",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'keepNext'",
"@keep_next",
"=",
"true",
"when",
"'sectPr'",
"@section_properties",
"=",
"PageProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
",",
"@parent",
",",
"DocxParagraphRun",
".",
"new",
")",
"when",
"'spacing'",
"@spacing",
"=",
"ParagraphSpacing",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'jc'",
"@justification",
"=",
"value_to_symbol",
"(",
"node_child",
".",
"attribute",
"(",
"'val'",
")",
")",
"when",
"'contextualSpacing'",
"@contextual_spacing",
"=",
"option_enabled?",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse ParagraphProperties object
@param node [Nokogiri::XML:Element] node to parse
@return [ParagraphProperties] result of parsing
|
[
"Parse",
"ParagraphProperties",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb#L45-L97
|
17,940
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/common_parser/common_data/table/row/row.rb
|
OoxmlParser.TableRow.parse
|
def parse(node)
root_object.default_font_style = FontStyle.new(true) # TODO: Add correct parsing of TableStyle.xml file and use it
node.attributes.each do |key, value|
case key
when 'h'
@height = OoxmlSize.new(value.value.to_f, :emu)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'trPr'
@table_row_properties = TableRowProperties.new(parent: self).parse(node_child)
when 'tc'
@cells << TableCell.new(parent: self).parse(node_child)
end
end
root_object.default_font_style = FontStyle.new
self
end
|
ruby
|
def parse(node)
root_object.default_font_style = FontStyle.new(true) # TODO: Add correct parsing of TableStyle.xml file and use it
node.attributes.each do |key, value|
case key
when 'h'
@height = OoxmlSize.new(value.value.to_f, :emu)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'trPr'
@table_row_properties = TableRowProperties.new(parent: self).parse(node_child)
when 'tc'
@cells << TableCell.new(parent: self).parse(node_child)
end
end
root_object.default_font_style = FontStyle.new
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"root_object",
".",
"default_font_style",
"=",
"FontStyle",
".",
"new",
"(",
"true",
")",
"# TODO: Add correct parsing of TableStyle.xml file and use it",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'h'",
"@height",
"=",
"OoxmlSize",
".",
"new",
"(",
"value",
".",
"value",
".",
"to_f",
",",
":emu",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'trPr'",
"@table_row_properties",
"=",
"TableRowProperties",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'tc'",
"@cells",
"<<",
"TableCell",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"root_object",
".",
"default_font_style",
"=",
"FontStyle",
".",
"new",
"self",
"end"
] |
Parse TableRow object
@param node [Nokogiri::XML:Element] node to parse
@return [TableRow] result of parsing
|
[
"Parse",
"TableRow",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/common_parser/common_data/table/row/row.rb#L17-L35
|
17,941
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position_parameters.rb
|
OoxmlParser.XlsxDrawingPositionParameters.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'col'
@column = Coordinates.get_column_name(node_child.text.to_i + 1)
when 'colOff'
@column_offset = OoxmlSize.new(node_child.text.to_f, :emu)
when 'row'
@row = node_child.text.to_i + 1
when 'rowOff'
@row_offset = OoxmlSize.new(node_child.text.to_f, :emu)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'col'
@column = Coordinates.get_column_name(node_child.text.to_i + 1)
when 'colOff'
@column_offset = OoxmlSize.new(node_child.text.to_f, :emu)
when 'row'
@row = node_child.text.to_i + 1
when 'rowOff'
@row_offset = OoxmlSize.new(node_child.text.to_f, :emu)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'col'",
"@column",
"=",
"Coordinates",
".",
"get_column_name",
"(",
"node_child",
".",
"text",
".",
"to_i",
"+",
"1",
")",
"when",
"'colOff'",
"@column_offset",
"=",
"OoxmlSize",
".",
"new",
"(",
"node_child",
".",
"text",
".",
"to_f",
",",
":emu",
")",
"when",
"'row'",
"@row",
"=",
"node_child",
".",
"text",
".",
"to_i",
"+",
"1",
"when",
"'rowOff'",
"@row_offset",
"=",
"OoxmlSize",
".",
"new",
"(",
"node_child",
".",
"text",
".",
"to_f",
",",
":emu",
")",
"end",
"end",
"self",
"end"
] |
Parse XlsxDrawingPositionParameters object
@param node [Nokogiri::XML:Element] node to parse
@return [XlsxDrawingPositionParameters] result of parsing
|
[
"Parse",
"XlsxDrawingPositionParameters",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_drawing/xlsx_drawing_position_parameters.rb#L9-L23
|
17,942
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb
|
OoxmlParser.Fill.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'color2'
@color2 = Color.new(parent: self).parse_hex_string(value.value.split(' ').first.delete('#'))
when 'id'
@id = value.value.to_s
@file = FileReference.new(parent: self).parse(node)
when 'type'
@type = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'patternFill'
@pattern_fill = PatternFill.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'color2'
@color2 = Color.new(parent: self).parse_hex_string(value.value.split(' ').first.delete('#'))
when 'id'
@id = value.value.to_s
@file = FileReference.new(parent: self).parse(node)
when 'type'
@type = value_to_symbol(value)
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'patternFill'
@pattern_fill = PatternFill.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'color2'",
"@color2",
"=",
"Color",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse_hex_string",
"(",
"value",
".",
"value",
".",
"split",
"(",
"' '",
")",
".",
"first",
".",
"delete",
"(",
"'#'",
")",
")",
"when",
"'id'",
"@id",
"=",
"value",
".",
"value",
".",
"to_s",
"@file",
"=",
"FileReference",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node",
")",
"when",
"'type'",
"@type",
"=",
"value_to_symbol",
"(",
"value",
")",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'patternFill'",
"@pattern_fill",
"=",
"PatternFill",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse Fill data
@param [Nokogiri::XML:Element] node with Fill data
@return [Fill] value of Fill data
|
[
"Parse",
"Fill",
"data"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill.rb#L19-L39
|
17,943
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/docx_parser/docx_data/document_structure/styles/document_defaults.rb
|
OoxmlParser.DocumentDefaults.parse
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'rPrDefault'
@run_properties_default = RunPropertiesDefault.new(parent: self).parse(node_child)
when 'pPrDefault'
@paragraph_properties_default = ParagraphPropertiesDefault.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.xpath('*').each do |node_child|
case node_child.name
when 'rPrDefault'
@run_properties_default = RunPropertiesDefault.new(parent: self).parse(node_child)
when 'pPrDefault'
@paragraph_properties_default = ParagraphPropertiesDefault.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'rPrDefault'",
"@run_properties_default",
"=",
"RunPropertiesDefault",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'pPrDefault'",
"@paragraph_properties_default",
"=",
"ParagraphPropertiesDefault",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse Bookmark object
@param node [Nokogiri::XML:Element] node to parse
@return [Bookmark] result of parsing
|
[
"Parse",
"Bookmark",
"object"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/docx_parser/docx_data/document_structure/styles/document_defaults.rb#L14-L24
|
17,944
|
ONLYOFFICE/ooxml_parser
|
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb
|
OoxmlParser.PatternFill.parse
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'patternType'
@pattern_type = value.value.to_sym
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'fgColor'
@foreground_color = OoxmlColor.new(parent: self).parse(node_child)
when 'bgColor'
@background_color = OoxmlColor.new(parent: self).parse(node_child)
end
end
self
end
|
ruby
|
def parse(node)
node.attributes.each do |key, value|
case key
when 'patternType'
@pattern_type = value.value.to_sym
end
end
node.xpath('*').each do |node_child|
case node_child.name
when 'fgColor'
@foreground_color = OoxmlColor.new(parent: self).parse(node_child)
when 'bgColor'
@background_color = OoxmlColor.new(parent: self).parse(node_child)
end
end
self
end
|
[
"def",
"parse",
"(",
"node",
")",
"node",
".",
"attributes",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"key",
"when",
"'patternType'",
"@pattern_type",
"=",
"value",
".",
"value",
".",
"to_sym",
"end",
"end",
"node",
".",
"xpath",
"(",
"'*'",
")",
".",
"each",
"do",
"|",
"node_child",
"|",
"case",
"node_child",
".",
"name",
"when",
"'fgColor'",
"@foreground_color",
"=",
"OoxmlColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"when",
"'bgColor'",
"@background_color",
"=",
"OoxmlColor",
".",
"new",
"(",
"parent",
":",
"self",
")",
".",
"parse",
"(",
"node_child",
")",
"end",
"end",
"self",
"end"
] |
Parse PatternFill data
@param [Nokogiri::XML:Element] node with PatternFill data
@return [PatternFill] value of PatternFill data
|
[
"Parse",
"PatternFill",
"data"
] |
08452315cde52fa94d8cb3e1eff1db4ea33abc88
|
https://github.com/ONLYOFFICE/ooxml_parser/blob/08452315cde52fa94d8cb3e1eff1db4ea33abc88/lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/style_sheet/fills/fill/pattern_fill.rb#L14-L31
|
17,945
|
stewartmckee/cobweb
|
lib/crawl.rb
|
CobwebModule.Crawl.set_base_url
|
def set_base_url(redis)
if redis.get("base_url").nil?
unless !defined?(content.redirect_through) || content.redirect_through.empty? || !@options[:first_page_redirect_internal]
uri = Addressable::URI.parse(content.redirect_through.last)
redis.sadd("internal_urls", [uri.scheme, "://", uri.host, "/*"].join)
end
redis.set("base_url", content.url)
end
end
|
ruby
|
def set_base_url(redis)
if redis.get("base_url").nil?
unless !defined?(content.redirect_through) || content.redirect_through.empty? || !@options[:first_page_redirect_internal]
uri = Addressable::URI.parse(content.redirect_through.last)
redis.sadd("internal_urls", [uri.scheme, "://", uri.host, "/*"].join)
end
redis.set("base_url", content.url)
end
end
|
[
"def",
"set_base_url",
"(",
"redis",
")",
"if",
"redis",
".",
"get",
"(",
"\"base_url\"",
")",
".",
"nil?",
"unless",
"!",
"defined?",
"(",
"content",
".",
"redirect_through",
")",
"||",
"content",
".",
"redirect_through",
".",
"empty?",
"||",
"!",
"@options",
"[",
":first_page_redirect_internal",
"]",
"uri",
"=",
"Addressable",
"::",
"URI",
".",
"parse",
"(",
"content",
".",
"redirect_through",
".",
"last",
")",
"redis",
".",
"sadd",
"(",
"\"internal_urls\"",
",",
"[",
"uri",
".",
"scheme",
",",
"\"://\"",
",",
"uri",
".",
"host",
",",
"\"/*\"",
"]",
".",
"join",
")",
"end",
"redis",
".",
"set",
"(",
"\"base_url\"",
",",
"content",
".",
"url",
")",
"end",
"end"
] |
Sets the base url in redis. If the first page is a redirect, it sets the base_url to the destination
|
[
"Sets",
"the",
"base",
"url",
"in",
"redis",
".",
"If",
"the",
"first",
"page",
"is",
"a",
"redirect",
"it",
"sets",
"the",
"base_url",
"to",
"the",
"destination"
] |
a957f4519e544c09e6f32a497cac2e991e5dbac3
|
https://github.com/stewartmckee/cobweb/blob/a957f4519e544c09e6f32a497cac2e991e5dbac3/lib/crawl.rb#L348-L356
|
17,946
|
yihangho/emoji-for-jekyll
|
lib/emoji_for_jekyll.rb
|
EmojiForJekyll.EmojiGenerator.convert
|
def convert(key, block = nil)
if block.nil? or block.call(key)
img_tag(key)
else
":#{key}:"
end
end
|
ruby
|
def convert(key, block = nil)
if block.nil? or block.call(key)
img_tag(key)
else
":#{key}:"
end
end
|
[
"def",
"convert",
"(",
"key",
",",
"block",
"=",
"nil",
")",
"if",
"block",
".",
"nil?",
"or",
"block",
".",
"call",
"(",
"key",
")",
"img_tag",
"(",
"key",
")",
"else",
"\":#{key}:\"",
"end",
"end"
] |
convert takes in the key to the emoji to be converted and an optional block
If block is provided, conversion will be done only if this block evaluates to true.
|
[
"convert",
"takes",
"in",
"the",
"key",
"to",
"the",
"emoji",
"to",
"be",
"converted",
"and",
"an",
"optional",
"block",
"If",
"block",
"is",
"provided",
"conversion",
"will",
"be",
"done",
"only",
"if",
"this",
"block",
"evaluates",
"to",
"true",
"."
] |
2946d1dc5a0419af42b28fe5af9275494bf25316
|
https://github.com/yihangho/emoji-for-jekyll/blob/2946d1dc5a0419af42b28fe5af9275494bf25316/lib/emoji_for_jekyll.rb#L82-L88
|
17,947
|
stretcher/stretcher
|
lib/stretcher/index_type.rb
|
Stretcher.IndexType.get
|
def get(id, options={}, raw=false)
if options == true || options == false # Support raw as second argument, legacy API
raw = true
options = {}
end
res = request(:get, id, options)
raw ? res : (res["_source"] || res["fields"])
end
|
ruby
|
def get(id, options={}, raw=false)
if options == true || options == false # Support raw as second argument, legacy API
raw = true
options = {}
end
res = request(:get, id, options)
raw ? res : (res["_source"] || res["fields"])
end
|
[
"def",
"get",
"(",
"id",
",",
"options",
"=",
"{",
"}",
",",
"raw",
"=",
"false",
")",
"if",
"options",
"==",
"true",
"||",
"options",
"==",
"false",
"# Support raw as second argument, legacy API",
"raw",
"=",
"true",
"options",
"=",
"{",
"}",
"end",
"res",
"=",
"request",
"(",
":get",
",",
"id",
",",
"options",
")",
"raw",
"?",
"res",
":",
"(",
"res",
"[",
"\"_source\"",
"]",
"||",
"res",
"[",
"\"fields\"",
"]",
")",
"end"
] |
Retrieves the document by ID.
Normally this returns the contents of _source, however, if the 'raw' flag is passed in, it will return the full response hash.
Returns nil if the document does not exist.
The :fields argument can either be a csv String or an Array. e.g. [:field1,'field2] or "field1,field2".
If the fields parameter is passed in those fields are returned instead of _source.
If, you include _source as a field, along with other fields you MUST set the raw flag to true to
receive both fields and _source. Otherwise, only _source will be returned
|
[
"Retrieves",
"the",
"document",
"by",
"ID",
".",
"Normally",
"this",
"returns",
"the",
"contents",
"of",
"_source",
"however",
"if",
"the",
"raw",
"flag",
"is",
"passed",
"in",
"it",
"will",
"return",
"the",
"full",
"response",
"hash",
".",
"Returns",
"nil",
"if",
"the",
"document",
"does",
"not",
"exist",
"."
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/index_type.rb#L23-L31
|
17,948
|
stretcher/stretcher
|
lib/stretcher/index_type.rb
|
Stretcher.IndexType.delete
|
def delete(id, options={})
request :delete, id, options
rescue Stretcher::RequestError => e
raise e if e.http_response.status != 404
false
end
|
ruby
|
def delete(id, options={})
request :delete, id, options
rescue Stretcher::RequestError => e
raise e if e.http_response.status != 404
false
end
|
[
"def",
"delete",
"(",
"id",
",",
"options",
"=",
"{",
"}",
")",
"request",
":delete",
",",
"id",
",",
"options",
"rescue",
"Stretcher",
"::",
"RequestError",
"=>",
"e",
"raise",
"e",
"if",
"e",
".",
"http_response",
".",
"status",
"!=",
"404",
"false",
"end"
] |
Deletes the document with the given ID
|
[
"Deletes",
"the",
"document",
"with",
"the",
"given",
"ID"
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/index_type.rb#L69-L74
|
17,949
|
stretcher/stretcher
|
lib/stretcher/index_type.rb
|
Stretcher.IndexType.exists?
|
def exists?(id=nil)
request :head, id
true
rescue Stretcher::RequestError::NotFound => e
false
end
|
ruby
|
def exists?(id=nil)
request :head, id
true
rescue Stretcher::RequestError::NotFound => e
false
end
|
[
"def",
"exists?",
"(",
"id",
"=",
"nil",
")",
"request",
":head",
",",
"id",
"true",
"rescue",
"Stretcher",
"::",
"RequestError",
"::",
"NotFound",
"=>",
"e",
"false",
"end"
] |
Check if this index type is defined, if passed an id
this will check if the given document exists
|
[
"Check",
"if",
"this",
"index",
"type",
"is",
"defined",
"if",
"passed",
"an",
"id",
"this",
"will",
"check",
"if",
"the",
"given",
"document",
"exists"
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/index_type.rb#L110-L115
|
17,950
|
stretcher/stretcher
|
lib/stretcher/es_component.rb
|
Stretcher.EsComponent.do_search
|
def do_search(generic_opts={}, explicit_body=nil)
query_opts = {}
body = nil
if explicit_body
query_opts = generic_opts
body = explicit_body
else
body = generic_opts
end
response = request(:get, "_search", query_opts, nil, {}, :mashify => false) do |req|
req.body = body
end
SearchResults.new(response)
end
|
ruby
|
def do_search(generic_opts={}, explicit_body=nil)
query_opts = {}
body = nil
if explicit_body
query_opts = generic_opts
body = explicit_body
else
body = generic_opts
end
response = request(:get, "_search", query_opts, nil, {}, :mashify => false) do |req|
req.body = body
end
SearchResults.new(response)
end
|
[
"def",
"do_search",
"(",
"generic_opts",
"=",
"{",
"}",
",",
"explicit_body",
"=",
"nil",
")",
"query_opts",
"=",
"{",
"}",
"body",
"=",
"nil",
"if",
"explicit_body",
"query_opts",
"=",
"generic_opts",
"body",
"=",
"explicit_body",
"else",
"body",
"=",
"generic_opts",
"end",
"response",
"=",
"request",
"(",
":get",
",",
"\"_search\"",
",",
"query_opts",
",",
"nil",
",",
"{",
"}",
",",
":mashify",
"=>",
"false",
")",
"do",
"|",
"req",
"|",
"req",
".",
"body",
"=",
"body",
"end",
"SearchResults",
".",
"new",
"(",
"response",
")",
"end"
] |
Many of the methods marked protected are called by one line shims in subclasses. This is mostly to facilitate
better looking rdocs
|
[
"Many",
"of",
"the",
"methods",
"marked",
"protected",
"are",
"called",
"by",
"one",
"line",
"shims",
"in",
"subclasses",
".",
"This",
"is",
"mostly",
"to",
"facilitate",
"better",
"looking",
"rdocs"
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/es_component.rb#L8-L22
|
17,951
|
stretcher/stretcher
|
lib/stretcher/server.rb
|
Stretcher.Server.check_response
|
def check_response(res, options)
if res.status >= 200 && res.status <= 299
if(options[:mashify] && res.body.instance_of?(Hash))
Hashie::Mash.new(res.body)
else
res.body
end
elsif [404, 410].include? res.status
err_str = "Error processing request: (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}"
err_str << "\n Resp Body: #{res.body}"
raise RequestError::NotFound.new(res), err_str
else
err_str = "Error processing request (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}"
err_str << "\n Resp Body: #{res.body}"
raise RequestError.new(res), err_str
end
end
|
ruby
|
def check_response(res, options)
if res.status >= 200 && res.status <= 299
if(options[:mashify] && res.body.instance_of?(Hash))
Hashie::Mash.new(res.body)
else
res.body
end
elsif [404, 410].include? res.status
err_str = "Error processing request: (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}"
err_str << "\n Resp Body: #{res.body}"
raise RequestError::NotFound.new(res), err_str
else
err_str = "Error processing request (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}"
err_str << "\n Resp Body: #{res.body}"
raise RequestError.new(res), err_str
end
end
|
[
"def",
"check_response",
"(",
"res",
",",
"options",
")",
"if",
"res",
".",
"status",
">=",
"200",
"&&",
"res",
".",
"status",
"<=",
"299",
"if",
"(",
"options",
"[",
":mashify",
"]",
"&&",
"res",
".",
"body",
".",
"instance_of?",
"(",
"Hash",
")",
")",
"Hashie",
"::",
"Mash",
".",
"new",
"(",
"res",
".",
"body",
")",
"else",
"res",
".",
"body",
"end",
"elsif",
"[",
"404",
",",
"410",
"]",
".",
"include?",
"res",
".",
"status",
"err_str",
"=",
"\"Error processing request: (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}\"",
"err_str",
"<<",
"\"\\n Resp Body: #{res.body}\"",
"raise",
"RequestError",
"::",
"NotFound",
".",
"new",
"(",
"res",
")",
",",
"err_str",
"else",
"err_str",
"=",
"\"Error processing request (#{res.status})! #{res.env[:method]} URL: #{res.env[:url]}\"",
"err_str",
"<<",
"\"\\n Resp Body: #{res.body}\"",
"raise",
"RequestError",
".",
"new",
"(",
"res",
")",
",",
"err_str",
"end",
"end"
] |
Internal use only
Check response codes from request
|
[
"Internal",
"use",
"only",
"Check",
"response",
"codes",
"from",
"request"
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/server.rb#L246-L262
|
17,952
|
stretcher/stretcher
|
lib/stretcher/alias.rb
|
Stretcher.Alias.create
|
def create(options = {})
request(:put) do |req|
req.body = {
actions: [
add: options.merge(:alias => @name)
]
}
end
end
|
ruby
|
def create(options = {})
request(:put) do |req|
req.body = {
actions: [
add: options.merge(:alias => @name)
]
}
end
end
|
[
"def",
"create",
"(",
"options",
"=",
"{",
"}",
")",
"request",
"(",
":put",
")",
"do",
"|",
"req",
"|",
"req",
".",
"body",
"=",
"{",
"actions",
":",
"[",
"add",
":",
"options",
".",
"merge",
"(",
":alias",
"=>",
"@name",
")",
"]",
"}",
"end",
"end"
] |
Create the alias in elastic search with the given options
my_alias.create({ filter: { term: { user_id: 1 } } })
|
[
"Create",
"the",
"alias",
"in",
"elastic",
"search",
"with",
"the",
"given",
"options"
] |
2ae1b4b012e7d66dfd6028da77a948c55b36fb80
|
https://github.com/stretcher/stretcher/blob/2ae1b4b012e7d66dfd6028da77a948c55b36fb80/lib/stretcher/alias.rb#L27-L35
|
17,953
|
salesforce/flo
|
lib/flo/task.rb
|
Flo.Task.call
|
def call(args=[])
raise ArgumentError.new("Expected Array") unless args.is_a? Array
@provider.public_send(method_sym, *merged_evaluated_args(args.dup))
end
|
ruby
|
def call(args=[])
raise ArgumentError.new("Expected Array") unless args.is_a? Array
@provider.public_send(method_sym, *merged_evaluated_args(args.dup))
end
|
[
"def",
"call",
"(",
"args",
"=",
"[",
"]",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Expected Array\"",
")",
"unless",
"args",
".",
"is_a?",
"Array",
"@provider",
".",
"public_send",
"(",
"method_sym",
",",
"merged_evaluated_args",
"(",
"args",
".",
"dup",
")",
")",
"end"
] |
Creates a new Task instance
@param [Provider] provider The provider to send the message to
@param [Symbol] The method you wish to call on the provider
@param [Hash] provider_options={} A hash of options to be passed when
invoking the method on the provider. Any lambda values will be called
during the execution stage when {#call} is invoked
Call invokes the task on the provider instance. Additional parameters can be
passed in that are merged into the parameters that were provided in {initialize}.
Proc values will be evaluated before being passed to the provider.
@param [Array] args=[] Additional arguments to pass to the provider method
@return [#success?] Response of the provider's method
|
[
"Creates",
"a",
"new",
"Task",
"instance"
] |
34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a
|
https://github.com/salesforce/flo/blob/34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a/lib/flo/task.rb#L34-L37
|
17,954
|
salesforce/flo
|
lib/flo/task.rb
|
Flo.Task.evaluate_proc_values
|
def evaluate_proc_values(args=[])
args.collect do |arg|
case arg
when Proc
arg.call
when Hash
hsh = {}
arg.each do |k, v|
hsh[k] = v.is_a?(Proc) ? v.call : v
end
hsh
else
arg
end
end
end
|
ruby
|
def evaluate_proc_values(args=[])
args.collect do |arg|
case arg
when Proc
arg.call
when Hash
hsh = {}
arg.each do |k, v|
hsh[k] = v.is_a?(Proc) ? v.call : v
end
hsh
else
arg
end
end
end
|
[
"def",
"evaluate_proc_values",
"(",
"args",
"=",
"[",
"]",
")",
"args",
".",
"collect",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"Proc",
"arg",
".",
"call",
"when",
"Hash",
"hsh",
"=",
"{",
"}",
"arg",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"hsh",
"[",
"k",
"]",
"=",
"v",
".",
"is_a?",
"(",
"Proc",
")",
"?",
"v",
".",
"call",
":",
"v",
"end",
"hsh",
"else",
"arg",
"end",
"end",
"end"
] |
For each value in the args array, evaluate any procs.
If the value is a hash, evaluate any values in the hash
that are procs.
|
[
"For",
"each",
"value",
"in",
"the",
"args",
"array",
"evaluate",
"any",
"procs",
".",
"If",
"the",
"value",
"is",
"a",
"hash",
"evaluate",
"any",
"values",
"in",
"the",
"hash",
"that",
"are",
"procs",
"."
] |
34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a
|
https://github.com/salesforce/flo/blob/34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a/lib/flo/task.rb#L54-L69
|
17,955
|
maestrano/mno-enterprise
|
core/lib/mno_enterprise/smtp_client.rb
|
MnoEnterprise.SmtpClient.deliver
|
def deliver(template, from, to, vars={}, opts={})
@info = vars
@info[:company] = from[:name]
mail(
from: format_sender(from),
to: to[:email],
subject: humanize(template),
template_path: 'system_notifications',
template_name: template
)
end
|
ruby
|
def deliver(template, from, to, vars={}, opts={})
@info = vars
@info[:company] = from[:name]
mail(
from: format_sender(from),
to: to[:email],
subject: humanize(template),
template_path: 'system_notifications',
template_name: template
)
end
|
[
"def",
"deliver",
"(",
"template",
",",
"from",
",",
"to",
",",
"vars",
"=",
"{",
"}",
",",
"opts",
"=",
"{",
"}",
")",
"@info",
"=",
"vars",
"@info",
"[",
":company",
"]",
"=",
"from",
"[",
":name",
"]",
"mail",
"(",
"from",
":",
"format_sender",
"(",
"from",
")",
",",
"to",
":",
"to",
"[",
":email",
"]",
",",
"subject",
":",
"humanize",
"(",
"template",
")",
",",
"template_path",
":",
"'system_notifications'",
",",
"template_name",
":",
"template",
")",
"end"
] |
Send SMTP template - terminal mailing part
|
[
"Send",
"SMTP",
"template",
"-",
"terminal",
"mailing",
"part"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/lib/mno_enterprise/smtp_client.rb#L9-L20
|
17,956
|
maestrano/mno-enterprise
|
api/lib/mno_enterprise/intercom_events_listener.rb
|
MnoEnterprise.IntercomEventsListener.tag_user
|
def tag_user(user)
if user.meta_data && user.meta_data[:source].present?
intercom.tags.tag(name: user.meta_data[:source], users: [{user_id: user.id}])
end
end
|
ruby
|
def tag_user(user)
if user.meta_data && user.meta_data[:source].present?
intercom.tags.tag(name: user.meta_data[:source], users: [{user_id: user.id}])
end
end
|
[
"def",
"tag_user",
"(",
"user",
")",
"if",
"user",
".",
"meta_data",
"&&",
"user",
".",
"meta_data",
"[",
":source",
"]",
".",
"present?",
"intercom",
".",
"tags",
".",
"tag",
"(",
"name",
":",
"user",
".",
"meta_data",
"[",
":source",
"]",
",",
"users",
":",
"[",
"{",
"user_id",
":",
"user",
".",
"id",
"}",
"]",
")",
"end",
"end"
] |
If a source is set, tag the user with it
|
[
"If",
"a",
"source",
"is",
"set",
"tag",
"the",
"user",
"with",
"it"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/lib/mno_enterprise/intercom_events_listener.rb#L65-L69
|
17,957
|
maestrano/mno-enterprise
|
api/app/controllers/mno_enterprise/jpi/v1/admin/invites_controller.rb
|
MnoEnterprise::Jpi::V1::Admin.InvitesController.send_org_invite
|
def send_org_invite(user, invite)
# Generate token if not generated
user.send(:generate_confirmation_token!) if !user.confirmed? && user.confirmation_token.blank?
MnoEnterprise::SystemNotificationMailer.organization_invite(invite).deliver_later
# Update staged invite status
invite.status = 'pending' if invite.status == 'staged'
invite.notification_sent_at = Time.now unless invite.notification_sent_at.present?
invite.save
end
|
ruby
|
def send_org_invite(user, invite)
# Generate token if not generated
user.send(:generate_confirmation_token!) if !user.confirmed? && user.confirmation_token.blank?
MnoEnterprise::SystemNotificationMailer.organization_invite(invite).deliver_later
# Update staged invite status
invite.status = 'pending' if invite.status == 'staged'
invite.notification_sent_at = Time.now unless invite.notification_sent_at.present?
invite.save
end
|
[
"def",
"send_org_invite",
"(",
"user",
",",
"invite",
")",
"# Generate token if not generated",
"user",
".",
"send",
"(",
":generate_confirmation_token!",
")",
"if",
"!",
"user",
".",
"confirmed?",
"&&",
"user",
".",
"confirmation_token",
".",
"blank?",
"MnoEnterprise",
"::",
"SystemNotificationMailer",
".",
"organization_invite",
"(",
"invite",
")",
".",
"deliver_later",
"# Update staged invite status",
"invite",
".",
"status",
"=",
"'pending'",
"if",
"invite",
".",
"status",
"==",
"'staged'",
"invite",
".",
"notification_sent_at",
"=",
"Time",
".",
"now",
"unless",
"invite",
".",
"notification_sent_at",
".",
"present?",
"invite",
".",
"save",
"end"
] |
Send the org invite and update the status
|
[
"Send",
"the",
"org",
"invite",
"and",
"update",
"the",
"status"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/app/controllers/mno_enterprise/jpi/v1/admin/invites_controller.rb#L28-L38
|
17,958
|
maestrano/mno-enterprise
|
api/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
|
MnoEnterprise.Jpi::V1::BaseResourceController.check_authorization
|
def check_authorization
unless current_user
render nothing: true, status: :unauthorized
return false
end
if params[:organization_id] && !parent_organization
render nothing: true, status: :forbidden
return false
end
true
end
|
ruby
|
def check_authorization
unless current_user
render nothing: true, status: :unauthorized
return false
end
if params[:organization_id] && !parent_organization
render nothing: true, status: :forbidden
return false
end
true
end
|
[
"def",
"check_authorization",
"unless",
"current_user",
"render",
"nothing",
":",
"true",
",",
"status",
":",
":unauthorized",
"return",
"false",
"end",
"if",
"params",
"[",
":organization_id",
"]",
"&&",
"!",
"parent_organization",
"render",
"nothing",
":",
"true",
",",
"status",
":",
":forbidden",
"return",
"false",
"end",
"true",
"end"
] |
Check current user is logged in
Check organization is valid if specified
|
[
"Check",
"current",
"user",
"is",
"logged",
"in",
"Check",
"organization",
"is",
"valid",
"if",
"specified"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb#L20-L30
|
17,959
|
maestrano/mno-enterprise
|
core/app/models/mno_enterprise/base_resource.rb
|
MnoEnterprise.BaseResource.save!
|
def save!(options={})
if perform_validations(options)
ret = super()
process_response_errors
raise_record_invalid if self.errors.any?
ret
else
raise_record_invalid
end
end
|
ruby
|
def save!(options={})
if perform_validations(options)
ret = super()
process_response_errors
raise_record_invalid if self.errors.any?
ret
else
raise_record_invalid
end
end
|
[
"def",
"save!",
"(",
"options",
"=",
"{",
"}",
")",
"if",
"perform_validations",
"(",
"options",
")",
"ret",
"=",
"super",
"(",
")",
"process_response_errors",
"raise_record_invalid",
"if",
"self",
".",
"errors",
".",
"any?",
"ret",
"else",
"raise_record_invalid",
"end",
"end"
] |
ActiveRecord Compatibility for Her
|
[
"ActiveRecord",
"Compatibility",
"for",
"Her"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/models/mno_enterprise/base_resource.rb#L149-L158
|
17,960
|
maestrano/mno-enterprise
|
core/app/models/mno_enterprise/user.rb
|
MnoEnterprise.User.role
|
def role(organization = nil)
# Return cached version if available
return self.read_attribute(:role) if !organization
# Find in arrays if organizations have been fetched
# already. Perform remote query otherwise
org = begin
if self.organizations.loaded?
self.organizations.to_a.find { |e| e.id == organization.id }
else
self.organizations.where(id: organization.id).first
end
end
org ? org.role : nil
end
|
ruby
|
def role(organization = nil)
# Return cached version if available
return self.read_attribute(:role) if !organization
# Find in arrays if organizations have been fetched
# already. Perform remote query otherwise
org = begin
if self.organizations.loaded?
self.organizations.to_a.find { |e| e.id == organization.id }
else
self.organizations.where(id: organization.id).first
end
end
org ? org.role : nil
end
|
[
"def",
"role",
"(",
"organization",
"=",
"nil",
")",
"# Return cached version if available",
"return",
"self",
".",
"read_attribute",
"(",
":role",
")",
"if",
"!",
"organization",
"# Find in arrays if organizations have been fetched",
"# already. Perform remote query otherwise",
"org",
"=",
"begin",
"if",
"self",
".",
"organizations",
".",
"loaded?",
"self",
".",
"organizations",
".",
"to_a",
".",
"find",
"{",
"|",
"e",
"|",
"e",
".",
"id",
"==",
"organization",
".",
"id",
"}",
"else",
"self",
".",
"organizations",
".",
"where",
"(",
"id",
":",
"organization",
".",
"id",
")",
".",
"first",
"end",
"end",
"org",
"?",
"org",
".",
"role",
":",
"nil",
"end"
] |
Return the role of this user for the provided
organization
|
[
"Return",
"the",
"role",
"of",
"this",
"user",
"for",
"the",
"provided",
"organization"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/models/mno_enterprise/user.rb#L186-L201
|
17,961
|
maestrano/mno-enterprise
|
core/app/controllers/mno_enterprise/application_controller.rb
|
MnoEnterprise.ApplicationController.after_sign_in_path_for
|
def after_sign_in_path_for(resource)
previous_url = session.delete(:previous_url)
default_url = if resource.respond_to?(:admin_role) && resource.admin_role.present?
MnoEnterprise.router.admin_path
else
MnoEnterprise.router.dashboard_path || main_app.root_url
end
return (return_to_url(resource) || previous_url || default_url)
end
|
ruby
|
def after_sign_in_path_for(resource)
previous_url = session.delete(:previous_url)
default_url = if resource.respond_to?(:admin_role) && resource.admin_role.present?
MnoEnterprise.router.admin_path
else
MnoEnterprise.router.dashboard_path || main_app.root_url
end
return (return_to_url(resource) || previous_url || default_url)
end
|
[
"def",
"after_sign_in_path_for",
"(",
"resource",
")",
"previous_url",
"=",
"session",
".",
"delete",
"(",
":previous_url",
")",
"default_url",
"=",
"if",
"resource",
".",
"respond_to?",
"(",
":admin_role",
")",
"&&",
"resource",
".",
"admin_role",
".",
"present?",
"MnoEnterprise",
".",
"router",
".",
"admin_path",
"else",
"MnoEnterprise",
".",
"router",
".",
"dashboard_path",
"||",
"main_app",
".",
"root_url",
"end",
"return",
"(",
"return_to_url",
"(",
"resource",
")",
"||",
"previous_url",
"||",
"default_url",
")",
"end"
] |
Redirect to previous url and reset it
|
[
"Redirect",
"to",
"previous",
"url",
"and",
"reset",
"it"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/controllers/mno_enterprise/application_controller.rb#L96-L104
|
17,962
|
maestrano/mno-enterprise
|
core/app/models/mno_enterprise/impac/dashboard.rb
|
MnoEnterprise.Impac::Dashboard.organizations
|
def organizations(org_list = nil)
if org_list
return org_list if dashboard_type == 'template'
org_list.to_a.select { |e| organization_ids.include?(e.uid) || organization_ids.include?(e.id) }
else
MnoEnterprise::Organization.where('uid.in' => organization_ids).to_a
end
end
|
ruby
|
def organizations(org_list = nil)
if org_list
return org_list if dashboard_type == 'template'
org_list.to_a.select { |e| organization_ids.include?(e.uid) || organization_ids.include?(e.id) }
else
MnoEnterprise::Organization.where('uid.in' => organization_ids).to_a
end
end
|
[
"def",
"organizations",
"(",
"org_list",
"=",
"nil",
")",
"if",
"org_list",
"return",
"org_list",
"if",
"dashboard_type",
"==",
"'template'",
"org_list",
".",
"to_a",
".",
"select",
"{",
"|",
"e",
"|",
"organization_ids",
".",
"include?",
"(",
"e",
".",
"uid",
")",
"||",
"organization_ids",
".",
"include?",
"(",
"e",
".",
"id",
")",
"}",
"else",
"MnoEnterprise",
"::",
"Organization",
".",
"where",
"(",
"'uid.in'",
"=>",
"organization_ids",
")",
".",
"to_a",
"end",
"end"
] |
Return all the organizations linked to this dashboard and to which the user has access
If the dashboard is a template, return all the current user's organizations
|
[
"Return",
"all",
"the",
"organizations",
"linked",
"to",
"this",
"dashboard",
"and",
"to",
"which",
"the",
"user",
"has",
"access",
"If",
"the",
"dashboard",
"is",
"a",
"template",
"return",
"all",
"the",
"current",
"user",
"s",
"organizations"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/models/mno_enterprise/impac/dashboard.rb#L26-L33
|
17,963
|
maestrano/mno-enterprise
|
core/app/models/mno_enterprise/impac/dashboard.rb
|
MnoEnterprise.Impac::Dashboard.filtered_widgets_templates
|
def filtered_widgets_templates
if MnoEnterprise.widgets_templates_listing
return self.widgets_templates.select do |t|
MnoEnterprise.widgets_templates_listing.include?(t[:path])
end
else
return self.widgets_templates
end
end
|
ruby
|
def filtered_widgets_templates
if MnoEnterprise.widgets_templates_listing
return self.widgets_templates.select do |t|
MnoEnterprise.widgets_templates_listing.include?(t[:path])
end
else
return self.widgets_templates
end
end
|
[
"def",
"filtered_widgets_templates",
"if",
"MnoEnterprise",
".",
"widgets_templates_listing",
"return",
"self",
".",
"widgets_templates",
".",
"select",
"do",
"|",
"t",
"|",
"MnoEnterprise",
".",
"widgets_templates_listing",
".",
"include?",
"(",
"t",
"[",
":path",
"]",
")",
"end",
"else",
"return",
"self",
".",
"widgets_templates",
"end",
"end"
] |
Filter widgets list based on config
|
[
"Filter",
"widgets",
"list",
"based",
"on",
"config"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/models/mno_enterprise/impac/dashboard.rb#L36-L44
|
17,964
|
salesforce/flo
|
lib/flo/command.rb
|
Flo.Command.call
|
def call(args={})
evaluate_command_definition(args)
response = tasks.map do |task|
response = task.call(args)
# bail early if the task failed
return response unless response.success?
response
end.last
end
|
ruby
|
def call(args={})
evaluate_command_definition(args)
response = tasks.map do |task|
response = task.call(args)
# bail early if the task failed
return response unless response.success?
response
end.last
end
|
[
"def",
"call",
"(",
"args",
"=",
"{",
"}",
")",
"evaluate_command_definition",
"(",
"args",
")",
"response",
"=",
"tasks",
".",
"map",
"do",
"|",
"task",
"|",
"response",
"=",
"task",
".",
"call",
"(",
"args",
")",
"# bail early if the task failed",
"return",
"response",
"unless",
"response",
".",
"success?",
"response",
"end",
".",
"last",
"end"
] |
Invoke the command that has already been defined.
This will run the command, processing any tasks defined by {#perform} and
{#validate} in order, stopping execution if any of the tasks fails.
Arguments passed in here will be merged with the provider options defined
in each task.
@param args [Hash] arguments to be passed to each task
|
[
"Invoke",
"the",
"command",
"that",
"has",
"already",
"been",
"defined",
"."
] |
34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a
|
https://github.com/salesforce/flo/blob/34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a/lib/flo/command.rb#L78-L88
|
17,965
|
salesforce/flo
|
lib/flo/command.rb
|
Flo.Command.optional_parameters
|
def optional_parameters
definition_lambda.parameters.select { |key,_value| key == :key }.map { |_key,value| value }
end
|
ruby
|
def optional_parameters
definition_lambda.parameters.select { |key,_value| key == :key }.map { |_key,value| value }
end
|
[
"def",
"optional_parameters",
"definition_lambda",
".",
"parameters",
".",
"select",
"{",
"|",
"key",
",",
"_value",
"|",
"key",
"==",
":key",
"}",
".",
"map",
"{",
"|",
"_key",
",",
"value",
"|",
"value",
"}",
"end"
] |
Returns a list of any optional parameters
Optional parameters are generated automatically by inspecting the optional
parameters for the definition lambda
@return [Array<Symbol>] An array of symbols representing optional parameters
|
[
"Returns",
"a",
"list",
"of",
"any",
"optional",
"parameters"
] |
34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a
|
https://github.com/salesforce/flo/blob/34c01f22e0a5d065f879aaed9fbdf3f2a9b2163a/lib/flo/command.rb#L107-L109
|
17,966
|
maestrano/mno-enterprise
|
api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb
|
MnoEnterprise.Jpi::V1::Admin::ThemeController.save_previewer_style
|
def save_previewer_style(theme)
target = Rails.root.join('frontend', 'src','app','stylesheets','theme-previewer-tmp.less')
File.open(target, 'w') { |f| f.write(theme_to_less(theme)) }
end
|
ruby
|
def save_previewer_style(theme)
target = Rails.root.join('frontend', 'src','app','stylesheets','theme-previewer-tmp.less')
File.open(target, 'w') { |f| f.write(theme_to_less(theme)) }
end
|
[
"def",
"save_previewer_style",
"(",
"theme",
")",
"target",
"=",
"Rails",
".",
"root",
".",
"join",
"(",
"'frontend'",
",",
"'src'",
",",
"'app'",
",",
"'stylesheets'",
",",
"'theme-previewer-tmp.less'",
")",
"File",
".",
"open",
"(",
"target",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"theme_to_less",
"(",
"theme",
")",
")",
"}",
"end"
] |
Save current style to theme-previewer-tmp.less stylesheet
This file overrides theme-previewer-published.less
|
[
"Save",
"current",
"style",
"to",
"theme",
"-",
"previewer",
"-",
"tmp",
".",
"less",
"stylesheet",
"This",
"file",
"overrides",
"theme",
"-",
"previewer",
"-",
"published",
".",
"less"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb#L55-L58
|
17,967
|
maestrano/mno-enterprise
|
api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb
|
MnoEnterprise.Jpi::V1::Admin::ThemeController.apply_previewer_style
|
def apply_previewer_style(theme)
target = Rails.root.join('frontend', 'src','app','stylesheets','theme-previewer-published.less')
File.open(target, 'w') { |f| f.write(theme_to_less(theme)) }
reset_previewer_style
end
|
ruby
|
def apply_previewer_style(theme)
target = Rails.root.join('frontend', 'src','app','stylesheets','theme-previewer-published.less')
File.open(target, 'w') { |f| f.write(theme_to_less(theme)) }
reset_previewer_style
end
|
[
"def",
"apply_previewer_style",
"(",
"theme",
")",
"target",
"=",
"Rails",
".",
"root",
".",
"join",
"(",
"'frontend'",
",",
"'src'",
",",
"'app'",
",",
"'stylesheets'",
",",
"'theme-previewer-published.less'",
")",
"File",
".",
"open",
"(",
"target",
",",
"'w'",
")",
"{",
"|",
"f",
"|",
"f",
".",
"write",
"(",
"theme_to_less",
"(",
"theme",
")",
")",
"}",
"reset_previewer_style",
"end"
] |
Save style to theme-previewer-published.less and discard theme-previewer-tmp.less
|
[
"Save",
"style",
"to",
"theme",
"-",
"previewer",
"-",
"published",
".",
"less",
"and",
"discard",
"theme",
"-",
"previewer",
"-",
"tmp",
".",
"less"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb#L61-L65
|
17,968
|
maestrano/mno-enterprise
|
api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb
|
MnoEnterprise.Jpi::V1::Admin::ThemeController.theme_to_less
|
def theme_to_less(theme)
out = "// Generated by the Express Theme Previewer\n"
if theme[:branding]
out += "\n//----------------------------------------\n"
out += "// General Branding\n"
out += "//----------------------------------------\n"
out += theme[:branding].map { |k,v| "#{k}: #{v};" }.join("\n")
out += "\n"
end
if theme[:variables]
out += "\n//----------------------------------------\n"
out += "// Theme Variables\n"
out += "//----------------------------------------\n"
theme[:variables].each do |section,vars|
out += "// #{section}\n"
out += vars.map { |k,v| "#{k}: #{v};" }.join("\n")
out += "\n\n"
end
end
return out
end
|
ruby
|
def theme_to_less(theme)
out = "// Generated by the Express Theme Previewer\n"
if theme[:branding]
out += "\n//----------------------------------------\n"
out += "// General Branding\n"
out += "//----------------------------------------\n"
out += theme[:branding].map { |k,v| "#{k}: #{v};" }.join("\n")
out += "\n"
end
if theme[:variables]
out += "\n//----------------------------------------\n"
out += "// Theme Variables\n"
out += "//----------------------------------------\n"
theme[:variables].each do |section,vars|
out += "// #{section}\n"
out += vars.map { |k,v| "#{k}: #{v};" }.join("\n")
out += "\n\n"
end
end
return out
end
|
[
"def",
"theme_to_less",
"(",
"theme",
")",
"out",
"=",
"\"// Generated by the Express Theme Previewer\\n\"",
"if",
"theme",
"[",
":branding",
"]",
"out",
"+=",
"\"\\n//----------------------------------------\\n\"",
"out",
"+=",
"\"// General Branding\\n\"",
"out",
"+=",
"\"//----------------------------------------\\n\"",
"out",
"+=",
"theme",
"[",
":branding",
"]",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}: #{v};\"",
"}",
".",
"join",
"(",
"\"\\n\"",
")",
"out",
"+=",
"\"\\n\"",
"end",
"if",
"theme",
"[",
":variables",
"]",
"out",
"+=",
"\"\\n//----------------------------------------\\n\"",
"out",
"+=",
"\"// Theme Variables\\n\"",
"out",
"+=",
"\"//----------------------------------------\\n\"",
"theme",
"[",
":variables",
"]",
".",
"each",
"do",
"|",
"section",
",",
"vars",
"|",
"out",
"+=",
"\"// #{section}\\n\"",
"out",
"+=",
"vars",
".",
"map",
"{",
"|",
"k",
",",
"v",
"|",
"\"#{k}: #{v};\"",
"}",
".",
"join",
"(",
"\"\\n\"",
")",
"out",
"+=",
"\"\\n\\n\"",
"end",
"end",
"return",
"out",
"end"
] |
Convert a theme provided as a hash into a properly
formatted LESS file
|
[
"Convert",
"a",
"theme",
"provided",
"as",
"a",
"hash",
"into",
"a",
"properly",
"formatted",
"LESS",
"file"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/api/app/controllers/mno_enterprise/jpi/v1/admin/theme_controller.rb#L84-L107
|
17,969
|
maestrano/mno-enterprise
|
core/app/pdf/mno_enterprise/invoice_pdf.rb
|
MnoEnterprise.InvoicePdf.generate_content
|
def generate_content
@pdf = Prawn::Document.new(
info: self.metadata,
top_margin: @format[:header_size] + @format[:top_margin],
bottom_margin: @format[:footer_size] + @format[:bottom_margin]
)
add_page_body
add_page_header
add_page_footer
add_page_numbering
end
|
ruby
|
def generate_content
@pdf = Prawn::Document.new(
info: self.metadata,
top_margin: @format[:header_size] + @format[:top_margin],
bottom_margin: @format[:footer_size] + @format[:bottom_margin]
)
add_page_body
add_page_header
add_page_footer
add_page_numbering
end
|
[
"def",
"generate_content",
"@pdf",
"=",
"Prawn",
"::",
"Document",
".",
"new",
"(",
"info",
":",
"self",
".",
"metadata",
",",
"top_margin",
":",
"@format",
"[",
":header_size",
"]",
"+",
"@format",
"[",
":top_margin",
"]",
",",
"bottom_margin",
":",
"@format",
"[",
":footer_size",
"]",
"+",
"@format",
"[",
":bottom_margin",
"]",
")",
"add_page_body",
"add_page_header",
"add_page_footer",
"add_page_numbering",
"end"
] |
Generate the document content
by adding body, header, footer and
page numbering
|
[
"Generate",
"the",
"document",
"content",
"by",
"adding",
"body",
"header",
"footer",
"and",
"page",
"numbering"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/pdf/mno_enterprise/invoice_pdf.rb#L97-L107
|
17,970
|
maestrano/mno-enterprise
|
core/app/pdf/mno_enterprise/invoice_pdf.rb
|
MnoEnterprise.InvoicePdf.add_page_header
|
def add_page_header
title = Settings.payment.disabled ? 'Account Statement - ' : 'Monthly Invoice - '
@pdf.repeat :all do
@pdf.bounding_box([0, @pdf.bounds.top+@format[:header_size]], width: 540, height: @format[:footer_size]) do
@pdf.float do
@pdf.image main_logo_white_bg_path(true), fit: [135, (@format[:footer_size])]
end
@pdf.move_down 52
@pdf.font_size(20) { @pdf.text "#{title} #{@data[:period_month]}", style: :bold, align: :right }
end
end
end
|
ruby
|
def add_page_header
title = Settings.payment.disabled ? 'Account Statement - ' : 'Monthly Invoice - '
@pdf.repeat :all do
@pdf.bounding_box([0, @pdf.bounds.top+@format[:header_size]], width: 540, height: @format[:footer_size]) do
@pdf.float do
@pdf.image main_logo_white_bg_path(true), fit: [135, (@format[:footer_size])]
end
@pdf.move_down 52
@pdf.font_size(20) { @pdf.text "#{title} #{@data[:period_month]}", style: :bold, align: :right }
end
end
end
|
[
"def",
"add_page_header",
"title",
"=",
"Settings",
".",
"payment",
".",
"disabled",
"?",
"'Account Statement - '",
":",
"'Monthly Invoice - '",
"@pdf",
".",
"repeat",
":all",
"do",
"@pdf",
".",
"bounding_box",
"(",
"[",
"0",
",",
"@pdf",
".",
"bounds",
".",
"top",
"+",
"@format",
"[",
":header_size",
"]",
"]",
",",
"width",
":",
"540",
",",
"height",
":",
"@format",
"[",
":footer_size",
"]",
")",
"do",
"@pdf",
".",
"float",
"do",
"@pdf",
".",
"image",
"main_logo_white_bg_path",
"(",
"true",
")",
",",
"fit",
":",
"[",
"135",
",",
"(",
"@format",
"[",
":footer_size",
"]",
")",
"]",
"end",
"@pdf",
".",
"move_down",
"52",
"@pdf",
".",
"font_size",
"(",
"20",
")",
"{",
"@pdf",
".",
"text",
"\"#{title} #{@data[:period_month]}\"",
",",
"style",
":",
":bold",
",",
"align",
":",
":right",
"}",
"end",
"end",
"end"
] |
Add a repeated header to the document
|
[
"Add",
"a",
"repeated",
"header",
"to",
"the",
"document"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/pdf/mno_enterprise/invoice_pdf.rb#L126-L137
|
17,971
|
maestrano/mno-enterprise
|
core/app/pdf/mno_enterprise/invoice_pdf.rb
|
MnoEnterprise.InvoicePdf.add_page_footer
|
def add_page_footer
@pdf.repeat :all do
@pdf.bounding_box([0, @pdf.bounds.bottom], width: 540, height: @format[:footer_size]) do
@pdf.move_down 50
@pdf.stroke_color '999999'
@pdf.stroke_horizontal_rule
@pdf.move_down 10
@pdf.font_size(8) do
@pdf.text "<color rgb='999999'>This invoice has been generated by Maestrano Pty Ltd on behalf of the #{MnoEnterprise.app_name} platform (the \"Service\").</color>", inline_format: true
@pdf.text "<color rgb='999999'>All charges in this invoice are in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]}). Credit card payments will be processed by Maestrano Pty Ltd.</color>", inline_format: true
@pdf.text " ", inline_format: true
@pdf.text "<color rgb='999999'>Maestrano Pty Ltd | Suite 504, 46 Market Street, Sydney, NSW 2000, Australia | ABN: 80 152 564 424</color>", inline_format: true
end
end
end
end
|
ruby
|
def add_page_footer
@pdf.repeat :all do
@pdf.bounding_box([0, @pdf.bounds.bottom], width: 540, height: @format[:footer_size]) do
@pdf.move_down 50
@pdf.stroke_color '999999'
@pdf.stroke_horizontal_rule
@pdf.move_down 10
@pdf.font_size(8) do
@pdf.text "<color rgb='999999'>This invoice has been generated by Maestrano Pty Ltd on behalf of the #{MnoEnterprise.app_name} platform (the \"Service\").</color>", inline_format: true
@pdf.text "<color rgb='999999'>All charges in this invoice are in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]}). Credit card payments will be processed by Maestrano Pty Ltd.</color>", inline_format: true
@pdf.text " ", inline_format: true
@pdf.text "<color rgb='999999'>Maestrano Pty Ltd | Suite 504, 46 Market Street, Sydney, NSW 2000, Australia | ABN: 80 152 564 424</color>", inline_format: true
end
end
end
end
|
[
"def",
"add_page_footer",
"@pdf",
".",
"repeat",
":all",
"do",
"@pdf",
".",
"bounding_box",
"(",
"[",
"0",
",",
"@pdf",
".",
"bounds",
".",
"bottom",
"]",
",",
"width",
":",
"540",
",",
"height",
":",
"@format",
"[",
":footer_size",
"]",
")",
"do",
"@pdf",
".",
"move_down",
"50",
"@pdf",
".",
"stroke_color",
"'999999'",
"@pdf",
".",
"stroke_horizontal_rule",
"@pdf",
".",
"move_down",
"10",
"@pdf",
".",
"font_size",
"(",
"8",
")",
"do",
"@pdf",
".",
"text",
"\"<color rgb='999999'>This invoice has been generated by Maestrano Pty Ltd on behalf of the #{MnoEnterprise.app_name} platform (the \\\"Service\\\").</color>\"",
",",
"inline_format",
":",
"true",
"@pdf",
".",
"text",
"\"<color rgb='999999'>All charges in this invoice are in #{@data[:invoice_currency_name]} (#{@data[:invoice_currency]}). Credit card payments will be processed by Maestrano Pty Ltd.</color>\"",
",",
"inline_format",
":",
"true",
"@pdf",
".",
"text",
"\" \"",
",",
"inline_format",
":",
"true",
"@pdf",
".",
"text",
"\"<color rgb='999999'>Maestrano Pty Ltd | Suite 504, 46 Market Street, Sydney, NSW 2000, Australia | ABN: 80 152 564 424</color>\"",
",",
"inline_format",
":",
"true",
"end",
"end",
"end",
"end"
] |
Add a repeated footer to the document
|
[
"Add",
"a",
"repeated",
"footer",
"to",
"the",
"document"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/pdf/mno_enterprise/invoice_pdf.rb#L140-L155
|
17,972
|
maestrano/mno-enterprise
|
core/app/pdf/mno_enterprise/invoice_pdf.rb
|
MnoEnterprise.InvoicePdf.add_page_numbering
|
def add_page_numbering
numbering_options = {
at: [@pdf.bounds.right - 150, 0-@format[:footer_size]],
width: 150,
align: :right,
start_count_at: 1,
color: "999999",
size: 8
}
@pdf.number_pages "Page <page> of <total>", numbering_options
end
|
ruby
|
def add_page_numbering
numbering_options = {
at: [@pdf.bounds.right - 150, 0-@format[:footer_size]],
width: 150,
align: :right,
start_count_at: 1,
color: "999999",
size: 8
}
@pdf.number_pages "Page <page> of <total>", numbering_options
end
|
[
"def",
"add_page_numbering",
"numbering_options",
"=",
"{",
"at",
":",
"[",
"@pdf",
".",
"bounds",
".",
"right",
"-",
"150",
",",
"0",
"-",
"@format",
"[",
":footer_size",
"]",
"]",
",",
"width",
":",
"150",
",",
"align",
":",
":right",
",",
"start_count_at",
":",
"1",
",",
"color",
":",
"\"999999\"",
",",
"size",
":",
"8",
"}",
"@pdf",
".",
"number_pages",
"\"Page <page> of <total>\"",
",",
"numbering_options",
"end"
] |
Add page number on every page
|
[
"Add",
"page",
"number",
"on",
"every",
"page"
] |
bd957f523959531926e2bf844608d77addef2047
|
https://github.com/maestrano/mno-enterprise/blob/bd957f523959531926e2bf844608d77addef2047/core/app/pdf/mno_enterprise/invoice_pdf.rb#L158-L168
|
17,973
|
NCSU-Libraries/quick_search
|
app/searchers/quick_search/best_bets_searcher.rb
|
QuickSearch.BestBetsSearcher.search_best_bets_index
|
def search_best_bets_index
response = @http.get(query_url)
parsed_response = JSON.parse(response.body)
if parsed_response['response']['numFound'].to_s == '0'
return nil
else
resp = parsed_response['response']['docs'][0]
result = OpenStruct.new
result.title = title(resp)
result.link = link(resp)
result.id = id(resp)
result.description = description(resp)
result.best_bets_type = 'best-bets-regular'
@response = result
end
end
|
ruby
|
def search_best_bets_index
response = @http.get(query_url)
parsed_response = JSON.parse(response.body)
if parsed_response['response']['numFound'].to_s == '0'
return nil
else
resp = parsed_response['response']['docs'][0]
result = OpenStruct.new
result.title = title(resp)
result.link = link(resp)
result.id = id(resp)
result.description = description(resp)
result.best_bets_type = 'best-bets-regular'
@response = result
end
end
|
[
"def",
"search_best_bets_index",
"response",
"=",
"@http",
".",
"get",
"(",
"query_url",
")",
"parsed_response",
"=",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"if",
"parsed_response",
"[",
"'response'",
"]",
"[",
"'numFound'",
"]",
".",
"to_s",
"==",
"'0'",
"return",
"nil",
"else",
"resp",
"=",
"parsed_response",
"[",
"'response'",
"]",
"[",
"'docs'",
"]",
"[",
"0",
"]",
"result",
"=",
"OpenStruct",
".",
"new",
"result",
".",
"title",
"=",
"title",
"(",
"resp",
")",
"result",
".",
"link",
"=",
"link",
"(",
"resp",
")",
"result",
".",
"id",
"=",
"id",
"(",
"resp",
")",
"result",
".",
"description",
"=",
"description",
"(",
"resp",
")",
"result",
".",
"best_bets_type",
"=",
"'best-bets-regular'",
"@response",
"=",
"result",
"end",
"end"
] |
Regular Best Bets
|
[
"Regular",
"Best",
"Bets"
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/searchers/quick_search/best_bets_searcher.rb#L34-L50
|
17,974
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/typeahead_controller.rb
|
QuickSearch.TypeaheadController.typeahead
|
def typeahead
# :searcher param expected to be name of a searcher with underscores, ie: ematrix_journal
searcher = params[:searcher]
query = params[:q] or ''
total = params[:total] or 3
if searcher.blank?
logger.error "Typeahead request: no searcher param provided"
head :bad_request
return nil
end
searcher_string = "QuickSearch::#{searcher.camelize}Searcher"
begin
klass = searcher_string.constantize
rescue NameError
logger.error "Typeahead request: searcher #{searcher} does not exist"
head :bad_request
return nil
end
if klass.method_defined? :typeahead
typeahead_result = klass.new(HTTPClient.new, query, total).typeahead
if params.has_key? 'callback'
render json: typeahead_result, callback: params['callback']
else
render json: typeahead_result
end
else
logger.error "Typeahead request: searcher #{searcher} has no typeahead method"
head :bad_request
return nil
end
end
|
ruby
|
def typeahead
# :searcher param expected to be name of a searcher with underscores, ie: ematrix_journal
searcher = params[:searcher]
query = params[:q] or ''
total = params[:total] or 3
if searcher.blank?
logger.error "Typeahead request: no searcher param provided"
head :bad_request
return nil
end
searcher_string = "QuickSearch::#{searcher.camelize}Searcher"
begin
klass = searcher_string.constantize
rescue NameError
logger.error "Typeahead request: searcher #{searcher} does not exist"
head :bad_request
return nil
end
if klass.method_defined? :typeahead
typeahead_result = klass.new(HTTPClient.new, query, total).typeahead
if params.has_key? 'callback'
render json: typeahead_result, callback: params['callback']
else
render json: typeahead_result
end
else
logger.error "Typeahead request: searcher #{searcher} has no typeahead method"
head :bad_request
return nil
end
end
|
[
"def",
"typeahead",
"# :searcher param expected to be name of a searcher with underscores, ie: ematrix_journal",
"searcher",
"=",
"params",
"[",
":searcher",
"]",
"query",
"=",
"params",
"[",
":q",
"]",
"or",
"''",
"total",
"=",
"params",
"[",
":total",
"]",
"or",
"3",
"if",
"searcher",
".",
"blank?",
"logger",
".",
"error",
"\"Typeahead request: no searcher param provided\"",
"head",
":bad_request",
"return",
"nil",
"end",
"searcher_string",
"=",
"\"QuickSearch::#{searcher.camelize}Searcher\"",
"begin",
"klass",
"=",
"searcher_string",
".",
"constantize",
"rescue",
"NameError",
"logger",
".",
"error",
"\"Typeahead request: searcher #{searcher} does not exist\"",
"head",
":bad_request",
"return",
"nil",
"end",
"if",
"klass",
".",
"method_defined?",
":typeahead",
"typeahead_result",
"=",
"klass",
".",
"new",
"(",
"HTTPClient",
".",
"new",
",",
"query",
",",
"total",
")",
".",
"typeahead",
"if",
"params",
".",
"has_key?",
"'callback'",
"render",
"json",
":",
"typeahead_result",
",",
"callback",
":",
"params",
"[",
"'callback'",
"]",
"else",
"render",
"json",
":",
"typeahead_result",
"end",
"else",
"logger",
".",
"error",
"\"Typeahead request: searcher #{searcher} has no typeahead method\"",
"head",
":bad_request",
"return",
"nil",
"end",
"end"
] |
This method should return a list of search suggestions for a given searcher
It should return errors if there is no param called 'searcher', if the searcher does not exist
or if the searcher doesn't implement the 'typeahead' method
Otherwise, it should return the result of calling the 'typeahead' method as JSON
|
[
"This",
"method",
"should",
"return",
"a",
"list",
"of",
"search",
"suggestions",
"for",
"a",
"given",
"searcher",
"It",
"should",
"return",
"errors",
"if",
"there",
"is",
"no",
"param",
"called",
"searcher",
"if",
"the",
"searcher",
"does",
"not",
"exist",
"or",
"if",
"the",
"searcher",
"doesn",
"t",
"implement",
"the",
"typeahead",
"method",
"Otherwise",
"it",
"should",
"return",
"the",
"result",
"of",
"calling",
"the",
"typeahead",
"method",
"as",
"JSON"
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/typeahead_controller.rb#L10-L45
|
17,975
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/logging_controller.rb
|
QuickSearch.LoggingController.log_search
|
def log_search
if params[:query].present? && params[:page].present?
@session.searches.create(query: params[:query], page: params[:page])
head :ok
else
head :bad_request
end
end
|
ruby
|
def log_search
if params[:query].present? && params[:page].present?
@session.searches.create(query: params[:query], page: params[:page])
head :ok
else
head :bad_request
end
end
|
[
"def",
"log_search",
"if",
"params",
"[",
":query",
"]",
".",
"present?",
"&&",
"params",
"[",
":page",
"]",
".",
"present?",
"@session",
".",
"searches",
".",
"create",
"(",
"query",
":",
"params",
"[",
":query",
"]",
",",
"page",
":",
"params",
"[",
":page",
"]",
")",
"head",
":ok",
"else",
"head",
":bad_request",
"end",
"end"
] |
Logs a search to the database
This is an API endpoint for logging a search. It requires that at least a search query and a page are
present in the query parameters. It returns a 200 OK HTTP status if the request was successful, or
an 400 BAD REQUEST HTTP status if any parameters are missing.
|
[
"Logs",
"a",
"search",
"to",
"the",
"database"
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/logging_controller.rb#L20-L27
|
17,976
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/logging_controller.rb
|
QuickSearch.LoggingController.log_event
|
def log_event
if params[:category].present? && params[:event_action].present? && params[:label].present?
# if an action isn't passed in, assume that it is a click
action = params.fetch(:action_type, 'click')
# create a new event on the current session
@session.events.create(category: params[:category], item: params[:event_action], query: params[:label][0..250], action: action)
if params[:ga].present? and params[:ga]
send_event_to_ga(params[:category], params[:event_action], params[:label])
end
# check whether this is a jsonp request
if params[:callback].present?
render :json => { 'response': 'success' }, :callback => params[:callback]
else
render :json => { 'response': 'success' }
end
else
head :bad_request
end
end
|
ruby
|
def log_event
if params[:category].present? && params[:event_action].present? && params[:label].present?
# if an action isn't passed in, assume that it is a click
action = params.fetch(:action_type, 'click')
# create a new event on the current session
@session.events.create(category: params[:category], item: params[:event_action], query: params[:label][0..250], action: action)
if params[:ga].present? and params[:ga]
send_event_to_ga(params[:category], params[:event_action], params[:label])
end
# check whether this is a jsonp request
if params[:callback].present?
render :json => { 'response': 'success' }, :callback => params[:callback]
else
render :json => { 'response': 'success' }
end
else
head :bad_request
end
end
|
[
"def",
"log_event",
"if",
"params",
"[",
":category",
"]",
".",
"present?",
"&&",
"params",
"[",
":event_action",
"]",
".",
"present?",
"&&",
"params",
"[",
":label",
"]",
".",
"present?",
"# if an action isn't passed in, assume that it is a click",
"action",
"=",
"params",
".",
"fetch",
"(",
":action_type",
",",
"'click'",
")",
"# create a new event on the current session",
"@session",
".",
"events",
".",
"create",
"(",
"category",
":",
"params",
"[",
":category",
"]",
",",
"item",
":",
"params",
"[",
":event_action",
"]",
",",
"query",
":",
"params",
"[",
":label",
"]",
"[",
"0",
"..",
"250",
"]",
",",
"action",
":",
"action",
")",
"if",
"params",
"[",
":ga",
"]",
".",
"present?",
"and",
"params",
"[",
":ga",
"]",
"send_event_to_ga",
"(",
"params",
"[",
":category",
"]",
",",
"params",
"[",
":event_action",
"]",
",",
"params",
"[",
":label",
"]",
")",
"end",
"# check whether this is a jsonp request",
"if",
"params",
"[",
":callback",
"]",
".",
"present?",
"render",
":json",
"=>",
"{",
"'response'",
":",
"'success'",
"}",
",",
":callback",
"=>",
"params",
"[",
":callback",
"]",
"else",
"render",
":json",
"=>",
"{",
"'response'",
":",
"'success'",
"}",
"end",
"else",
"head",
":bad_request",
"end",
"end"
] |
Logs an event to the database. Typically, these can be clicks or serves.
This is an API endpoint for logging an event. It requires that at least a TODO are
present in the query parameters. It returns a 200 OK HTTP status if the request was successful, or
an 400 BAD REQUEST HTTP status if any parameters are missing. This endpoint supports JSONP requests.
|
[
"Logs",
"an",
"event",
"to",
"the",
"database",
".",
"Typically",
"these",
"can",
"be",
"clicks",
"or",
"serves",
"."
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/logging_controller.rb#L36-L57
|
17,977
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/logging_controller.rb
|
QuickSearch.LoggingController.new_session
|
def new_session
on_campus = on_campus?(request.remote_ip)
is_mobile = is_mobile?
session_expiry = 5.minutes.from_now
session_uuid = SecureRandom.uuid
# create session in db
@session = Session.create(session_uuid: session_uuid, expiry: session_expiry, on_campus: on_campus, is_mobile: is_mobile)
# set cookie
cookies[:session_id] = { :value => session_uuid, :expires => session_expiry }
end
|
ruby
|
def new_session
on_campus = on_campus?(request.remote_ip)
is_mobile = is_mobile?
session_expiry = 5.minutes.from_now
session_uuid = SecureRandom.uuid
# create session in db
@session = Session.create(session_uuid: session_uuid, expiry: session_expiry, on_campus: on_campus, is_mobile: is_mobile)
# set cookie
cookies[:session_id] = { :value => session_uuid, :expires => session_expiry }
end
|
[
"def",
"new_session",
"on_campus",
"=",
"on_campus?",
"(",
"request",
".",
"remote_ip",
")",
"is_mobile",
"=",
"is_mobile?",
"session_expiry",
"=",
"5",
".",
"minutes",
".",
"from_now",
"session_uuid",
"=",
"SecureRandom",
".",
"uuid",
"# create session in db",
"@session",
"=",
"Session",
".",
"create",
"(",
"session_uuid",
":",
"session_uuid",
",",
"expiry",
":",
"session_expiry",
",",
"on_campus",
":",
"on_campus",
",",
"is_mobile",
":",
"is_mobile",
")",
"# set cookie",
"cookies",
"[",
":session_id",
"]",
"=",
"{",
":value",
"=>",
"session_uuid",
",",
":expires",
"=>",
"session_expiry",
"}",
"end"
] |
Creates a new session, and logs it in the database
A session is tracked by a UUID that is stored in a cookie, and has a 5 minute expiry time.
Sessions are stored in the database with the time they were initiated, their expiry time (or end time),
whether the request originated from a campus IP address, and whether the request originated from a mobile device
|
[
"Creates",
"a",
"new",
"session",
"and",
"logs",
"it",
"in",
"the",
"database"
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/logging_controller.rb#L135-L145
|
17,978
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/logging_controller.rb
|
QuickSearch.LoggingController.update_session
|
def update_session
# update session expiry in the database
session_id = cookies[:session_id]
@session = Session.find_by session_uuid: session_id
@session.expiry = 5.minutes.from_now
@session.save
# update session expiry on cookie
cookies[:session_id] = { :value => session_id, :expires => @session.expiry }
end
|
ruby
|
def update_session
# update session expiry in the database
session_id = cookies[:session_id]
@session = Session.find_by session_uuid: session_id
@session.expiry = 5.minutes.from_now
@session.save
# update session expiry on cookie
cookies[:session_id] = { :value => session_id, :expires => @session.expiry }
end
|
[
"def",
"update_session",
"# update session expiry in the database",
"session_id",
"=",
"cookies",
"[",
":session_id",
"]",
"@session",
"=",
"Session",
".",
"find_by",
"session_uuid",
":",
"session_id",
"@session",
".",
"expiry",
"=",
"5",
".",
"minutes",
".",
"from_now",
"@session",
".",
"save",
"# update session expiry on cookie",
"cookies",
"[",
":session_id",
"]",
"=",
"{",
":value",
"=>",
"session_id",
",",
":expires",
"=>",
"@session",
".",
"expiry",
"}",
"end"
] |
Updates a session's expiration time on cookie and in database
When a request is made with a non-expired session, the expiration time is updated to 5 minutes from the current time.
This update is reflected in the cookie as well as in the database entry for the session.
|
[
"Updates",
"a",
"session",
"s",
"expiration",
"time",
"on",
"cookie",
"and",
"in",
"database"
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/logging_controller.rb#L153-L162
|
17,979
|
NCSU-Libraries/quick_search
|
app/searchers/quick_search/searcher.rb
|
QuickSearch.Searcher.no_results_link
|
def no_results_link(service_name, i18n_key, default_i18n_key = nil)
if (i18n_key.present? && I18n.exists?(i18n_key)) ||
(default_i18n_key.present? && I18n.exists?(default_i18n_key))
locale_result = I18n.t(i18n_key, default: I18n.t(default_i18n_key))
return locale_result if locale_result
end
begin
config_class = "QuickSearch::Engine::#{service_name.upcase}_CONFIG".constantize
config_class['no_results_link']
rescue NameError
nil
end
end
|
ruby
|
def no_results_link(service_name, i18n_key, default_i18n_key = nil)
if (i18n_key.present? && I18n.exists?(i18n_key)) ||
(default_i18n_key.present? && I18n.exists?(default_i18n_key))
locale_result = I18n.t(i18n_key, default: I18n.t(default_i18n_key))
return locale_result if locale_result
end
begin
config_class = "QuickSearch::Engine::#{service_name.upcase}_CONFIG".constantize
config_class['no_results_link']
rescue NameError
nil
end
end
|
[
"def",
"no_results_link",
"(",
"service_name",
",",
"i18n_key",
",",
"default_i18n_key",
"=",
"nil",
")",
"if",
"(",
"i18n_key",
".",
"present?",
"&&",
"I18n",
".",
"exists?",
"(",
"i18n_key",
")",
")",
"||",
"(",
"default_i18n_key",
".",
"present?",
"&&",
"I18n",
".",
"exists?",
"(",
"default_i18n_key",
")",
")",
"locale_result",
"=",
"I18n",
".",
"t",
"(",
"i18n_key",
",",
"default",
":",
"I18n",
".",
"t",
"(",
"default_i18n_key",
")",
")",
"return",
"locale_result",
"if",
"locale_result",
"end",
"begin",
"config_class",
"=",
"\"QuickSearch::Engine::#{service_name.upcase}_CONFIG\"",
".",
"constantize",
"config_class",
"[",
"'no_results_link'",
"]",
"rescue",
"NameError",
"nil",
"end",
"end"
] |
Returns a String representing the link to use when no results are
found for a search.
This default implementation first looks for the "i18n_key" and
"default_i18n_key" in the I18N locale files. If no entry is found
the "no_results_link" from the searcher configuration is returned.
Using the I18N locale files is considered legacy behavior (but
is preferred in this method to preserve existing functionality).
Use of the searcher configuration file is preferred.
|
[
"Returns",
"a",
"String",
"representing",
"the",
"link",
"to",
"use",
"when",
"no",
"results",
"are",
"found",
"for",
"a",
"search",
"."
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/searchers/quick_search/searcher.rb#L38-L51
|
17,980
|
NCSU-Libraries/quick_search
|
app/controllers/quick_search/search_controller.rb
|
QuickSearch.SearchController.xhr_search
|
def xhr_search
endpoint = params[:endpoint]
if params[:template] == 'with_paging'
template = 'xhr_response_with_paging'
else
template = 'xhr_response'
end
@query = params_q_scrubbed
@page = page
@per_page = per_page(endpoint)
@offset = offset(@page,@per_page)
http_client = HTTPClient.new
update_searcher_timeout(http_client, endpoint, true)
benchmark "%s xhr #{endpoint}" % CGI.escape(@query.to_str) do
klass = "QuickSearch::#{endpoint.camelize}Searcher".constantize
searcher = klass.new(http_client,
extracted_query(params_q_scrubbed),
@per_page,
@offset,
@page,
on_campus?(ip),
extracted_scope(params_q_scrubbed))
searcher.search
searcher_partials = {}
searcher_cfg = searcher_config(endpoint)
unless searcher_cfg.blank?
services = searcher_cfg['services'].blank? ? [] : searcher_cfg['services']
else
services = []
end
services << endpoint
respond_to do |format|
format.html {
services.each do |service|
service_template = render_to_string(
:partial => "quick_search/search/#{template}",
:layout => false,
:locals => { module_display_name: t("#{endpoint}_search.display_name"),
searcher: searcher,
search: '',
service_name: service
})
searcher_partials[service] = service_template
end
render :json => searcher_partials
}
format.json {
# prevents openstruct object from results being nested inside tables
# See: http://stackoverflow.com/questions/7835047/collecting-hashes-into-openstruct-creates-table-entry
result_list = []
searcher.results.each do |result|
result_list << result.to_h
end
render :json => { :endpoint => endpoint,
:per_page => @per_page.to_s,
:page => @page.to_s,
:total => searcher.total,
:results => result_list
}
}
end
end
end
|
ruby
|
def xhr_search
endpoint = params[:endpoint]
if params[:template] == 'with_paging'
template = 'xhr_response_with_paging'
else
template = 'xhr_response'
end
@query = params_q_scrubbed
@page = page
@per_page = per_page(endpoint)
@offset = offset(@page,@per_page)
http_client = HTTPClient.new
update_searcher_timeout(http_client, endpoint, true)
benchmark "%s xhr #{endpoint}" % CGI.escape(@query.to_str) do
klass = "QuickSearch::#{endpoint.camelize}Searcher".constantize
searcher = klass.new(http_client,
extracted_query(params_q_scrubbed),
@per_page,
@offset,
@page,
on_campus?(ip),
extracted_scope(params_q_scrubbed))
searcher.search
searcher_partials = {}
searcher_cfg = searcher_config(endpoint)
unless searcher_cfg.blank?
services = searcher_cfg['services'].blank? ? [] : searcher_cfg['services']
else
services = []
end
services << endpoint
respond_to do |format|
format.html {
services.each do |service|
service_template = render_to_string(
:partial => "quick_search/search/#{template}",
:layout => false,
:locals => { module_display_name: t("#{endpoint}_search.display_name"),
searcher: searcher,
search: '',
service_name: service
})
searcher_partials[service] = service_template
end
render :json => searcher_partials
}
format.json {
# prevents openstruct object from results being nested inside tables
# See: http://stackoverflow.com/questions/7835047/collecting-hashes-into-openstruct-creates-table-entry
result_list = []
searcher.results.each do |result|
result_list << result.to_h
end
render :json => { :endpoint => endpoint,
:per_page => @per_page.to_s,
:page => @page.to_s,
:total => searcher.total,
:results => result_list
}
}
end
end
end
|
[
"def",
"xhr_search",
"endpoint",
"=",
"params",
"[",
":endpoint",
"]",
"if",
"params",
"[",
":template",
"]",
"==",
"'with_paging'",
"template",
"=",
"'xhr_response_with_paging'",
"else",
"template",
"=",
"'xhr_response'",
"end",
"@query",
"=",
"params_q_scrubbed",
"@page",
"=",
"page",
"@per_page",
"=",
"per_page",
"(",
"endpoint",
")",
"@offset",
"=",
"offset",
"(",
"@page",
",",
"@per_page",
")",
"http_client",
"=",
"HTTPClient",
".",
"new",
"update_searcher_timeout",
"(",
"http_client",
",",
"endpoint",
",",
"true",
")",
"benchmark",
"\"%s xhr #{endpoint}\"",
"%",
"CGI",
".",
"escape",
"(",
"@query",
".",
"to_str",
")",
"do",
"klass",
"=",
"\"QuickSearch::#{endpoint.camelize}Searcher\"",
".",
"constantize",
"searcher",
"=",
"klass",
".",
"new",
"(",
"http_client",
",",
"extracted_query",
"(",
"params_q_scrubbed",
")",
",",
"@per_page",
",",
"@offset",
",",
"@page",
",",
"on_campus?",
"(",
"ip",
")",
",",
"extracted_scope",
"(",
"params_q_scrubbed",
")",
")",
"searcher",
".",
"search",
"searcher_partials",
"=",
"{",
"}",
"searcher_cfg",
"=",
"searcher_config",
"(",
"endpoint",
")",
"unless",
"searcher_cfg",
".",
"blank?",
"services",
"=",
"searcher_cfg",
"[",
"'services'",
"]",
".",
"blank?",
"?",
"[",
"]",
":",
"searcher_cfg",
"[",
"'services'",
"]",
"else",
"services",
"=",
"[",
"]",
"end",
"services",
"<<",
"endpoint",
"respond_to",
"do",
"|",
"format",
"|",
"format",
".",
"html",
"{",
"services",
".",
"each",
"do",
"|",
"service",
"|",
"service_template",
"=",
"render_to_string",
"(",
":partial",
"=>",
"\"quick_search/search/#{template}\"",
",",
":layout",
"=>",
"false",
",",
":locals",
"=>",
"{",
"module_display_name",
":",
"t",
"(",
"\"#{endpoint}_search.display_name\"",
")",
",",
"searcher",
":",
"searcher",
",",
"search",
":",
"''",
",",
"service_name",
":",
"service",
"}",
")",
"searcher_partials",
"[",
"service",
"]",
"=",
"service_template",
"end",
"render",
":json",
"=>",
"searcher_partials",
"}",
"format",
".",
"json",
"{",
"# prevents openstruct object from results being nested inside tables",
"# See: http://stackoverflow.com/questions/7835047/collecting-hashes-into-openstruct-creates-table-entry",
"result_list",
"=",
"[",
"]",
"searcher",
".",
"results",
".",
"each",
"do",
"|",
"result",
"|",
"result_list",
"<<",
"result",
".",
"to_h",
"end",
"render",
":json",
"=>",
"{",
":endpoint",
"=>",
"endpoint",
",",
":per_page",
"=>",
"@per_page",
".",
"to_s",
",",
":page",
"=>",
"@page",
".",
"to_s",
",",
":total",
"=>",
"searcher",
".",
"total",
",",
":results",
"=>",
"result_list",
"}",
"}",
"end",
"end",
"end"
] |
The following searches for individual sections of the page.
This allows us to do client-side requests in cases where the original server-side
request times out or otherwise fails.
|
[
"The",
"following",
"searches",
"for",
"individual",
"sections",
"of",
"the",
"page",
".",
"This",
"allows",
"us",
"to",
"do",
"client",
"-",
"side",
"requests",
"in",
"cases",
"where",
"the",
"original",
"server",
"-",
"side",
"request",
"times",
"out",
"or",
"otherwise",
"fails",
"."
] |
2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03
|
https://github.com/NCSU-Libraries/quick_search/blob/2e2c3f8682eed63a2bf2c008fa77f04ff9dd6a03/app/controllers/quick_search/search_controller.rb#L46-L119
|
17,981
|
saturnflyer/surrounded
|
lib/surrounded/context.rb
|
Surrounded.Context.private_const_set
|
def private_const_set(name, const)
unless role_const_defined?(name)
const = const_set(name, const)
private_constant name.to_sym
end
const
end
|
ruby
|
def private_const_set(name, const)
unless role_const_defined?(name)
const = const_set(name, const)
private_constant name.to_sym
end
const
end
|
[
"def",
"private_const_set",
"(",
"name",
",",
"const",
")",
"unless",
"role_const_defined?",
"(",
"name",
")",
"const",
"=",
"const_set",
"(",
"name",
",",
"const",
")",
"private_constant",
"name",
".",
"to_sym",
"end",
"const",
"end"
] |
Set a named constant and make it private
|
[
"Set",
"a",
"named",
"constant",
"and",
"make",
"it",
"private"
] |
0052932a1ce70aa01122c0efdc79b4f60578bace
|
https://github.com/saturnflyer/surrounded/blob/0052932a1ce70aa01122c0efdc79b4f60578bace/lib/surrounded/context.rb#L73-L79
|
17,982
|
CocoaPods/fourflusher
|
lib/fourflusher/executable.rb
|
Fourflusher.Executable.executable
|
def executable(name)
define_method(name) do |*command|
Executable.execute_command(name, Array(command).flatten, false)
end
define_method(name.to_s + '!') do |*command|
Executable.execute_command(name, Array(command).flatten, true)
end
end
|
ruby
|
def executable(name)
define_method(name) do |*command|
Executable.execute_command(name, Array(command).flatten, false)
end
define_method(name.to_s + '!') do |*command|
Executable.execute_command(name, Array(command).flatten, true)
end
end
|
[
"def",
"executable",
"(",
"name",
")",
"define_method",
"(",
"name",
")",
"do",
"|",
"*",
"command",
"|",
"Executable",
".",
"execute_command",
"(",
"name",
",",
"Array",
"(",
"command",
")",
".",
"flatten",
",",
"false",
")",
"end",
"define_method",
"(",
"name",
".",
"to_s",
"+",
"'!'",
")",
"do",
"|",
"*",
"command",
"|",
"Executable",
".",
"execute_command",
"(",
"name",
",",
"Array",
"(",
"command",
")",
".",
"flatten",
",",
"true",
")",
"end",
"end"
] |
Creates the methods for the executable with the given name.
@param [Symbol] name
the name of the executable.
@return [void]
|
[
"Creates",
"the",
"methods",
"for",
"the",
"executable",
"with",
"the",
"given",
"name",
"."
] |
8235ee8fae34ccaf5c708987306228988cea2e43
|
https://github.com/CocoaPods/fourflusher/blob/8235ee8fae34ccaf5c708987306228988cea2e43/lib/fourflusher/executable.rb#L52-L60
|
17,983
|
CocoaPods/fourflusher
|
lib/fourflusher/find.rb
|
Fourflusher.SimControl.fetch_sims
|
def fetch_sims
device_list = JSON.parse(list(['-j', 'devices']))['devices']
unless device_list.is_a?(Hash)
msg = "Expected devices to be of type Hash but instated found #{device_list.class}"
fail Fourflusher::Informative, msg
end
device_list.flat_map do |runtime_str, devices|
# This format changed with Xcode 10.2.
if runtime_str.start_with?('com.apple.CoreSimulator.SimRuntime.')
# Sample string: com.apple.CoreSimulator.SimRuntime.iOS-12-2
_unused, os_info = runtime_str.split 'com.apple.CoreSimulator.SimRuntime.'
os_name, os_major_version, os_minor_version = os_info.split '-'
os_version = "#{os_major_version}.#{os_minor_version}"
else
# Sample string: iOS 9.3
os_name, os_version = runtime_str.split ' '
end
devices.map do |device|
if device['availability'] == '(available)' || device['isAvailable'] == 'YES'
Simulator.new(device, os_name, os_version)
end
end
end.compact.sort(&:sim_list_compare)
end
|
ruby
|
def fetch_sims
device_list = JSON.parse(list(['-j', 'devices']))['devices']
unless device_list.is_a?(Hash)
msg = "Expected devices to be of type Hash but instated found #{device_list.class}"
fail Fourflusher::Informative, msg
end
device_list.flat_map do |runtime_str, devices|
# This format changed with Xcode 10.2.
if runtime_str.start_with?('com.apple.CoreSimulator.SimRuntime.')
# Sample string: com.apple.CoreSimulator.SimRuntime.iOS-12-2
_unused, os_info = runtime_str.split 'com.apple.CoreSimulator.SimRuntime.'
os_name, os_major_version, os_minor_version = os_info.split '-'
os_version = "#{os_major_version}.#{os_minor_version}"
else
# Sample string: iOS 9.3
os_name, os_version = runtime_str.split ' '
end
devices.map do |device|
if device['availability'] == '(available)' || device['isAvailable'] == 'YES'
Simulator.new(device, os_name, os_version)
end
end
end.compact.sort(&:sim_list_compare)
end
|
[
"def",
"fetch_sims",
"device_list",
"=",
"JSON",
".",
"parse",
"(",
"list",
"(",
"[",
"'-j'",
",",
"'devices'",
"]",
")",
")",
"[",
"'devices'",
"]",
"unless",
"device_list",
".",
"is_a?",
"(",
"Hash",
")",
"msg",
"=",
"\"Expected devices to be of type Hash but instated found #{device_list.class}\"",
"fail",
"Fourflusher",
"::",
"Informative",
",",
"msg",
"end",
"device_list",
".",
"flat_map",
"do",
"|",
"runtime_str",
",",
"devices",
"|",
"# This format changed with Xcode 10.2.",
"if",
"runtime_str",
".",
"start_with?",
"(",
"'com.apple.CoreSimulator.SimRuntime.'",
")",
"# Sample string: com.apple.CoreSimulator.SimRuntime.iOS-12-2",
"_unused",
",",
"os_info",
"=",
"runtime_str",
".",
"split",
"'com.apple.CoreSimulator.SimRuntime.'",
"os_name",
",",
"os_major_version",
",",
"os_minor_version",
"=",
"os_info",
".",
"split",
"'-'",
"os_version",
"=",
"\"#{os_major_version}.#{os_minor_version}\"",
"else",
"# Sample string: iOS 9.3",
"os_name",
",",
"os_version",
"=",
"runtime_str",
".",
"split",
"' '",
"end",
"devices",
".",
"map",
"do",
"|",
"device",
"|",
"if",
"device",
"[",
"'availability'",
"]",
"==",
"'(available)'",
"||",
"device",
"[",
"'isAvailable'",
"]",
"==",
"'YES'",
"Simulator",
".",
"new",
"(",
"device",
",",
"os_name",
",",
"os_version",
")",
"end",
"end",
"end",
".",
"compact",
".",
"sort",
"(",
":sim_list_compare",
")",
"end"
] |
Gets the simulators and transforms the simctl json into Simulator objects
|
[
"Gets",
"the",
"simulators",
"and",
"transforms",
"the",
"simctl",
"json",
"into",
"Simulator",
"objects"
] |
8235ee8fae34ccaf5c708987306228988cea2e43
|
https://github.com/CocoaPods/fourflusher/blob/8235ee8fae34ccaf5c708987306228988cea2e43/lib/fourflusher/find.rb#L124-L148
|
17,984
|
brandur/json_schema
|
lib/json_schema/validator.rb
|
JsonSchema.Validator.get_extra_keys
|
def get_extra_keys(schema, data)
extra = data.keys - schema.properties.keys
if schema.pattern_properties
schema.pattern_properties.keys.each do |pattern|
extra -= extra.select { |k| k =~ pattern }
end
end
extra
end
|
ruby
|
def get_extra_keys(schema, data)
extra = data.keys - schema.properties.keys
if schema.pattern_properties
schema.pattern_properties.keys.each do |pattern|
extra -= extra.select { |k| k =~ pattern }
end
end
extra
end
|
[
"def",
"get_extra_keys",
"(",
"schema",
",",
"data",
")",
"extra",
"=",
"data",
".",
"keys",
"-",
"schema",
".",
"properties",
".",
"keys",
"if",
"schema",
".",
"pattern_properties",
"schema",
".",
"pattern_properties",
".",
"keys",
".",
"each",
"do",
"|",
"pattern",
"|",
"extra",
"-=",
"extra",
".",
"select",
"{",
"|",
"k",
"|",
"k",
"=~",
"pattern",
"}",
"end",
"end",
"extra",
"end"
] |
for use with additionalProperties and strictProperties
|
[
"for",
"use",
"with",
"additionalProperties",
"and",
"strictProperties"
] |
9c4656774a7c7d22a6f466932b34fd47d67c88dc
|
https://github.com/brandur/json_schema/blob/9c4656774a7c7d22a6f466932b34fd47d67c88dc/lib/json_schema/validator.rb#L60-L70
|
17,985
|
brandur/json_schema
|
lib/json_pointer/evaluator.rb
|
JsonPointer.Evaluator.split
|
def split(path)
parts = []
last_index = 0
while index = path.index("/", last_index)
if index == last_index
parts << ""
else
parts << path[last_index...index]
end
last_index = index + 1
end
# and also get that last segment
parts << path[last_index..-1]
# it should begin with a blank segment from the leading "/"; kill that
parts.shift
parts
end
|
ruby
|
def split(path)
parts = []
last_index = 0
while index = path.index("/", last_index)
if index == last_index
parts << ""
else
parts << path[last_index...index]
end
last_index = index + 1
end
# and also get that last segment
parts << path[last_index..-1]
# it should begin with a blank segment from the leading "/"; kill that
parts.shift
parts
end
|
[
"def",
"split",
"(",
"path",
")",
"parts",
"=",
"[",
"]",
"last_index",
"=",
"0",
"while",
"index",
"=",
"path",
".",
"index",
"(",
"\"/\"",
",",
"last_index",
")",
"if",
"index",
"==",
"last_index",
"parts",
"<<",
"\"\"",
"else",
"parts",
"<<",
"path",
"[",
"last_index",
"...",
"index",
"]",
"end",
"last_index",
"=",
"index",
"+",
"1",
"end",
"# and also get that last segment",
"parts",
"<<",
"path",
"[",
"last_index",
"..",
"-",
"1",
"]",
"# it should begin with a blank segment from the leading \"/\"; kill that",
"parts",
".",
"shift",
"parts",
"end"
] |
custom split method to account for blank segments
|
[
"custom",
"split",
"method",
"to",
"account",
"for",
"blank",
"segments"
] |
9c4656774a7c7d22a6f466932b34fd47d67c88dc
|
https://github.com/brandur/json_schema/blob/9c4656774a7c7d22a6f466932b34fd47d67c88dc/lib/json_pointer/evaluator.rb#L53-L69
|
17,986
|
rajatthareja/ReportBuilder
|
lib/report_builder/builder.rb
|
ReportBuilder.Builder.build_report
|
def build_report
options = ReportBuilder.options
groups = get_groups options[:input_path]
json_report_path = options[:json_report_path] || options[:report_path]
if options[:report_types].include? 'JSON'
File.open(json_report_path + '.json', 'w') do |file|
file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
end
end
if options[:additional_css] and Pathname.new(options[:additional_css]).file?
options[:additional_css] = File.read(options[:additional_css])
end
if options[:additional_js] and Pathname.new(options[:additional_js]).file?
options[:additional_js] = File.read(options[:additional_js])
end
html_report_path = options[:html_report_path] || options[:report_path]
if options[:report_types].include? 'HTML'
File.open(html_report_path + '.html', 'w') do |file|
file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub(' ', '').gsub("\n\n", '')
end
end
retry_report_path = options[:retry_report_path] || options[:report_path]
if options[:report_types].include? 'RETRY'
File.open(retry_report_path + '.retry', 'w') do |file|
groups.each do |group|
group['features'].each do |feature|
if feature['status'] == 'broken'
feature['elements'].each do |scenario|
file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'
end
end
end
end
end
end
[json_report_path, html_report_path, retry_report_path]
end
|
ruby
|
def build_report
options = ReportBuilder.options
groups = get_groups options[:input_path]
json_report_path = options[:json_report_path] || options[:report_path]
if options[:report_types].include? 'JSON'
File.open(json_report_path + '.json', 'w') do |file|
file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
end
end
if options[:additional_css] and Pathname.new(options[:additional_css]).file?
options[:additional_css] = File.read(options[:additional_css])
end
if options[:additional_js] and Pathname.new(options[:additional_js]).file?
options[:additional_js] = File.read(options[:additional_js])
end
html_report_path = options[:html_report_path] || options[:report_path]
if options[:report_types].include? 'HTML'
File.open(html_report_path + '.html', 'w') do |file|
file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub(' ', '').gsub("\n\n", '')
end
end
retry_report_path = options[:retry_report_path] || options[:report_path]
if options[:report_types].include? 'RETRY'
File.open(retry_report_path + '.retry', 'w') do |file|
groups.each do |group|
group['features'].each do |feature|
if feature['status'] == 'broken'
feature['elements'].each do |scenario|
file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'
end
end
end
end
end
end
[json_report_path, html_report_path, retry_report_path]
end
|
[
"def",
"build_report",
"options",
"=",
"ReportBuilder",
".",
"options",
"groups",
"=",
"get_groups",
"options",
"[",
":input_path",
"]",
"json_report_path",
"=",
"options",
"[",
":json_report_path",
"]",
"||",
"options",
"[",
":report_path",
"]",
"if",
"options",
"[",
":report_types",
"]",
".",
"include?",
"'JSON'",
"File",
".",
"open",
"(",
"json_report_path",
"+",
"'.json'",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"file",
".",
"write",
"JSON",
".",
"pretty_generate",
"(",
"groups",
".",
"size",
">",
"1",
"?",
"groups",
":",
"groups",
".",
"first",
"[",
"'features'",
"]",
")",
"end",
"end",
"if",
"options",
"[",
":additional_css",
"]",
"and",
"Pathname",
".",
"new",
"(",
"options",
"[",
":additional_css",
"]",
")",
".",
"file?",
"options",
"[",
":additional_css",
"]",
"=",
"File",
".",
"read",
"(",
"options",
"[",
":additional_css",
"]",
")",
"end",
"if",
"options",
"[",
":additional_js",
"]",
"and",
"Pathname",
".",
"new",
"(",
"options",
"[",
":additional_js",
"]",
")",
".",
"file?",
"options",
"[",
":additional_js",
"]",
"=",
"File",
".",
"read",
"(",
"options",
"[",
":additional_js",
"]",
")",
"end",
"html_report_path",
"=",
"options",
"[",
":html_report_path",
"]",
"||",
"options",
"[",
":report_path",
"]",
"if",
"options",
"[",
":report_types",
"]",
".",
"include?",
"'HTML'",
"File",
".",
"open",
"(",
"html_report_path",
"+",
"'.html'",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"file",
".",
"write",
"get",
"(",
"groups",
".",
"size",
">",
"1",
"?",
"'group_report'",
":",
"'report'",
")",
".",
"result",
"(",
"binding",
")",
".",
"gsub",
"(",
"' '",
",",
"''",
")",
".",
"gsub",
"(",
"\"\\n\\n\"",
",",
"''",
")",
"end",
"end",
"retry_report_path",
"=",
"options",
"[",
":retry_report_path",
"]",
"||",
"options",
"[",
":report_path",
"]",
"if",
"options",
"[",
":report_types",
"]",
".",
"include?",
"'RETRY'",
"File",
".",
"open",
"(",
"retry_report_path",
"+",
"'.retry'",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"groups",
".",
"each",
"do",
"|",
"group",
"|",
"group",
"[",
"'features'",
"]",
".",
"each",
"do",
"|",
"feature",
"|",
"if",
"feature",
"[",
"'status'",
"]",
"==",
"'broken'",
"feature",
"[",
"'elements'",
"]",
".",
"each",
"do",
"|",
"scenario",
"|",
"file",
".",
"puts",
"\"#{feature['uri']}:#{scenario['line']}\"",
"if",
"scenario",
"[",
"'status'",
"]",
"==",
"'failed'",
"end",
"end",
"end",
"end",
"end",
"end",
"[",
"json_report_path",
",",
"html_report_path",
",",
"retry_report_path",
"]",
"end"
] |
ReportBuilder Main method
|
[
"ReportBuilder",
"Main",
"method"
] |
58b849fb368a7d6407ab9519cbee70bb9decd908
|
https://github.com/rajatthareja/ReportBuilder/blob/58b849fb368a7d6407ab9519cbee70bb9decd908/lib/report_builder/builder.rb#L19-L61
|
17,987
|
davetron5000/methadone
|
lib/methadone/exit_now.rb
|
Methadone.ExitNow.exit_now!
|
def exit_now!(exit_code,message=nil)
if exit_code.kind_of?(String) && message.nil?
raise Methadone::Error.new(1,exit_code)
else
raise Methadone::Error.new(exit_code,message)
end
end
|
ruby
|
def exit_now!(exit_code,message=nil)
if exit_code.kind_of?(String) && message.nil?
raise Methadone::Error.new(1,exit_code)
else
raise Methadone::Error.new(exit_code,message)
end
end
|
[
"def",
"exit_now!",
"(",
"exit_code",
",",
"message",
"=",
"nil",
")",
"if",
"exit_code",
".",
"kind_of?",
"(",
"String",
")",
"&&",
"message",
".",
"nil?",
"raise",
"Methadone",
"::",
"Error",
".",
"new",
"(",
"1",
",",
"exit_code",
")",
"else",
"raise",
"Methadone",
"::",
"Error",
".",
"new",
"(",
"exit_code",
",",
"message",
")",
"end",
"end"
] |
Call this to exit the program immediately
with the given error code and message.
+exit_code+:: exit status you'd like to exit with
+message+:: message to display to the user explaining the problem
If +exit_code+ is a String and +message+ is omitted, +exit_code+ will be used as the message
and the actual exit code will be 1.
=== Examples
exit_now!(4,"Oh noes!")
# => exit app with status 4 and show the user "Oh noes!" on stderr
exit_now!("Oh noes!")
# => exit app with status 1 and show the user "Oh noes!" on stderr
exit_now!(4)
# => exit app with status 4 and dont' give the user a message (how rude of you)
|
[
"Call",
"this",
"to",
"exit",
"the",
"program",
"immediately",
"with",
"the",
"given",
"error",
"code",
"and",
"message",
"."
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/exit_now.rb#L25-L31
|
17,988
|
davetron5000/methadone
|
lib/methadone/cli.rb
|
Methadone.CLI.check_and_prepare_basedir!
|
def check_and_prepare_basedir!(basedir,force)
if File.exists? basedir
if force
rm_rf basedir, :verbose => true, :secure => true
else
exit_now! 1,"error: #{basedir} exists, use --force to override"
end
end
mkdir_p basedir
end
|
ruby
|
def check_and_prepare_basedir!(basedir,force)
if File.exists? basedir
if force
rm_rf basedir, :verbose => true, :secure => true
else
exit_now! 1,"error: #{basedir} exists, use --force to override"
end
end
mkdir_p basedir
end
|
[
"def",
"check_and_prepare_basedir!",
"(",
"basedir",
",",
"force",
")",
"if",
"File",
".",
"exists?",
"basedir",
"if",
"force",
"rm_rf",
"basedir",
",",
":verbose",
"=>",
"true",
",",
":secure",
"=>",
"true",
"else",
"exit_now!",
"1",
",",
"\"error: #{basedir} exists, use --force to override\"",
"end",
"end",
"mkdir_p",
"basedir",
"end"
] |
Checks that the basedir can be used, either by
not existing, or by existing and force is true.
In that case, we clean it out entirely
+basedir+:: base directory where the user wants to create a new project
+force+:: if true, and +basedir+ exists, delete it before proceeding
This will exit the app if the dir exists and force is false
|
[
"Checks",
"that",
"the",
"basedir",
"can",
"be",
"used",
"either",
"by",
"not",
"existing",
"or",
"by",
"existing",
"and",
"force",
"is",
"true",
".",
"In",
"that",
"case",
"we",
"clean",
"it",
"out",
"entirely"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/cli.rb#L19-L28
|
17,989
|
davetron5000/methadone
|
lib/methadone/cli.rb
|
Methadone.CLI.add_to_file
|
def add_to_file(file,lines,options = {})
new_lines = []
found_line = false
File.open(file).readlines.each do |line|
line.chomp!
if options[:before] && options[:before] === line
found_line = true
new_lines += lines
end
new_lines << line
end
raise "No line matched #{options[:before]}" if options[:before] && !found_line
new_lines += lines unless options[:before]
File.open(file,'w') do |fp|
new_lines.each { |line| fp.puts line }
end
end
|
ruby
|
def add_to_file(file,lines,options = {})
new_lines = []
found_line = false
File.open(file).readlines.each do |line|
line.chomp!
if options[:before] && options[:before] === line
found_line = true
new_lines += lines
end
new_lines << line
end
raise "No line matched #{options[:before]}" if options[:before] && !found_line
new_lines += lines unless options[:before]
File.open(file,'w') do |fp|
new_lines.each { |line| fp.puts line }
end
end
|
[
"def",
"add_to_file",
"(",
"file",
",",
"lines",
",",
"options",
"=",
"{",
"}",
")",
"new_lines",
"=",
"[",
"]",
"found_line",
"=",
"false",
"File",
".",
"open",
"(",
"file",
")",
".",
"readlines",
".",
"each",
"do",
"|",
"line",
"|",
"line",
".",
"chomp!",
"if",
"options",
"[",
":before",
"]",
"&&",
"options",
"[",
":before",
"]",
"===",
"line",
"found_line",
"=",
"true",
"new_lines",
"+=",
"lines",
"end",
"new_lines",
"<<",
"line",
"end",
"raise",
"\"No line matched #{options[:before]}\"",
"if",
"options",
"[",
":before",
"]",
"&&",
"!",
"found_line",
"new_lines",
"+=",
"lines",
"unless",
"options",
"[",
":before",
"]",
"File",
".",
"open",
"(",
"file",
",",
"'w'",
")",
"do",
"|",
"fp",
"|",
"new_lines",
".",
"each",
"{",
"|",
"line",
"|",
"fp",
".",
"puts",
"line",
"}",
"end",
"end"
] |
Add content to a file
+file+:: path to the file
+lines+:: Array of String representing the lines to add
+options+:: Hash of options:
<tt>:before</tt>:: A regexp that will appear right after the new content. i.e.
this is where to insert said content.
|
[
"Add",
"content",
"to",
"a",
"file"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/cli.rb#L37-L55
|
17,990
|
davetron5000/methadone
|
lib/methadone/cli.rb
|
Methadone.CLI.copy_file
|
def copy_file(relative_path,options = {})
options[:from] ||= :full
relative_path = File.join(relative_path.split(/\//))
template_path = File.join(template_dir(options[:from]),relative_path + ".erb")
template = ERB.new(File.open(template_path).readlines.join(''))
relative_path_parts = File.split(relative_path)
relative_path_parts[-1] = options[:as] if options[:as]
erb_binding = options[:binding] or binding
File.open(File.join(relative_path_parts),'w') do |file|
file.puts template.result(erb_binding)
file.chmod(0755) if options[:executable]
end
end
|
ruby
|
def copy_file(relative_path,options = {})
options[:from] ||= :full
relative_path = File.join(relative_path.split(/\//))
template_path = File.join(template_dir(options[:from]),relative_path + ".erb")
template = ERB.new(File.open(template_path).readlines.join(''))
relative_path_parts = File.split(relative_path)
relative_path_parts[-1] = options[:as] if options[:as]
erb_binding = options[:binding] or binding
File.open(File.join(relative_path_parts),'w') do |file|
file.puts template.result(erb_binding)
file.chmod(0755) if options[:executable]
end
end
|
[
"def",
"copy_file",
"(",
"relative_path",
",",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":from",
"]",
"||=",
":full",
"relative_path",
"=",
"File",
".",
"join",
"(",
"relative_path",
".",
"split",
"(",
"/",
"\\/",
"/",
")",
")",
"template_path",
"=",
"File",
".",
"join",
"(",
"template_dir",
"(",
"options",
"[",
":from",
"]",
")",
",",
"relative_path",
"+",
"\".erb\"",
")",
"template",
"=",
"ERB",
".",
"new",
"(",
"File",
".",
"open",
"(",
"template_path",
")",
".",
"readlines",
".",
"join",
"(",
"''",
")",
")",
"relative_path_parts",
"=",
"File",
".",
"split",
"(",
"relative_path",
")",
"relative_path_parts",
"[",
"-",
"1",
"]",
"=",
"options",
"[",
":as",
"]",
"if",
"options",
"[",
":as",
"]",
"erb_binding",
"=",
"options",
"[",
":binding",
"]",
"or",
"binding",
"File",
".",
"open",
"(",
"File",
".",
"join",
"(",
"relative_path_parts",
")",
",",
"'w'",
")",
"do",
"|",
"file",
"|",
"file",
".",
"puts",
"template",
".",
"result",
"(",
"erb_binding",
")",
"file",
".",
"chmod",
"(",
"0755",
")",
"if",
"options",
"[",
":executable",
"]",
"end",
"end"
] |
Copies a file, running it through ERB
+relative_path+:: path to the file, relative to the project root, minus the .erb extension
You should use forward slashes to separate paths; this method
will handle making the ultimate path OS independent.
+options+:: Options to affect how the copy is done:
<tt>:from</tt>:: The name of the profile from which to find the file, "full" by default
<tt>:as</tt>:: The name the file should get if not the one in relative_path
<tt>:executable</tt>:: true if this file should be set executable
<tt>:binding</tt>:: the binding to use for the template
|
[
"Copies",
"a",
"file",
"running",
"it",
"through",
"ERB"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/cli.rb#L67-L84
|
17,991
|
davetron5000/methadone
|
lib/methadone/argv_parser.rb
|
Methadone.ARGVParser.parse_string_for_argv
|
def parse_string_for_argv(string) #:nodoc:
return [] if string.nil?
args = [] # return value we are building up
current = 0 # pointer to where we are in +string+
next_arg = '' # the next arg we are building up to ultimatley put into args
inside_quote = nil # quote character we are "inside" of
last_char = nil # the last character we saw
while current < string.length
char = string.chars.to_a[current]
case char
when /["']/
if inside_quote.nil? # eat the quote, but remember we are now "inside" one
inside_quote = char
elsif inside_quote == char # we closed the quote we were "inside"
inside_quote = nil
else # we got a different quote, so it goes in literally
next_arg << char
end
when /\s/
if last_char == "\\" # we have an escaped space, replace the escape char
next_arg[-1] = char
elsif inside_quote # we are inside a quote so keep the space
next_arg << char
else # new argument
args << next_arg
next_arg = ''
end
else
next_arg << char
end
current += 1
last_char = char
end
args << next_arg unless next_arg == ''
args
end
|
ruby
|
def parse_string_for_argv(string) #:nodoc:
return [] if string.nil?
args = [] # return value we are building up
current = 0 # pointer to where we are in +string+
next_arg = '' # the next arg we are building up to ultimatley put into args
inside_quote = nil # quote character we are "inside" of
last_char = nil # the last character we saw
while current < string.length
char = string.chars.to_a[current]
case char
when /["']/
if inside_quote.nil? # eat the quote, but remember we are now "inside" one
inside_quote = char
elsif inside_quote == char # we closed the quote we were "inside"
inside_quote = nil
else # we got a different quote, so it goes in literally
next_arg << char
end
when /\s/
if last_char == "\\" # we have an escaped space, replace the escape char
next_arg[-1] = char
elsif inside_quote # we are inside a quote so keep the space
next_arg << char
else # new argument
args << next_arg
next_arg = ''
end
else
next_arg << char
end
current += 1
last_char = char
end
args << next_arg unless next_arg == ''
args
end
|
[
"def",
"parse_string_for_argv",
"(",
"string",
")",
"#:nodoc:",
"return",
"[",
"]",
"if",
"string",
".",
"nil?",
"args",
"=",
"[",
"]",
"# return value we are building up",
"current",
"=",
"0",
"# pointer to where we are in +string+",
"next_arg",
"=",
"''",
"# the next arg we are building up to ultimatley put into args",
"inside_quote",
"=",
"nil",
"# quote character we are \"inside\" of",
"last_char",
"=",
"nil",
"# the last character we saw",
"while",
"current",
"<",
"string",
".",
"length",
"char",
"=",
"string",
".",
"chars",
".",
"to_a",
"[",
"current",
"]",
"case",
"char",
"when",
"/",
"/",
"if",
"inside_quote",
".",
"nil?",
"# eat the quote, but remember we are now \"inside\" one",
"inside_quote",
"=",
"char",
"elsif",
"inside_quote",
"==",
"char",
"# we closed the quote we were \"inside\"",
"inside_quote",
"=",
"nil",
"else",
"# we got a different quote, so it goes in literally",
"next_arg",
"<<",
"char",
"end",
"when",
"/",
"\\s",
"/",
"if",
"last_char",
"==",
"\"\\\\\"",
"# we have an escaped space, replace the escape char",
"next_arg",
"[",
"-",
"1",
"]",
"=",
"char",
"elsif",
"inside_quote",
"# we are inside a quote so keep the space",
"next_arg",
"<<",
"char",
"else",
"# new argument",
"args",
"<<",
"next_arg",
"next_arg",
"=",
"''",
"end",
"else",
"next_arg",
"<<",
"char",
"end",
"current",
"+=",
"1",
"last_char",
"=",
"char",
"end",
"args",
"<<",
"next_arg",
"unless",
"next_arg",
"==",
"''",
"args",
"end"
] |
Parses +string+, returning an array that can be placed into ARGV or given to OptionParser
|
[
"Parses",
"+",
"string",
"+",
"returning",
"an",
"array",
"that",
"can",
"be",
"placed",
"into",
"ARGV",
"or",
"given",
"to",
"OptionParser"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/argv_parser.rb#L11-L48
|
17,992
|
davetron5000/methadone
|
lib/methadone/main.rb
|
Methadone.Main.go!
|
def go!
setup_defaults
opts.post_setup
opts.parse!
opts.check_args!
result = call_main
if result.kind_of? Integer
exit result
else
exit 0
end
rescue OptionParser::ParseError => ex
logger.error ex.message
puts
puts opts.help
exit 64 # Linux standard for bad command line
end
|
ruby
|
def go!
setup_defaults
opts.post_setup
opts.parse!
opts.check_args!
result = call_main
if result.kind_of? Integer
exit result
else
exit 0
end
rescue OptionParser::ParseError => ex
logger.error ex.message
puts
puts opts.help
exit 64 # Linux standard for bad command line
end
|
[
"def",
"go!",
"setup_defaults",
"opts",
".",
"post_setup",
"opts",
".",
"parse!",
"opts",
".",
"check_args!",
"result",
"=",
"call_main",
"if",
"result",
".",
"kind_of?",
"Integer",
"exit",
"result",
"else",
"exit",
"0",
"end",
"rescue",
"OptionParser",
"::",
"ParseError",
"=>",
"ex",
"logger",
".",
"error",
"ex",
".",
"message",
"puts",
"puts",
"opts",
".",
"help",
"exit",
"64",
"# Linux standard for bad command line",
"end"
] |
Start your command-line app, exiting appropriately when
complete.
This *will* exit your program when it completes. If your
#main block evaluates to an integer, that value will be sent
to Kernel#exit, otherwise, this will exit with 0
If the command-line options couldn't be parsed, this
will exit with 64 and whatever message OptionParser provided.
If a required argument (see #arg) is not found, this exits with
64 and a message about that missing argument.
|
[
"Start",
"your",
"command",
"-",
"line",
"app",
"exiting",
"appropriately",
"when",
"complete",
"."
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/main.rb#L162-L178
|
17,993
|
davetron5000/methadone
|
lib/methadone/main.rb
|
Methadone.Main.normalize_defaults
|
def normalize_defaults
new_options = {}
options.each do |key,value|
unless value.nil?
new_options[key.to_s] = value
new_options[key.to_sym] = value
end
end
options.merge!(new_options)
end
|
ruby
|
def normalize_defaults
new_options = {}
options.each do |key,value|
unless value.nil?
new_options[key.to_s] = value
new_options[key.to_sym] = value
end
end
options.merge!(new_options)
end
|
[
"def",
"normalize_defaults",
"new_options",
"=",
"{",
"}",
"options",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"unless",
"value",
".",
"nil?",
"new_options",
"[",
"key",
".",
"to_s",
"]",
"=",
"value",
"new_options",
"[",
"key",
".",
"to_sym",
"]",
"=",
"value",
"end",
"end",
"options",
".",
"merge!",
"(",
"new_options",
")",
"end"
] |
Normalized all defaults to both string and symbol forms, so
the user can access them via either means just as they would for
non-defaulted options
|
[
"Normalized",
"all",
"defaults",
"to",
"both",
"string",
"and",
"symbol",
"forms",
"so",
"the",
"user",
"can",
"access",
"them",
"via",
"either",
"means",
"just",
"as",
"they",
"would",
"for",
"non",
"-",
"defaulted",
"options"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/main.rb#L384-L393
|
17,994
|
davetron5000/methadone
|
lib/methadone/main.rb
|
Methadone.Main.call_main
|
def call_main
@leak_exceptions = nil unless defined? @leak_exceptions
@main_block.call(*ARGV)
rescue Methadone::Error => ex
raise ex if ENV['DEBUG']
logger.error ex.message unless no_message? ex
ex.exit_code
rescue OptionParser::ParseError
raise
rescue => ex
raise ex if ENV['DEBUG']
raise ex if @leak_exceptions
logger.error ex.message unless no_message? ex
70 # Linux sysexit code for internal software error
end
|
ruby
|
def call_main
@leak_exceptions = nil unless defined? @leak_exceptions
@main_block.call(*ARGV)
rescue Methadone::Error => ex
raise ex if ENV['DEBUG']
logger.error ex.message unless no_message? ex
ex.exit_code
rescue OptionParser::ParseError
raise
rescue => ex
raise ex if ENV['DEBUG']
raise ex if @leak_exceptions
logger.error ex.message unless no_message? ex
70 # Linux sysexit code for internal software error
end
|
[
"def",
"call_main",
"@leak_exceptions",
"=",
"nil",
"unless",
"defined?",
"@leak_exceptions",
"@main_block",
".",
"call",
"(",
"ARGV",
")",
"rescue",
"Methadone",
"::",
"Error",
"=>",
"ex",
"raise",
"ex",
"if",
"ENV",
"[",
"'DEBUG'",
"]",
"logger",
".",
"error",
"ex",
".",
"message",
"unless",
"no_message?",
"ex",
"ex",
".",
"exit_code",
"rescue",
"OptionParser",
"::",
"ParseError",
"raise",
"rescue",
"=>",
"ex",
"raise",
"ex",
"if",
"ENV",
"[",
"'DEBUG'",
"]",
"raise",
"ex",
"if",
"@leak_exceptions",
"logger",
".",
"error",
"ex",
".",
"message",
"unless",
"no_message?",
"ex",
"70",
"# Linux sysexit code for internal software error",
"end"
] |
Handle calling main and trapping any exceptions thrown
|
[
"Handle",
"calling",
"main",
"and",
"trapping",
"any",
"exceptions",
"thrown"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/main.rb#L396-L410
|
17,995
|
davetron5000/methadone
|
lib/methadone/main.rb
|
Methadone.OptionParserProxy.check_args!
|
def check_args!
::Hash[@args.zip(::ARGV)].each do |arg_name,arg_value|
if @arg_options[arg_name].include? :required
if arg_value.nil?
message = "'#{arg_name.to_s}' is required"
message = "at least one " + message if @arg_options[arg_name].include? :many
raise ::OptionParser::ParseError,message
end
end
end
end
|
ruby
|
def check_args!
::Hash[@args.zip(::ARGV)].each do |arg_name,arg_value|
if @arg_options[arg_name].include? :required
if arg_value.nil?
message = "'#{arg_name.to_s}' is required"
message = "at least one " + message if @arg_options[arg_name].include? :many
raise ::OptionParser::ParseError,message
end
end
end
end
|
[
"def",
"check_args!",
"::",
"Hash",
"[",
"@args",
".",
"zip",
"(",
"::",
"ARGV",
")",
"]",
".",
"each",
"do",
"|",
"arg_name",
",",
"arg_value",
"|",
"if",
"@arg_options",
"[",
"arg_name",
"]",
".",
"include?",
":required",
"if",
"arg_value",
".",
"nil?",
"message",
"=",
"\"'#{arg_name.to_s}' is required\"",
"message",
"=",
"\"at least one \"",
"+",
"message",
"if",
"@arg_options",
"[",
"arg_name",
"]",
".",
"include?",
":many",
"raise",
"::",
"OptionParser",
"::",
"ParseError",
",",
"message",
"end",
"end",
"end",
"end"
] |
Create the proxy
+option_parser+:: An OptionParser instance
+options+:: a hash that will store the options
set via automatic setting. The caller should
retain a reference to this
|
[
"Create",
"the",
"proxy"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/main.rb#L442-L452
|
17,996
|
davetron5000/methadone
|
lib/methadone/main.rb
|
Methadone.OptionParserProxy.arg
|
def arg(arg_name,*options)
options << :optional if options.include?(:any) && !options.include?(:optional)
options << :required unless options.include? :optional
options << :one unless options.include?(:any) || options.include?(:many)
@args << arg_name
@arg_options[arg_name] = options
options.select(&STRINGS_ONLY).each do |doc|
@arg_documentation[arg_name] = doc + (options.include?(:optional) ? " (optional)" : "")
end
set_banner
end
|
ruby
|
def arg(arg_name,*options)
options << :optional if options.include?(:any) && !options.include?(:optional)
options << :required unless options.include? :optional
options << :one unless options.include?(:any) || options.include?(:many)
@args << arg_name
@arg_options[arg_name] = options
options.select(&STRINGS_ONLY).each do |doc|
@arg_documentation[arg_name] = doc + (options.include?(:optional) ? " (optional)" : "")
end
set_banner
end
|
[
"def",
"arg",
"(",
"arg_name",
",",
"*",
"options",
")",
"options",
"<<",
":optional",
"if",
"options",
".",
"include?",
"(",
":any",
")",
"&&",
"!",
"options",
".",
"include?",
"(",
":optional",
")",
"options",
"<<",
":required",
"unless",
"options",
".",
"include?",
":optional",
"options",
"<<",
":one",
"unless",
"options",
".",
"include?",
"(",
":any",
")",
"||",
"options",
".",
"include?",
"(",
":many",
")",
"@args",
"<<",
"arg_name",
"@arg_options",
"[",
"arg_name",
"]",
"=",
"options",
"options",
".",
"select",
"(",
"STRINGS_ONLY",
")",
".",
"each",
"do",
"|",
"doc",
"|",
"@arg_documentation",
"[",
"arg_name",
"]",
"=",
"doc",
"+",
"(",
"options",
".",
"include?",
"(",
":optional",
")",
"?",
"\" (optional)\"",
":",
"\"\"",
")",
"end",
"set_banner",
"end"
] |
Sets the banner to include these arg names
|
[
"Sets",
"the",
"banner",
"to",
"include",
"these",
"arg",
"names"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/main.rb#L483-L493
|
17,997
|
davetron5000/methadone
|
lib/methadone/sh.rb
|
Methadone.SH.sh
|
def sh(command,options={},&block)
sh_logger.debug("Executing '#{command}'")
stdout,stderr,status = execution_strategy.run_command(command)
process_status = Methadone::ProcessStatus.new(status,options[:expected])
sh_logger.warn("stderr output of '#{command}': #{stderr}") unless stderr.strip.length == 0
if process_status.success?
sh_logger.debug("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
call_block(block,stdout,stderr,process_status.exitstatus) unless block.nil?
else
sh_logger.info("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
sh_logger.warn("Error running '#{command}'")
end
process_status.exitstatus
rescue *exception_meaning_command_not_found => ex
sh_logger.error("Error running '#{command}': #{ex.message}")
127
end
|
ruby
|
def sh(command,options={},&block)
sh_logger.debug("Executing '#{command}'")
stdout,stderr,status = execution_strategy.run_command(command)
process_status = Methadone::ProcessStatus.new(status,options[:expected])
sh_logger.warn("stderr output of '#{command}': #{stderr}") unless stderr.strip.length == 0
if process_status.success?
sh_logger.debug("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
call_block(block,stdout,stderr,process_status.exitstatus) unless block.nil?
else
sh_logger.info("stdout output of '#{command}': #{stdout}") unless stdout.strip.length == 0
sh_logger.warn("Error running '#{command}'")
end
process_status.exitstatus
rescue *exception_meaning_command_not_found => ex
sh_logger.error("Error running '#{command}': #{ex.message}")
127
end
|
[
"def",
"sh",
"(",
"command",
",",
"options",
"=",
"{",
"}",
",",
"&",
"block",
")",
"sh_logger",
".",
"debug",
"(",
"\"Executing '#{command}'\"",
")",
"stdout",
",",
"stderr",
",",
"status",
"=",
"execution_strategy",
".",
"run_command",
"(",
"command",
")",
"process_status",
"=",
"Methadone",
"::",
"ProcessStatus",
".",
"new",
"(",
"status",
",",
"options",
"[",
":expected",
"]",
")",
"sh_logger",
".",
"warn",
"(",
"\"stderr output of '#{command}': #{stderr}\"",
")",
"unless",
"stderr",
".",
"strip",
".",
"length",
"==",
"0",
"if",
"process_status",
".",
"success?",
"sh_logger",
".",
"debug",
"(",
"\"stdout output of '#{command}': #{stdout}\"",
")",
"unless",
"stdout",
".",
"strip",
".",
"length",
"==",
"0",
"call_block",
"(",
"block",
",",
"stdout",
",",
"stderr",
",",
"process_status",
".",
"exitstatus",
")",
"unless",
"block",
".",
"nil?",
"else",
"sh_logger",
".",
"info",
"(",
"\"stdout output of '#{command}': #{stdout}\"",
")",
"unless",
"stdout",
".",
"strip",
".",
"length",
"==",
"0",
"sh_logger",
".",
"warn",
"(",
"\"Error running '#{command}'\"",
")",
"end",
"process_status",
".",
"exitstatus",
"rescue",
"exception_meaning_command_not_found",
"=>",
"ex",
"sh_logger",
".",
"error",
"(",
"\"Error running '#{command}': #{ex.message}\"",
")",
"127",
"end"
] |
Run a shell command, capturing and logging its output.
If the command completed successfully, it's output is logged at DEBUG.
If not, its output as logged at INFO. In either case, its
error output is logged at WARN.
command:: the command to run as a String or Array of String. The String form is simplest, but
is open to injection. If you need to execute a command that is assembled from some portion
of user input, consider using an Array of String. This form prevents tokenization that occurs
in the String form. The first element is the command to execute,
and the remainder are the arguments. See Methadone::ExecutionStrategy::Base for more info.
options:: options to control the call. Currently responds to:
+:expected+:: an Int or Array of Int representing error codes, <b>in addition to 0</b>, that are
expected and therefore constitute success. Useful for commands that don't use
exit codes the way you'd like
block:: if provided, will be called if the command exited nonzero. The block may take 0, 1, 2, or 3 arguments.
The arguments provided are the standard output as a string, standard error as a string, and
the exitstatus as an Int.
You should be safe to pass in a lambda instead of a block, as long as your
lambda doesn't take more than three arguments
Example
sh "cp foo /tmp"
sh "ls /tmp" do |stdout|
# stdout contains the output of ls /tmp
end
sh "ls -l /tmp foobar" do |stdout,stderr|
# ...
end
Returns the exit status of the command. Note that if the command doesn't exist, this returns 127.
|
[
"Run",
"a",
"shell",
"command",
"capturing",
"and",
"logging",
"its",
"output",
".",
"If",
"the",
"command",
"completed",
"successfully",
"it",
"s",
"output",
"is",
"logged",
"at",
"DEBUG",
".",
"If",
"not",
"its",
"output",
"as",
"logged",
"at",
"INFO",
".",
"In",
"either",
"case",
"its",
"error",
"output",
"is",
"logged",
"at",
"WARN",
"."
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/sh.rb#L100-L120
|
17,998
|
davetron5000/methadone
|
lib/methadone/sh.rb
|
Methadone.SH.call_block
|
def call_block(block,stdout,stderr,exitstatus)
# blocks that take no arguments have arity -1. Or 0. Ugh.
if block.arity > 0
case block.arity
when 1
block.call(stdout)
when 2
block.call(stdout,stderr)
else
# Let it fail for lambdas
block.call(stdout,stderr,exitstatus)
end
else
block.call
end
end
|
ruby
|
def call_block(block,stdout,stderr,exitstatus)
# blocks that take no arguments have arity -1. Or 0. Ugh.
if block.arity > 0
case block.arity
when 1
block.call(stdout)
when 2
block.call(stdout,stderr)
else
# Let it fail for lambdas
block.call(stdout,stderr,exitstatus)
end
else
block.call
end
end
|
[
"def",
"call_block",
"(",
"block",
",",
"stdout",
",",
"stderr",
",",
"exitstatus",
")",
"# blocks that take no arguments have arity -1. Or 0. Ugh.",
"if",
"block",
".",
"arity",
">",
"0",
"case",
"block",
".",
"arity",
"when",
"1",
"block",
".",
"call",
"(",
"stdout",
")",
"when",
"2",
"block",
".",
"call",
"(",
"stdout",
",",
"stderr",
")",
"else",
"# Let it fail for lambdas",
"block",
".",
"call",
"(",
"stdout",
",",
"stderr",
",",
"exitstatus",
")",
"end",
"else",
"block",
".",
"call",
"end",
"end"
] |
Safely call our block, even if the user passed in a lambda
|
[
"Safely",
"call",
"our",
"block",
"even",
"if",
"the",
"user",
"passed",
"in",
"a",
"lambda"
] |
2e670ac24cee3ab8658a1de62a70ff58e7806dc5
|
https://github.com/davetron5000/methadone/blob/2e670ac24cee3ab8658a1de62a70ff58e7806dc5/lib/methadone/sh.rb#L206-L221
|
17,999
|
akretion/ooor
|
lib/ooor/associations.rb
|
Ooor.Associations.relationnal_result
|
def relationnal_result(method_name, *arguments)
self.class.reload_fields_definition(false)
if self.class.many2one_associations.has_key?(method_name)
load_m2o_association(method_name, *arguments)
elsif self.class.polymorphic_m2o_associations.has_key?(method_name)# && @associations[method_name]
load_polymorphic_m2o_association(method_name, *arguments)
# values = @associations[method_name].split(',')
# self.class.const_get(values[0]).find(values[1], arguments.extract_options!)
else # o2m or m2m
load_x2m_association(method_name, *arguments)
end
end
|
ruby
|
def relationnal_result(method_name, *arguments)
self.class.reload_fields_definition(false)
if self.class.many2one_associations.has_key?(method_name)
load_m2o_association(method_name, *arguments)
elsif self.class.polymorphic_m2o_associations.has_key?(method_name)# && @associations[method_name]
load_polymorphic_m2o_association(method_name, *arguments)
# values = @associations[method_name].split(',')
# self.class.const_get(values[0]).find(values[1], arguments.extract_options!)
else # o2m or m2m
load_x2m_association(method_name, *arguments)
end
end
|
[
"def",
"relationnal_result",
"(",
"method_name",
",",
"*",
"arguments",
")",
"self",
".",
"class",
".",
"reload_fields_definition",
"(",
"false",
")",
"if",
"self",
".",
"class",
".",
"many2one_associations",
".",
"has_key?",
"(",
"method_name",
")",
"load_m2o_association",
"(",
"method_name",
",",
"arguments",
")",
"elsif",
"self",
".",
"class",
".",
"polymorphic_m2o_associations",
".",
"has_key?",
"(",
"method_name",
")",
"# && @associations[method_name]",
"load_polymorphic_m2o_association",
"(",
"method_name",
",",
"arguments",
")",
"# values = @associations[method_name].split(',')",
"# self.class.const_get(values[0]).find(values[1], arguments.extract_options!)",
"else",
"# o2m or m2m",
"load_x2m_association",
"(",
"method_name",
",",
"arguments",
")",
"end",
"end"
] |
fakes associations like much like ActiveRecord according to the cached OpenERP data model
|
[
"fakes",
"associations",
"like",
"much",
"like",
"ActiveRecord",
"according",
"to",
"the",
"cached",
"OpenERP",
"data",
"model"
] |
f0aa6c70601cc28dbbb519ebec33af40f57b3943
|
https://github.com/akretion/ooor/blob/f0aa6c70601cc28dbbb519ebec33af40f57b3943/lib/ooor/associations.rb#L28-L39
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.