idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
7,600
def parse ( node ) columns_count = 1 j = 0 node . xpath ( 'm:mPr' ) . each do | m_pr | m_pr . xpath ( 'm:mcs' ) . each do | mcs | mcs . xpath ( 'm:mc' ) . each do | mc | mc . xpath ( 'm:mcPr' ) . each do | mc_pr | mc_pr . xpath ( 'm:count' ) . each do | count | columns_count = count . attribute ( 'val' ) . value . to_i...
Parse Matrix object
7,601
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'alias' @alias = ValuedChild . new ( :string , parent : self ) . parse ( node_child ) when 'tag' @tag = ValuedChild . new ( :string , parent : self ) . parse ( node_child ) when 'lock' @lock = ValuedChild . new ( :symbol , pare...
Parse SDTProperties object
7,602
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'p' @paragraphs << Paragraph . new ( parent : self ) . parse ( node_child ) when 'bodyPr' @properties = OOXMLShapeBodyProperties . new ( parent : self ) . parse ( node_child ) end end self end
Parse TextBody object
7,603
def parse ( node ) node . attributes . each do | key , value | case key when 'transition' @transition = value . value when 'filter' @filter = value . value end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'cBhvr' @behavior = Behavior . new ( parent : self ) . parse ( node_child ) end en...
Parse AnimationEffect object
7,604
def parse ( node ) node . attributes . each do | key , value | case key when 'applyFont' @apply_font = attribute_enabled? ( value ) when 'applyBorder' @apply_border = attribute_enabled? ( value ) when 'applyFill' @apply_fill = attribute_enabled? ( value ) when 'applyNumberFormat' @apply_number_format = attribute_enable...
Parse Xf object
7,605
def parse ( node ) node . attributes . each do | key , value | case key when 'state' @state = value . value . to_sym when 'topLeftCell' @top_left_cell = Coordinates . parse_coordinates_from_string ( value . value ) when 'xSplit' @x_split = value . value when 'ySplit' @y_split = value . value end end self end
Parse Pane object
7,606
def parse ( node ) node . attributes . each do | key , value | case key when 'authorId' @author_id = value . value . to_i end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'pos' @position = OOXMLCoordinates . parse ( node_child , x_attr : 'x' , y_attr : 'y' ) when 'text' @text = node_chi...
Parse PresentationComment object
7,607
def fill_empty_table_styles TABLE_STYLES_NAMES_HASH . each_value do | current_table_style | style_exist = false @table_style_properties_list . each do | existing_style | style_exist = true if existing_style . type == current_table_style end next if style_exist @table_style_properties_list << TableStyleProperties . new ...
Fill all empty tables styles with default value To make last changes in parsing table styles compatible with ooxml_parser 0 . 1 . 2 and earlier
7,608
def parse ( node ) node . attributes . each do | key , value | case key when 'showButton' @show_button = attribute_enabled? ( value ) end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'customFilters' @custom_filters = CustomFilters . new ( parent : self ) . parse ( node_child ) end end s...
Parse FilterColumn data
7,609
def parse ( node ) node . attributes . each do | key , value | case key when 'gridSpan' @grid_span = value . value . to_i when 'hMerge' @horizontal_merge = value . value . to_i when 'vMerge' @vertical_merge = value . value . to_i end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'txBody'...
Parse TableCell object
7,610
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'dPr' node_child . xpath ( '*' ) . each do | node_child_child | case node_child_child . name when 'begChr' @begin_character = ValuedChild . new ( :string , parent : self ) . parse ( node_child_child ) when 'endChr' @end_charact...
Parse Delimiter object
7,611
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'delete' @display = false if node_child . attribute ( 'val' ) . value == '1' when 'title' @title = ChartAxisTitle . new ( parent : self ) . parse ( node_child ) when 'majorGridlines' @major_grid_lines = true when 'minorGridline...
Parse ChartAxis object
7,612
def parse ( node ) node . xpath ( '*' ) . each do | child_node | case child_node . name when 'legendPos' @position = value_to_symbol ( child_node . attribute ( 'val' ) ) when 'overlay' @overlay = true if child_node . attribute ( 'val' ) . value . to_s == '1' end end self end
Parse ChartLegend object
7,613
def parse ( file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/comments/comment1.xml" ) return nil unless File . exist? ( file ) document = parse_xml ( File . open ( file ) ) node = document . xpath ( '*' ) . first node . xpath ( '*' ) . each do | node_child | case node_child . name whe...
Parse PresentationComments object
7,614
def to_base_unit case @unit when :centimeter OoxmlSize . new ( @value * 360_000 ) when :point OoxmlSize . new ( @value * 12_700 ) when :half_point OoxmlSize . new ( @value * ( 12_700 / 2 ) ) when :one_eighth_point OoxmlSize . new ( @value * ( 12_700 / 8 ) ) when :one_100th_point OoxmlSize . new ( @value * ( 12_700 / 10...
Convert all values to one same base unit
7,615
def parse properties_file = "#{OOXMLDocumentObject.path_to_folder}docProps/app.xml" unless File . exist? ( properties_file ) warn "There is no 'docProps/app.xml' in docx. It may be some problem with it" return self end node = parse_xml ( properties_file ) node . xpath ( '*' ) . each do | node_child | case node_child . ...
Parse Document properties
7,616
def parse ( node ) node . attributes . each do | key , value | case key when 'name' @name = value . value when 'id' @id = value . value when 'title' @title = value . value when 'descr' @description = value . value end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'hlinkClick' @on_click_h...
Parse CommonNonVisualProperties object
7,617
def to_rgb chroma = ( 1 - ( 2 * @l - 1 ) . abs ) * @s x = chroma * ( 1 - ( ( @h / 60.0 ) % 2.0 - 1 ) . abs ) m = @l - chroma / 2.0 rgb = if @h . zero? Color . new ( 0 , 0 , 0 ) elsif @h > 0 && @h < 60 Color . new ( chroma , x , 0 ) elsif @h > 60 && @h < 120 Color . new ( x , chroma , 0 ) elsif @h > 120 && @h < 180 Colo...
Chroma - The colorfulness relative to the brightness of a similarly illuminated white .
7,618
def parse ( node ) @type = node . name . to_sym case node . name when 'blinds' , 'checker' , 'comb' , 'cover' , 'pull' , 'push' , 'randomBar' , 'strips' , 'wipe' , 'zoom' , 'warp' @direction = value_to_symbol ( node . attribute ( 'dir' ) ) if node . attribute ( 'dir' ) when 'cut' , 'fade' @through_black = option_enable...
Parse TransitionProperties object
7,619
def parse ( node ) node . attributes . each do | key , value | case key when 'id' @id = value . value . to_i when 'author' @author = value . value . to_s when 'date' @date = parse_date ( value . value . to_s ) when 'oouserid' @user_id = value . value . to_s end end node . xpath ( '*' ) . each do | node_child | case nod...
Parse Inserted object
7,620
def parse ( node ) node . attributes . each do | key , value | case key when 'type' @type = value . value . to_sym end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'rPr' @run_properties = RunProperties . new ( parent : self ) . parse ( node_child ) when 'tcPr' @table_cell_properties = C...
Parse table style property
7,621
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'bgPr' @properties = BackgroundProperties . new ( parent : self ) . parse ( node_child ) end end background_properties_node = node . xpath ( 'p:bgPr' ) . first if background_properties_node @shade_to_title = attribute_enabled? ...
Parse Background object
7,622
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'sdtContent' @sdt_content = SDTContent . new ( parent : self ) . parse ( node_child ) when 'sdtPr' @properties = SDTProperties . new ( parent : self ) . parse ( node_child ) end end self end
Parse StructuredDocumentTag object
7,623
def parse ( node ) node . attributes . each do | key , value | case key when 'ref' @ref = Coordinates . parser_coordinates_range ( value . value ) end end node . xpath ( '*' ) . each do | node_child | case node_child . name when 'filterColumn' @filter_column = FilterColumn . new ( parent : self ) . parse ( node_child )...
Parse Autofilter data
7,624
def parse ( node ) node . xpath ( '*' ) . each do | node_child | case node_child . name when 'pPr' @properties = ParagraphProperties . new ( parent : self ) . parse ( node_child ) when 'fld' @text_field = TextField . new ( parent : self ) . parse ( node_child ) when 'r' @runs << ParagraphRun . new ( parent : self ) . p...
Parse Paragraph object
7,625
def parse ( node ) node . xpath ( '*' ) . each do | column_node | case column_node . name when 'table' @table = X14Table . new ( parent : self ) . parse ( column_node ) when 'sparklineGroups' @sparkline_groups = SparklineGroups . new ( parent : self ) . parse ( column_node ) end end self end
Parse Extension data
7,626
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 ) . pars...
Parse DocxShapeProperties object
7,627
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_chi...
Parse ColorProperties object
7,628
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 ( pare...
Parse DocxShapeLine object
7,629
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' @table_style_element = TableStyle . new ( parent : self ) . parse...
Parse TableProperties object
7,630
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
7,631
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 en...
Parse TableCellLine object
7,632
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 = OOX...
Parse DocxShape object
7,633
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 ( nod...
Parse SDTContent object
7,634
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 ( paren...
Parse CommonTiming object
7,635
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...
Parse OOXMLCustomGeometry object
7,636
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 ...
Parse OldDocxPicture object
7,637
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 DocxFormula object
7,638
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
7,639
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' @...
Parse XlsxColumnProperties object
7,640
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 ( pa...
Parse OOXMLTextBox object
7,641
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
7,642
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
7,643
def parse ( node ) @borders = true if node . name == 'borderBox' @element = MathRun . new ( parent : self ) . parse ( node ) self end
Parse Box object
7,644
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_ch...
Parse ImageFill object
7,645
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
7,646
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
7,647
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 ( spa...
Parse data for Spacing
7,648
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 ...
Parse GradientStop object
7,649
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
7,650
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 ,...
Parse TablePart object
7,651
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' @pan...
Parse SheetView object
7,652
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 , ...
Parse DocxDrawingPosition object
7,653
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 OldDocxShape object
7,654
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
7,655
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
7,656
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
7,657
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' @numberin...
Parse Numbering Level data
7,658
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
7,659
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
7,660
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_c...
Parse GraphicFrame object
7,661
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 'o...
Parse DocxShapeSize object
7,662
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 = :squa...
Parse DocxWrapDrawing object
7,663
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 ( no...
Parse DocxShapeLinePath object
7,664
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...
Parse PresentationFill object
7,665
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 . ...
Parse ParagraphProperties object
7,666
def parse ( node ) root_object . default_font_style = FontStyle . new ( true ) 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 = TableRow...
Parse TableRow object
7,667
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...
Parse XlsxDrawingPositionParameters object
7,668
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' @typ...
Parse Fill data
7,669
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_chil...
Parse Bookmark object
7,670
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' @back...
Parse PatternFill data
7,671
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 ,...
Sets the base url in redis . If the first page is a redirect it sets the base_url to the destination
7,672
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 .
7,673
def get ( id , options = { } , raw = false ) if options == true || options == false 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 .
7,674
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
7,675
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
7,676
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 ( ...
Many of the methods marked protected are called by one line shims in subclasses . This is mostly to facilitate better looking rdocs
7,677
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...
Internal use only Check response codes from request
7,678
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
7,679
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
7,680
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 .
7,681
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
7,682
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
7,683
def send_org_invite ( user , invite ) user . send ( :generate_confirmation_token! ) if ! user . confirmed? && user . confirmation_token . blank? MnoEnterprise :: SystemNotificationMailer . organization_invite ( invite ) . deliver_later invite . status = 'pending' if invite . status == 'staged' invite . notification_sen...
Send the org invite and update the status
7,684
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
7,685
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
7,686
def role ( organization = nil ) return self . read_attribute ( :role ) if ! organization 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
7,687
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 ( resou...
Redirect to previous url and reset it
7,688
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
7,689
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
7,690
def call ( args = { } ) evaluate_command_definition ( args ) response = tasks . map do | task | response = task . call ( args ) return response unless response . success? response end . last end
Invoke the command that has already been defined .
7,691
def optional_parameters definition_lambda . parameters . select { | key , _value | key == :key } . map { | _key , value | value } end
Returns a list of any optional parameters
7,692
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
7,693
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
7,694
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"...
Convert a theme provided as a hash into a properly formatted LESS file
7,695
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
7,696
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 ...
Add a repeated header to the document
7,697
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...
Add a repeated footer to the document
7,698
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
7,699
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...
Regular Best Bets