idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
10,900 | def fetch_items_from_filesystem_or_zip unless in_zip? @items = Dir . foreach ( current_dir ) . map { | fn | load_item dir : current_dir , name : fn } . to_a . partition { | i | %w( . .. ) . include? i . name } . flatten else @items = [ load_item ( dir : current_dir , name : '.' , stat : File . stat ( current_dir ) ) , ... | Fetch files from current directory or current . zip file . |
10,901 | def find ( str ) index = items . index { | i | i . index > current_row && i . name . start_with? ( str ) } || items . index { | i | i . name . start_with? str } move_cursor index if index end | Focus at the first file or directory of which name starts with the given String . |
10,902 | def find_reverse ( str ) index = items . reverse . index { | i | i . index < current_row && i . name . start_with? ( str ) } || items . reverse . index { | i | i . name . start_with? str } move_cursor items . size - index - 1 if index end | Focus at the last file or directory of which name starts with the given String . |
10,903 | def draw_items main . newpad items @displayed_items = items [ current_page * max_items , max_items ] main . display current_page header_l . draw_path_and_page_number path : current_dir . path , current : current_page + 1 , total : total_pages end | Update the main window with the loaded files and directories . Also update the header . |
10,904 | def sort_items_according_to_current_direction case @direction when nil @items = items . shift ( 2 ) + items . partition ( & :directory? ) . flat_map ( & :sort ) when 'r' @items = items . shift ( 2 ) + items . partition ( & :directory? ) . flat_map { | arr | arr . sort . reverse } when 'S' , 's' @items = items . shift (... | Sort the loaded files and directories in already given sort order . |
10,905 | def grep ( pattern = '.*' ) regexp = Regexp . new ( pattern ) fetch_items_from_filesystem_or_zip @items = items . shift ( 2 ) + items . select { | i | i . name =~ regexp } sort_items_according_to_current_direction draw_items draw_total_items switch_page 0 move_cursor 0 end | Search files and directories from the current directory and update the screen . |
10,906 | def cp ( dest ) unless in_zip? src = ( m = marked_items ) . any? ? m . map ( & :path ) : current_item FileUtils . cp_r src , expand_path ( dest ) else raise 'cping multiple items in .zip is not supported.' if selected_items . size > 1 Zip :: File . open ( current_zip ) do | zip | entry = zip . find_entry ( selected_ite... | Copy selected files and directories to the destination . |
10,907 | def mv ( dest ) unless in_zip? src = ( m = marked_items ) . any? ? m . map ( & :path ) : current_item FileUtils . mv src , expand_path ( dest ) else raise 'mving multiple items in .zip is not supported.' if selected_items . size > 1 rename "#{selected_items.first.name}/#{dest}" end ls end | Move selected files and directories to the destination . |
10,908 | def rename ( pattern ) from , to = pattern . sub ( / \/ / , '' ) . sub ( / \/ / , '' ) . split '/' if to . nil? from , to = current_item . name , from else from = Regexp . new from end unless in_zip? selected_items . each do | item | name = item . name . gsub from , to FileUtils . mv item , current_dir . join ( name ) ... | Rename selected files and directories . |
10,909 | def trash unless in_zip? if osx? FileUtils . mv selected_items . map ( & :path ) , File . expand_path ( '~/.Trash/' ) else FileUtils . rm_rf selected_items . map ( & :path ) end else return unless ask %Q[Trashing zip entries is not supported. Actually the files will be deleted. Are you sure want to proceed? (y/n)] dele... | Soft delete selected files and directories . |
10,910 | def delete unless in_zip? FileUtils . rm_rf selected_items . map ( & :path ) else Zip :: File . open ( current_zip ) do | zip | zip . select { | e | selected_items . map ( & :name ) . include? e . to_s } . each do | entry | if entry . name_is_directory? zip . dir . delete entry . to_s else zip . file . delete entry . t... | Delete selected files and directories . |
10,911 | def mkdir ( dir ) unless in_zip? FileUtils . mkdir_p current_dir . join ( dir ) else Zip :: File . open ( current_zip ) do | zip | zip . dir . mkdir dir end end ls end | Create a new directory . |
10,912 | def touch ( filename ) unless in_zip? FileUtils . touch current_dir . join ( filename ) else Zip :: File . open ( current_zip ) do | zip | zip . instance_variable_get ( :@entry_set ) << Zip :: Entry . new ( current_zip , filename ) end end ls end | Create a new empty file . |
10,913 | def zip ( zipfile_name ) return unless zipfile_name zipfile_name += '.zip' unless zipfile_name . end_with? '.zip' Zip :: File . open ( zipfile_name , Zip :: File :: CREATE ) do | zipfile | selected_items . each do | item | next if item . symlink? if item . directory? Dir [ item . join ( '**/**' ) ] . each do | file | z... | Archive selected files and directories into a . zip file . |
10,914 | def unarchive unless in_zip? zips , gzs = selected_items . partition ( & :zip? ) . tap { | z , others | break [ z , * others . partition ( & :gz? ) ] } zips . each do | item | FileUtils . mkdir_p current_dir . join ( item . basename ) Zip :: File . open ( item ) do | zip | zip . each do | entry | FileUtils . mkdir_p Fi... | Unarchive . zip and . tar . gz files within selected files and directories into current_directory . |
10,915 | def switch_page ( page ) main . display ( @current_page = page ) @displayed_items = items [ current_page * max_items , max_items ] header_l . draw_path_and_page_number path : current_dir . path , current : current_page + 1 , total : total_pages end | Move to the given page number . |
10,916 | def draw_marked_items items = marked_items header_r . draw_marked_items count : items . size , size : items . inject ( 0 ) { | sum , i | sum += i . size } end | Update the header information concerning currently marked files or directories . |
10,917 | def draw_total_items header_r . draw_total_items count : items . size , size : items . inject ( 0 ) { | sum , i | sum += i . size } end | Update the header information concerning total files and directories in the current directory . |
10,918 | def process_command_line ( preset_command : nil ) prompt = preset_command ? ":#{preset_command} " : ':' command_line . set_prompt prompt cmd , * args = command_line . get_command ( prompt : prompt ) . split ( ' ' ) if cmd && ! cmd . empty? && respond_to? ( cmd ) ret = self . public_send cmd , * args clear_command_line ... | Accept user input and directly execute it as a Ruby method call to the controller . |
10,919 | def process_shell_command command_line . set_prompt ':!' cmd = command_line . get_command ( prompt : ':!' ) [ 1 .. - 1 ] execute_external_command pause : true do system cmd end rescue Interrupt ensure command_line . clear command_line . noutrefresh end | Accept user input and directly execute it in an external shell . |
10,920 | def ask ( prompt = '(y/n)' ) command_line . set_prompt prompt command_line . refresh while ( c = Curses . getch ) next unless [ ?N , ?Y , ?n , ?y , 3 , 27 ] . include? c command_line . clear command_line . noutrefresh break ( c == 'y' ) || ( c == 'Y' ) end end | Let the user answer y or n . |
10,921 | def edit execute_external_command do editor = ENV [ 'EDITOR' ] || 'vim' unless in_zip? system %Q[#{editor} "#{current_item.path}"] else begin tmpdir , tmpfile_name = nil Zip :: File . open ( current_zip ) do | zip | tmpdir = Dir . mktmpdir FileUtils . mkdir_p File . join ( tmpdir , File . dirname ( current_item . name ... | Open current file or directory with the editor . |
10,922 | def view pager = ENV [ 'PAGER' ] || 'less' execute_external_command do unless in_zip? system %Q[#{pager} "#{current_item.path}"] else begin tmpdir , tmpfile_name = nil Zip :: File . open ( current_zip ) do | zip | tmpdir = Dir . mktmpdir FileUtils . mkdir_p File . join ( tmpdir , File . dirname ( current_item . name ) ... | Open current file or directory with the viewer . |
10,923 | def run ( situation ) @expectings << situation . evaluate ( & @expectation_block ) if @expectation_block actual = situation . evaluate ( & definition ) assert ( ( @macro . expects_exception? ? nil : actual ) , * @expectings ) rescue Exception => e @macro . expects_exception? ? assert ( e , * @expectings ) : @macro . er... | Setups a new Assertion . By default the assertion will be a positive one which means + evaluate + will be call on the associated assertion macro . If + negative + is true + devaluate + will be called instead . Not providing a definition block is just kind of silly since it s used to generate the + actual + value for ev... |
10,924 | def format_error ( e ) format = [ " #{e.class.name} occurred" , "#{e.to_s}" ] filter_backtrace ( e . backtrace ) { | line | format << " at #{line}" } format . join ( "\n" ) end | Generates a message for assertions that error out . However in the additional stacktrace any mentions of Riot and Rake framework methods calls are removed . Makes for a more readable error response . |
10,925 | def O dir = current_item . directory? ? current_item . path : current_dir . path system %Q[osascript -e 'tell app "Terminal" do script "cd #{dir}" end tell'] if osx? end | O pen terminal here . |
10,926 | def ctrl_a mark = marked_items . size != ( items . size - 2 ) items . each { | i | i . toggle_mark unless i . marked? == mark } draw_items draw_marked_items move_cursor current_row end | Mark or unmark a ll files and directories . |
10,927 | def enter if current_item . name == '.' elsif current_item . name == '..' cd '..' elsif in_zip? v elsif current_item . directory? || current_item . zip? cd current_item else v end end | cd into a directory or view a file . |
10,928 | def del if current_dir . path != '/' dir_was = times == 1 ? current_dir . name : File . basename ( current_dir . join ( [ '..' ] * ( times - 1 ) ) ) cd File . expand_path ( current_dir . join ( [ '..' ] * times ) ) find dir_was end end | cd to the upper hierarchy . |
10,929 | def method_missing ( meth , * phrases , & block ) push ( meth . to_s . gsub ( '_' , ' ' ) ) _inspect ( phrases ) end | Converts any method call into a more readable string by replacing underscores with spaces . Any arguments to the method are inspected and appended to the final message . Blocks are currently ignored . |
10,930 | def report ( description , response ) code , result = * response case code when :pass then @passes += 1 pass ( description , result ) when :fail then @failures += 1 message , line , file = * response [ 1 .. - 1 ] fail ( description , message , line , file ) when :error , :setup_error , :context_error then @errors += 1 ... | Called immediately after an assertion has been evaluated . From this method either + pass + + fail + or + error + will be called . |
10,931 | def encoded_char_array char_array = [ ] index = 0 while ( index < data . length ) do char = data [ index ] if char == '%' skip_next = 2 unless data [ index + 1 ] =~ HEX_CHARS_REGEX index += 2 next end unless data [ index + 2 ] =~ HEX_CHARS_REGEX index += 3 next end first_byte = '0x' + ( data [ index + 1 ] + data [ inde... | Returns an array of valid URI - encoded UTF - 8 characters . |
10,932 | def utf8_char_length_in_bytes ( first_byte ) if first_byte . hex < 'C0' . hex 1 elsif first_byte . hex < 'DF' . hex 2 elsif first_byte . hex < 'EF' . hex 3 else 4 end end | If the first byte is between 0xC0 and 0xDF the UTF - 8 character has two bytes ; if it is between 0xE0 and 0xEF the UTF - 8 character has 3 bytes ; and if it is 0xF0 and 0xFF the UTF - 8 character has 4 bytes . first_byte is a string like 0x13 |
10,933 | def ecs_services_with_ids ( * ids ) if ids . empty? ecs_services else ecs_services . select do | s | ids . include? ( s . logical_resource_id ) end end end | get services with a list of logical ids |
10,934 | def perform ( name = nil , count = nil ) Maestrano :: Connector :: Rails :: Organization . where . not ( oauth_provider : nil , encrypted_oauth_token : nil ) . where ( sync_enabled : true ) . select ( :id ) . find_each do | organization | Maestrano :: Connector :: Rails :: SynchronizationJob . set ( wait : rand ( 3600 ... | Trigger synchronization of all active organizations |
10,935 | def clean! self . class :: SIMPLE_ELEMENTS . each do | element | val = self . send ( element ) send ( "#{element}=" , ( val . is_a? ( Array ) ? val . collect { | v | HtmlCleaner . flatten ( v . to_s ) } : HtmlCleaner . flatten ( val . to_s ) ) ) end self . class :: HTML_ELEMENTS . each do | element | send ( "#{element}... | Recursively cleans all elements in place . |
10,936 | def ssm_parameter_tmpfile ( name ) Tempfile . new ( stack_name ) . tap do | file | file . write ( ssm_parameter_get ( name ) ) File . chmod ( 0400 , file . path ) file . close end end | get a parameter from the store to a Tmpfile |
10,937 | def ssm_run_shellscript ( * cmd ) Aws :: Ssm . run ( document_name : 'AWS-RunShellScript' , targets : [ { key : 'tag:aws:cloudformation:stack-name' , values : [ stack_name ] } ] , parameters : { commands : cmd } ) &. command_id . tap ( & method ( :puts ) ) end | run a command on stack instances |
10,938 | def report ( controller ) return if results . empty? action_display = "#{controller.controller_name}##{controller.action_name}" SnipSnip . logger . info ( action_display ) results . sort_by ( & :report ) . each do | result | SnipSnip . logger . info ( " #{result.report}" ) end ensure Registry . clear end | Report on the unused columns that were selected during the course of the processing the action on the given controller . |
10,939 | def fold_references ( mapped_external_entity , references , organization ) references = format_references ( references ) mapped_external_entity = mapped_external_entity . with_indifferent_access ( references . values . flatten + [ 'id' ] ) . each do | reference | fold_references_helper ( mapped_external_entity , refere... | Replaces ids from the external application by arrays containing them |
10,940 | def id_hash ( id , organization ) { id : id , provider : organization . oauth_provider , realm : organization . oauth_uid } end | Builds an id_hash from the id and organization |
10,941 | def fold_references_helper ( entity , array_of_refs , organization ) ref = array_of_refs . shift field = entity [ ref ] return if field . blank? case field when Array field . each do | f | fold_references_helper ( f , array_of_refs . dup , organization ) end when Hash fold_references_helper ( entity [ ref ] , array_of_... | Recursive method for folding references |
10,942 | def unfold_references_helper ( entity , array_of_refs , organization ) ref = array_of_refs . shift field = entity [ ref ] if array_of_refs . empty? && field return entity . delete ( ref ) if field . is_a? ( String ) id_hash = field . find { | id | id [ :provider ] == organization . oauth_provider && id [ :realm ] == or... | Recursive method for unfolding references |
10,943 | def filter_connec_entity_for_id_refs ( connec_entity , id_references ) return { } if id_references . empty? entity = connec_entity . dup . with_indifferent_access tree = build_id_references_tree ( id_references ) filter_connec_entity_for_id_refs_helper ( entity , tree ) entity end | Returns the connec_entity without all the fields that are not id_references |
10,944 | def filter_connec_entity_for_id_refs_helper ( entity_hash , tree ) return if tree . empty? entity_hash . slice! ( * tree . keys ) tree . each do | key , children | case entity_hash [ key ] when Array entity_hash [ key ] . each do | hash | filter_connec_entity_for_id_refs_helper ( hash , children ) end when Hash filter_... | Recursive method for filtering connec entities |
10,945 | def merge_id_hashes ( dist , src , id_references ) dist = dist . with_indifferent_access src = src . with_indifferent_access id_references . each do | id_reference | array_of_refs = id_reference . split ( '/' ) merge_id_hashes_helper ( dist , array_of_refs , src ) end dist end | Merges the id arrays from two hashes while keeping only the id_references fields |
10,946 | def merge_id_hashes_helper ( hash , array_of_refs , src , path = [ ] ) ref = array_of_refs . shift field = hash [ ref ] if array_of_refs . empty? && field value = value_from_hash ( src , path + [ ref ] ) if value . is_a? ( Array ) hash [ ref ] = ( field + value ) . uniq else hash . delete ( ref ) end else case field wh... | Recursive helper for merging id hashes |
10,947 | def taskdef_to_hash ( taskdef ) args = %i[ family cpu memory requires_compatibilities task_role_arn execution_role_arn network_mode container_definitions volumes placement_constraints ] taskdef . to_hash . slice ( * args ) end | convert to hash for registering new taskdef |
10,948 | def ecs_deploy ( id , & block ) service = Aws :: Ecs . services ( ecs_cluster_name , [ resource ( id ) ] ) . first taskdef = get_taskdef ( service ) hash = taskdef_to_hash ( taskdef ) yield ( hash ) if block_given? taskdef = register_taskdef ( hash ) update_service ( service , taskdef ) end | update taskdef for a service triggering a deploy modify current taskdef in block |
10,949 | def store_file ( filename , content ) zip . put_next_entry filename , nil , nil , Zip :: Entry :: STORED , Zlib :: NO_COMPRESSION zip . write content . to_s end | Store a file in the archive without any compression . |
10,950 | def compress_file ( filename , content ) zip . put_next_entry filename , nil , nil , Zip :: Entry :: DEFLATED , Zlib :: BEST_COMPRESSION zip . write content . to_s end | Store a file with maximum compression in the archive . |
10,951 | def pluck ( * cols ) options = cols . last . is_a? ( Hash ) ? cols . pop : { } @options . merge! ( options ) @options [ :symbolize_keys ] = true self . iterate_type ( options [ :class ] ) if options [ :class ] cols = cols . map { | c | c . to_sym } result = [ ] self . each ( ) do | row | row = row . symbolize_keys if r... | Returns an array of columns plucked from the result rows . Experimental function as this could still use too much memory and negate the purpose of this libarary . Should this return a lazy enumerator instead? |
10,952 | def weighted_account_match ( row ) query_tokens = tokenize ( row [ :description ] ) search_vector = [ ] account_vectors = { } query_tokens . each do | token | idf = Math . log ( ( accounts . keys . length + 1 ) / ( ( tokens [ token ] || { } ) . keys . length . to_f + 1 ) ) tf = 1.0 / query_tokens . length . to_f search... | Weigh accounts by how well they match the row |
10,953 | def lint return if target_files . empty? bin = textlint_path result_json = run_textlint ( bin , target_files ) errors = parse ( result_json ) send_comment ( errors ) end | Execute textlint and send comment |
10,954 | def set_defaults set_if_empty :karafka_role , :karafka set_if_empty :karafka_processes , 1 set_if_empty :karafka_consumer_groups , [ ] set_if_empty :karafka_default_hooks , -> { true } set_if_empty :karafka_env , -> { fetch ( :karafka_env , fetch ( :environment ) ) } set_if_empty :karafka_pid , -> { File . join ( share... | Default values for Karafka settings |
10,955 | def meets_requirements? ( params ) requirements . reject { | k | params . keys . map ( & :to_s ) . include? k . to_s } . empty? end | Given a hash of Request parameters do they meet the requirements? |
10,956 | def request ( params = { } ) normalize_parameters params raise UnmetRequirementsError , "Required parameters: #{requirements}" unless meets_requirements? params credentials = pull_credentials params pairs = pull_url_pairs params request = construct_request expand_url ( pairs ) , params , credentials yield request if bl... | Construct the request from the given parameters . |
10,957 | def compute_origin return nil if move . castle possibilities = case move . piece when / /i then direction_origins when / /i then move_origins when / /i then pawn_origins end if possibilities . length > 1 possibilities = disambiguate ( possibilities ) end self . board . position_for ( possibilities . first ) end | Using the current position and move figure out where the piece came from . |
10,958 | def direction_origins directions = DIRECTIONS [ move . piece . downcase ] possibilities = [ ] directions . each do | dir | piece , square = first_piece ( destination_coords , dir ) possibilities << square if piece == self . move . piece end possibilities end | From the destination square move in each direction stopping if we reach the end of the board . If we encounter a piece add it to the list of origin possibilities if it is the moving piece or else check the next direction . |
10,959 | def move_origins ( moves = nil ) moves ||= MOVES [ move . piece . downcase ] possibilities = [ ] file , rank = destination_coords moves . each do | i , j | f = file + i r = rank + j if valid_square? ( f , r ) && self . board . at ( f , r ) == move . piece possibilities << [ f , r ] end end possibilities end | From the destination square make each move . If it is a valid square and matches the moving piece add it to the list of origin possibilities . |
10,960 | def pawn_origins _ , rank = destination_coords double_rank = ( rank == 3 && self . move . white? ) || ( rank == 4 && self . move . black? ) pawn_moves = PAWN_MOVES [ self . move . piece ] moves = self . move . capture ? pawn_moves [ :capture ] : pawn_moves [ :normal ] moves += pawn_moves [ :double ] if double_rank move... | Computes the possbile pawn origins based on the destination square and whether or not the move is a capture . |
10,961 | def disambiguate_san ( possibilities ) move . disambiguation ? possibilities . select { | p | self . board . position_for ( p ) . match ( move . disambiguation ) } : possibilities end | Try to disambiguate based on the standard algebraic notation . |
10,962 | def disambiguate_pawns ( possibilities ) self . move . piece . match ( / /i ) && ! self . move . capture ? possibilities . reject { | p | self . board . position_for ( p ) . match ( / / ) } : possibilities end | A pawn can t move two spaces if there is a pawn in front of it . |
10,963 | def disambiguate_discovered_check ( possibilities ) DIRECTIONS . each do | attacking_piece , directions | attacking_piece = attacking_piece . upcase if self . move . black? directions . each do | dir | piece , square = first_piece ( king_position , dir ) next unless piece == self . move . piece && possibilities . inclu... | A piece can t move if it would result in a discovered check . |
10,964 | def en_passant_capture return nil if self . move . castle if ! self . board . at ( self . move . destination ) && self . move . capture self . move . destination [ 0 ] + self . origin [ 1 ] end end | If the move is a capture and there is no piece on the destination square it must be an en passant capture . |
10,965 | def call ( environment ) app = adapter . new middlewares = @middlewares || [ ] stack = Rack :: Builder . new do middlewares . each do | middleware | klass , * args = middleware use klass , * args [ 0 ... - 1 ] . flatten , & args . last end run app end stack . call rack_env_defaults . merge ( environment . update ( env ... | A Rack interface for the Request . Applies itself and whatever middlewares to the env and passes the new env into the adapter . |
10,966 | def perform future do status , headers , body = call ( rack_env_defaults ) response = Weary :: Response . new body , status , headers yield response if block_given? response end end | Returns a future - wrapped Response . |
10,967 | def query_params_from_hash ( value , prefix = nil ) case value when Array value . map { | v | query_params_from_hash ( v , "#{prefix}%5B%5D" ) } . join ( "&" ) when Hash value . map { | k , v | query_params_from_hash ( v , prefix ? "#{prefix}%5B#{Rack::Utils.escape_path(k)}%5D" : Rack :: Utils . escape_path ( k ) ) } .... | Stolen from Faraday |
10,968 | def to_html ( options = { } ) html = [ ] self . items . each do | item | html << item . to_html ( options ) end html . join end | Returns all + items + as HTML hidden field tags . |
10,969 | def find_by_office_order ( office_id , order_link_id , params = nil ) request ( :GET , "/#{office_id}/orders/#{order_link_id}" , params ) do | response | singular_class . new ( response . body . merge ( { :status_code => response . response_code , :server_message => response . server_message , :connection => response .... | Find affiliate commission of the office at the time the order was created |
10,970 | def play index = 0 hist = Array . new ( 3 , "" ) loop do puts "\e[H\e[2J" puts self . positions [ index ] . inspect hist [ 0 .. 2 ] = ( hist [ 1 .. 2 ] << STDIN . getch ) case hist . join when LEFT index -= 1 if index > 0 when RIGHT index += 1 if index < self . moves . length when EXIT break end end end | Interactively step through the game |
10,971 | def url_to_animation ( url , options = nil ) if options == nil options = AnimationOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLGet + "takeanimation.ashx" , false , options , url ) return nil end | Create a new instance of the Client class in order to access the GrabzIt API . |
10,972 | def url_to_image ( url , options = nil ) if options == nil options = ImageOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLGet + TakePicture , false , options , url ) return nil end | This method specifies the URL that should be converted into a image screenshot |
10,973 | def html_to_image ( html , options = nil ) if options == nil options = ImageOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLPost + TakePicture , true , options , html ) return nil end | This method specifies the HTML that should be converted into a image |
10,974 | def url_to_table ( url , options = nil ) if options == nil options = TableOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLGet + TakeTable , false , options , url ) return nil end | This method specifies the URL that the HTML tables should be extracted from |
10,975 | def html_to_table ( html , options = nil ) if options == nil options = TableOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLPost + TakeTable , true , options , html ) return nil end | This method specifies the HTML that the HTML tables should be extracted from |
10,976 | def url_to_pdf ( url , options = nil ) if options == nil options = PDFOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLGet + TakePDF , false , options , url ) return nil end | This method specifies the URL that should be converted into a PDF |
10,977 | def html_to_pdf ( html , options = nil ) if options == nil options = PDFOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLPost + TakePDF , true , options , html ) return nil end | This method specifies the HTML that should be converted into a PDF |
10,978 | def url_to_docx ( url , options = nil ) if options == nil options = DOCXOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLGet + TakeDOCX , false , options , url ) return nil end | This method specifies the URL that should be converted into a DOCX |
10,979 | def html_to_docx ( html , options = nil ) if options == nil options = DOCXOptions . new ( ) end @request = Request . new ( @protocol + WebServicesBaseURLPost + TakeDOCX , true , options , html ) return nil end | This method specifies the HTML that should be converted into a DOCX |
10,980 | def save ( callBackURL = nil ) if @request == nil raise GrabzItException . new ( "No parameters have been set." , GrabzItException :: PARAMETER_MISSING_PARAMETERS ) end sig = encode ( @request . options ( ) . _getSignatureString ( GrabzIt :: Utility . nil_check ( @applicationSecret ) , callBackURL , @request . getTarge... | Calls the GrabzIt web service to take the screenshot |
10,981 | def save_to ( saveToFile = nil ) id = save ( ) if id == nil || id == "" return false end sleep ( ( @request . options ( ) . startDelay ( ) / 1000 ) + 3 ) while true do status = get_status ( id ) if ! status . cached && ! status . processing raise GrabzItException . new ( "The capture did not complete with the error: " ... | Calls the GrabzIt web service to take the screenshot and saves it to the target path provided . if no target path is provided it returns the screenshot byte data . |
10,982 | def get_status ( id ) if id == nil || id == "" return nil end result = get ( @protocol + WebServicesBaseURLGet + "getstatus.ashx?id=" + GrabzIt :: Utility . nil_check ( id ) ) doc = REXML :: Document . new ( result ) processing = doc . root . elements [ "Processing" ] . text ( ) cached = doc . root . elements [ "Cached... | Get the current status of a GrabzIt screenshot |
10,983 | def get_result ( id ) if id == nil || id == "" return nil end return get ( @protocol + WebServicesBaseURLGet + "getfile.ashx?id=" + GrabzIt :: Utility . nil_check ( id ) ) end | This method returns the screenshot itself . If nothing is returned then something has gone wrong or the screenshot is not ready yet |
10,984 | def get_cookies ( domain ) sig = encode ( GrabzIt :: Utility . nil_check ( @applicationSecret ) + "|" + GrabzIt :: Utility . nil_check ( domain ) ) qs = "key=" qs . concat ( CGI . escape ( GrabzIt :: Utility . nil_check ( @applicationKey ) ) ) qs . concat ( "&domain=" ) qs . concat ( CGI . escape ( GrabzIt :: Utility .... | Get all the cookies that GrabzIt is using for a particular domain . This may include your user set cookies as well |
10,985 | def set_cookie ( name , domain , value = "" , path = "/" , httponly = false , expires = "" ) sig = encode ( GrabzIt :: Utility . nil_check ( @applicationSecret ) + "|" + GrabzIt :: Utility . nil_check ( name ) + "|" + GrabzIt :: Utility . nil_check ( domain ) + "|" + GrabzIt :: Utility . nil_check ( value ) + "|" + Gra... | Sets a new custom cookie on GrabzIt if the custom cookie has the same name and domain as a global cookie the global |
10,986 | def delete_cookie ( name , domain ) sig = encode ( GrabzIt :: Utility . nil_check ( @applicationSecret ) + "|" + GrabzIt :: Utility . nil_check ( name ) + "|" + GrabzIt :: Utility . nil_check ( domain ) + "|1" ) qs = "key=" qs . concat ( CGI . escape ( GrabzIt :: Utility . nil_check ( @applicationKey ) ) ) qs . concat ... | Delete a custom cookie or block a global cookie from being used |
10,987 | def add_watermark ( identifier , path , xpos , ypos ) if ! File . file? ( path ) raise "File: " + path + " does not exist" end sig = encode ( GrabzIt :: Utility . nil_check ( @applicationSecret ) + "|" + GrabzIt :: Utility . nil_check ( identifier ) + "|" + GrabzIt :: Utility . nil_int_check ( xpos ) + "|" + GrabzIt ::... | Add a new custom watermark |
10,988 | def delete_watermark ( identifier ) sig = encode ( GrabzIt :: Utility . nil_check ( @applicationSecret ) + "|" + GrabzIt :: Utility . nil_check ( identifier ) ) qs = "key=" qs . concat ( CGI . escape ( GrabzIt :: Utility . nil_check ( @applicationKey ) ) ) qs . concat ( "&identifier=" ) qs . concat ( CGI . escape ( Gra... | Delete a custom watermark |
10,989 | def set_local_proxy ( value ) if value uri = URI . parse ( value ) @proxy = Proxy . new ( uri . host , uri . port , uri . user , uri . password ) else @proxy = Proxy . new ( ) end end | This method enables a local proxy server to be used for all requests |
10,990 | def decrypt_file ( path , key ) data = read_file ( path ) decryptedFile = File . new ( path , "wb" ) decryptedFile . write ( decrypt ( data , key ) ) decryptedFile . close end | This method will decrypt a encrypted capture file using the key you passed to the encryption key parameter . |
10,991 | def decrypt ( data , key ) if data == nil return nil end iv = data [ 0 .. 15 ] payload = data [ 16 .. - 1 ] cipher = OpenSSL :: Cipher :: Cipher . new ( "aes-256-cbc" ) cipher . padding = 0 cipher . key = Base64 . strict_decode64 ( key ) ; cipher . iv = iv decrypted = cipher . update ( payload ) ; decrypted << cipher .... | This method will decrypt a encrypted capture using the key you passed to the encryption key parameter . |
10,992 | def halt_error ( status , errors , options = { } ) errors_as_json = errors . respond_to? ( :as_json ) ? errors . as_json : errors unless errors_as_json . is_a? ( Hash ) raise ArgumentError , "errors be an object representable in JSON as a Hash; got errors = #{errors.inspect}" end unless errors_as_json . keys . all? { |... | halt and render the given errors in the body on the errors key |
10,993 | def format_response ( status , body_object , headers = { } ) if status == 204 body = '' else body = case response_media_type when 'application/json' JSON . pretty_generate ( body_object ) when 'application/x-www-form-urlencoded' URI . encode_www_form ( body_object ) when 'application/xml' body_object . to_s when 'text/... | returns a rack response with the given object encoded in the appropriate format for the requests . |
10,994 | def request_body request . body . rewind request . body . read . tap do request . body . rewind end end | reads the request body |
10,995 | def parsed_body request_media_type = request . media_type unless request_media_type =~ / \S / fallback = true request_media_type = supported_media_types . first end case request_media_type when 'application/json' begin return JSON . parse ( request_body ) rescue JSON :: ParserError if fallback t_key = 'app.errors.reque... | returns the parsed contents of the request body . |
10,996 | def check_params_and_object_consistent ( path_params , object ) errors = { } path_params . each do | ( k , v ) | if object . key? ( k ) && object [ k ] != v errors [ k ] = [ I18n . t ( 'app.errors.inconsistent_uri_and_entity' , :key => k , :uri_value => v , :entity_value => object [ k ] , :default => "Inconsistent data... | for methods where parameters which are required in the path may also be specified in the body this takes the path_params and the body object and ensures that they are consistent any place they are specified in the body . |
10,997 | def object instance_variable_defined? ( :@object ) ? @object : @object = begin if media_type == 'application/json' JSON . parse ( body ) rescue nil elsif media_type == 'application/x-www-form-urlencoded' CGI . parse ( body ) . map { | k , vs | { k => vs . last } } . inject ( { } , & :update ) end end end | parses the body to an object |
10,998 | def jsonifiable @jsonifiable ||= Body . new ( catch ( :jsonifiable ) do original_body = self . body unless original_body . is_a? ( String ) begin JSON . generate ( [ original_body ] ) throw :jsonifiable , original_body rescue throw :jsonifiable , nil end end body = original_body . dup unless body . valid_encoding? body... | deal with the vagaries of getting the response body in a form which JSON gem will not cry about generating |
10,999 | def alter_body_by_content_type ( body , content_type ) return body unless body . is_a? ( String ) content_type_attrs = ApiHammer :: ContentTypeAttrs . new ( content_type ) if @options [ :text ] . nil? ? content_type_attrs . text? : @options [ :text ] if pretty? case content_type_attrs . media_type when 'application/jso... | takes a body and a content type ; returns the body altered according to options . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.