idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
19,200
def decode ( length , type ) if ( @index + length ) > @string . length value = nil else if type == "AT" value = decode_tag else value = @string . slice ( @index , length ) . unpack ( vr_to_str ( type ) ) if value . length == 1 value = value [ 0 ] value . gsub! ( / \000 / , "" ) if value . respond_to? :gsub! end skip ( ...
Creates a Stream instance .
19,201
def encode ( value , type ) value = [ value ] unless value . is_a? ( Array ) return value . pack ( vr_to_str ( type ) ) end
Encodes a value and returns the resulting binary string .
19,202
def parse_row ( line_num , line , header , column_idx , prev_fields , options ) fields = LineParser :: parse ( line , options [ :in_format ] , options [ :split_on ] ) return nil , nil if fields . compact == [ ] if options [ :pad_fields ] and fields . size < header . size fields += [ '' ] * ( header . size - fields . si...
Take a line as a string and return it as a tuple of rowname and datafields
19,203
def nextclean while true c = self . nextchar ( ) if ( c == '/' ) case self . nextchar ( ) when '/' c = self . nextchar ( ) while c != "\n" && c != "\r" && c != "\0" c = self . nextchar ( ) end when '*' while true c = self . nextchar ( ) raise "unclosed comment" if ( c == "\0" ) if ( c == '*' ) break if ( self . nextcha...
Read the next n characters from the string with escape sequence processing .
19,204
def utf8str ( code ) if ( code & ~ ( 0x7f ) ) == 0 return ( code . chr ) end buf = "" if ( code & ~ ( 0x7ff ) ) == 0 buf << ( 0b11000000 | ( code >> 6 ) ) . chr buf << ( 0b10000000 | ( code & 0b00111111 ) ) . chr return ( buf ) end if ( code & ~ ( 0x000ffff ) ) == 0 buf << ( 0b11100000 | ( code >> 12 ) ) . chr buf << (...
Given a Unicode code point return a string giving its UTF - 8 representation based on RFC 2279 .
19,205
def nextto ( regex ) buf = "" while ( true ) c = self . nextchar ( ) if ! ( regex =~ c ) . nil? || c == '\0' || c == '\n' || c == '\r' self . back ( ) if ( c != '\0' ) return ( buf . chomp ( ) ) end buf += c end end
Reads the next group of characters that match a regular expresion .
19,206
def nextvalue c = self . nextclean s = "" case c when / \" \' / return ( self . nextstring ( c ) ) when '{' self . back ( ) return ( Hash . new . from_json ( self ) ) when '[' self . back ( ) return ( Array . new . from_json ( self ) ) else buf = "" while ( ( c =~ / \] \} \/ \0 / ) . nil? ) buf += c c = self . nextchar...
Reads the next value from the string . This can return either a string a FixNum a floating point value a JSON array or a JSON object .
19,207
def complete ( fragment ) self . class . filter ( shell . instance_methods ) . grep Regexp . new ( Regexp . quote ( fragment ) ) end
Provide completion for a given fragment .
19,208
def flavor f @logger . debug "OpenStack: Looking up flavor '#{f}'" @compute_client . flavors . find { | x | x . name == f } || raise ( "Couldn't find flavor: #{f}" ) end
Create a new instance of the OpenStack hypervisor object
19,209
def image i @logger . debug "OpenStack: Looking up image '#{i}'" @compute_client . images . find { | x | x . name == i } || raise ( "Couldn't find image: #{i}" ) end
Provided an image name return the OpenStack id for that image
19,210
def network n @logger . debug "OpenStack: Looking up network '#{n}'" @network_client . networks . find { | x | x . name == n } || raise ( "Couldn't find network: #{n}" ) end
Provided a network name return the OpenStack id for that network
19,211
def security_groups sgs for sg in sgs @logger . debug "Openstack: Looking up security group '#{sg}'" @compute_client . security_groups . find { | x | x . name == sg } || raise ( "Couldn't find security group: #{sg}" ) sgs end end
Provided an array of security groups return that array if all security groups are present
19,212
def provision_storage host , vm volumes = get_volumes ( host ) if ! volumes . empty? volume_client_create volumes . keys . each_with_index do | volume , index | @logger . debug "Creating volume #{volume} for OpenStack host #{host.name}" openstack_size = volumes [ volume ] [ 'size' ] . to_i / 1000 args = { :size => open...
Create and attach dynamic volumes
19,213
def cleanup_storage vm vm . volumes . each do | vol | @logger . debug "Deleting volume #{vol.name} for OpenStack host #{vm.name}" vm . detach_volume ( vol . id ) vol . wait_for { ready? } vol . destroy end end
Detach and delete guest volumes
19,214
def get_ip begin @logger . debug "Creating IP" ip = @compute_client . addresses . create rescue Fog :: Compute :: OpenStack :: NotFound @compute_client . allocate_address ( @options [ :floating_ip_pool ] ) ip = @compute_client . addresses . find { | ip | ip . instance_id . nil? } end raise 'Could not find or allocate a...
Get a floating IP address to associate with the instance try to allocate a new one from the specified pool if none are available
19,215
def provision @logger . notify "Provisioning OpenStack" @hosts . each do | host | ip = get_ip hostname = ip . ip . gsub ( '.' , '-' ) host [ :vmhostname ] = hostname + '.rfc1918.puppetlabs.net' create_or_associate_keypair ( host , hostname ) @logger . debug "Provisioning #{host.name} (#{host[:vmhostname]})" options = {...
Create new instances in OpenStack
19,216
def cleanup @logger . notify "Cleaning up OpenStack" @vms . each do | vm | cleanup_storage ( vm ) if @options [ :openstack_volume_support ] @logger . debug "Release floating IPs for OpenStack host #{vm.name}" floating_ips = vm . all_addresses floating_ips . each do | address | @compute_client . disassociate_address ( v...
Destroy any OpenStack instances
19,217
def create_or_associate_keypair ( host , keyname ) if @options [ :openstack_keyname ] @logger . debug "Adding optional key_name #{@options[:openstack_keyname]} to #{host.name} (#{host[:vmhostname]})" keyname = @options [ :openstack_keyname ] else @logger . debug "Generate a new rsa key" begin retries ||= 0 key = OpenSS...
Get key_name from options or generate a new rsa key and add it to OpenStack keypairs
19,218
def get ( params = { } ) params [ :dt ] = params [ :dt ] . to_date . to_s if params . is_a? Time params [ :meta ] = params [ :meta ] ? 'yes' : 'no' if params . has_key? ( :meta ) options = create_params ( params ) posts = self . class . get ( '/posts/get' , options ) [ 'posts' ] [ 'post' ] posts = [ ] if posts . nil? p...
Returns one or more posts on a single day matching the arguments . If no date or url is given date of most recent bookmark will be used .
19,219
def suggest ( url ) options = create_params ( { url : url } ) suggested = self . class . get ( '/posts/suggest' , options ) [ 'suggested' ] popular = suggested [ 'popular' ] popular = [ ] if popular . nil? popular = [ popular ] if popular . class != Array recommended = suggested [ 'recommended' ] recommended = [ ] if r...
Returns a list of popular tags and recommended tags for a given URL . Popular tags are tags used site - wide for the url ; recommended tags are drawn from the user s own tags .
19,220
def recent ( params = { } ) options = create_params ( params ) posts = self . class . get ( '/posts/recent' , options ) [ 'posts' ] [ 'post' ] posts = [ ] if posts . nil? posts = [ * posts ] posts . map { | p | Post . new ( Util . symbolize_keys ( p ) ) } end
Returns a list of the user s most recent posts filtered by tag .
19,221
def dates ( tag = nil ) params = { } params [ :tag ] = tag if tag options = create_params ( params ) dates = self . class . get ( '/posts/dates' , options ) [ 'dates' ] [ 'date' ] dates = [ ] if dates . nil? dates = [ * dates ] dates . each_with_object ( { } ) { | value , hash | hash [ value [ "date" ] ] = value [ "cou...
Returns a list of dates with the number of posts at each date
19,222
def tags_get ( params = { } ) options = create_params ( params ) tags = self . class . get ( '/tags/get' , options ) [ 'tags' ] [ 'tag' ] tags = [ ] if tags . nil? tags = [ * tags ] tags . map { | p | Tag . new ( Util . symbolize_keys ( p ) ) } end
Returns a full list of the user s tags along with the number of times they were used .
19,223
def tags_rename ( old_tag , new_tag = nil ) params = { } params [ :old ] = old_tag params [ :new ] = new_tag if new_tag options = create_params ( params ) result_code = self . class . get ( '/tags/rename' , options ) . parsed_response [ "result" ] raise Error . new ( result_code ) if result_code != "done" result_code e...
Rename an tag or fold it into an existing tag
19,224
def tags_delete ( tag ) params = { tag : tag } options = create_params ( params ) self . class . get ( '/tags/delete' , options ) nil end
Delete an existing tag
19,225
def notes_list options = create_params ( { } ) notes = self . class . get ( '/notes/list' , options ) [ 'notes' ] [ 'note' ] notes = [ ] if notes . nil? notes = [ * notes ] notes . map { | p | Note . new ( Util . symbolize_keys ( p ) ) } end
Returns a list of the user s notes
19,226
def notes_get ( id ) options = create_params ( { } ) note = self . class . get ( "/notes/#{id}" , options ) [ 'note' ] return nil unless note content = '__content__' Note . new ( { id : note [ 'id' ] , title : note [ content ] . gsub ( / \n / , '' ) , length : note [ 'length' ] [ content ] . to_i , text : note [ 'text'...
Returns an individual user note . The hash property is a 20 character long sha1 hash of the note text .
19,227
def create_params params options = { } options [ :query ] = params if @auth_token options [ :query ] . merge! ( auth_token : @auth_token ) else options [ :basic_auth ] = @auth end options end
Construct params hash for HTTP request
19,228
def memory m = entity_xml . hardware_section . memory allocation_units = m . get_rasd_content ( Xml :: RASD_TYPES [ :ALLOCATION_UNITS ] ) bytes = eval_memory_allocation_units ( allocation_units ) virtual_quantity = m . get_rasd_content ( Xml :: RASD_TYPES [ :VIRTUAL_QUANTITY ] ) . to_i memory_mb = virtual_quantity * by...
returns size of memory in megabytes
19,229
def memory = ( size ) fail ( CloudError , "Invalid vm memory size #{size}MB" ) if size <= 0 Config . logger . info "Changing the vm memory to #{size}MB." payload = entity_xml payload . change_memory ( size ) task = connection . post ( payload . reconfigure_link . href , payload , Xml :: MEDIA_TYPE [ :VM ] ) monitor_tas...
sets size of memory in megabytes
19,230
def vcpu cpus = entity_xml . hardware_section . cpu . get_rasd_content ( Xml :: RASD_TYPES [ :VIRTUAL_QUANTITY ] ) fail CloudError , "Uable to retrieve number of virtual cpus of VM #{name}" if cpus . nil? cpus . to_i end
returns number of virtual cpus of VM
19,231
def vcpu = ( count ) fail ( CloudError , "Invalid virtual CPU count #{count}" ) if count <= 0 Config . logger . info "Changing the virtual CPU count to #{count}." payload = entity_xml payload . change_cpu_count ( count ) task = connection . post ( payload . reconfigure_link . href , payload , Xml :: MEDIA_TYPE [ :VM ] ...
sets number of virtual cpus of VM
19,232
def get_order_dir_for_column ( name ) name = name . to_s current_column = get_order_column return nil unless current_column == name dir = get_order_dir return nil if dir . nil? dir end
return nil if not sorted by this column return order dir if sorted by this column
19,233
def run ( params ) @adapter = ElFinderS3 :: Adapter . new ( @options [ :server ] , @options [ :cache_connector ] ) @root = ElFinderS3 :: Pathname . new ( adapter , @options [ :root ] ) begin @params = params . dup @headers = { } @response = { } @response [ :errorData ] = { } if VALID_COMMANDS . include? ( @params [ :cm...
Runs request - response cycle .
19,234
def add_handler ( app_id , opts = { } , & blk ) vendor = opts . fetch ( :vendor , 0 ) auth = opts . fetch ( :auth , false ) acct = opts . fetch ( :acct , false ) raise ArgumentError . new ( "Must specify at least one of auth or acct" ) unless auth or acct @acct_apps << [ app_id , vendor ] if acct @auth_apps << [ app_id...
Adds a handler for a specific Diameter application .
19,235
def connect_to_peer ( peer_uri , peer_host , realm ) peer = Peer . new ( peer_host , realm ) @peer_table [ peer_host ] = peer @peer_table [ peer_host ] . state = :WAITING uri = URI ( peer_uri ) cxn = @tcp_helper . setup_new_connection ( uri . host , uri . port ) @peer_table [ peer_host ] . cxn = cxn avps = [ AVP . crea...
Creates a Peer connection to a Diameter agent at the specific network location indicated by peer_uri .
19,236
def to_request credit = { delayed : self . delayed , authenticated : self . authenticated , pre_authorization : self . pre_authorization , save_card_data : self . save_card_data , transaction_type : self . transaction_type , number_installments : self . number_installments . to_i , soft_descriptor : self . soft_descrip...
Nova instancia da classe Credit
19,237
def stores return self . _stores if not self . _stores . empty? response = api_get ( "Stores.egg" ) stores = JSON . parse ( response . body ) stores . each do | store | self . _stores << Newegg :: Store . new ( store [ 'Title' ] , store [ 'StoreDepa' ] , store [ 'StoreID' ] , store [ 'ShowSeeAllDeals' ] ) end self . _s...
retrieve and populate a list of available stores
19,238
def categories ( store_id ) return [ ] if store_id . nil? response = api_get ( "Stores.egg" , "Categories" , store_id ) categories = JSON . parse ( response . body ) categories = categories . collect do | category | Newegg :: Category . new ( category [ 'Description' ] , category [ 'CategoryType' ] , category [ 'Catego...
retrieve and populate list of categories for a given store_id
19,239
def store_content ( store_id , category_id = - 1 , node_id = - 1 , store_type = 4 , page_number = 1 ) params = { 'storeId' => store_id , 'categoryId' => category_id , 'nodeId' => node_id , 'storeType' => store_type , 'pageNumber' => page_number } JSON . parse ( api_get ( 'Stores.egg' , 'Content' , nil , params ) . body...
retrieves store content
19,240
def search ( options = { } ) options = { store_id : - 1 , category_id : - 1 , sub_category_id : - 1 , node_id : - 1 , page_number : 1 , sort : "FEATURED" , keywords : "" } . merge ( options ) request = { 'IsUPCCodeSearch' => false , 'IsSubCategorySearch' => options [ :sub_category_id ] > 0 , 'isGuideAdvanceSearch' => f...
retrieves a single page of products given a query specified by an options hash . See options below . node_id page_number and an optional sorting method
19,241
def combo_deals ( item_number , options = { } ) options = { sub_category : - 1 , sort_field : 0 , page_number : 1 } . merge ( options ) params = { 'SubCategory' => options [ :sub_category ] , 'SortField' => options [ :sort_field ] , 'PageNumber' => options [ :page_number ] } JSON . parse ( api_get ( 'Products.egg' , it...
retrieve product combo deals given an item number
19,242
def reviews ( item_number , page_number = 1 , options = { } ) options = { time : 'all' , rating : 'All' , sort : 'date posted' } . merge ( options ) params = { 'filter.time' => options [ :time ] , 'filter.rating' => options [ :rating ] , 'sort' => options [ :sort ] } JSON . parse ( api_get ( 'Products.egg' , item_numbe...
retrieve product reviews given an item number
19,243
def current_mode_string n = room . membership_limit s = room . open_to_guests? ? "" : "s" i = room . locked? ? "i" : "" "+#{i}l#{s}" end
Returns the current mode string
19,244
def user_for_message ( message ) if user = users [ message . user_id ] yield message , user else message . user do | user | yield message , user end end end
Retrieve the user from a message either by finding it in the current list of known users or by asking campfire for the user .
19,245
def around * matchers , & proc proc || raise ( ArgumentError , 'block is missing' ) matchers . flatten! matchers = [ :* ] if matchers . empty? return if around? . find { | x | x [ 0 ] == matchers && x [ 1 ] . source_location == proc . source_location } around? . push ( [ matchers , proc ] ) end
a block to wrap each test evaluation
19,246
def statistics extracted_statistics = [ ] unless self . qp_statistics . nil? extracted_statistics . push ( EmailListStatistic . new ( qp_statistics ) ) end return extracted_statistics end
Extract the email list statistics from qp_statistics attribute .
19,247
def capture_command cmd = "#{@cutycapt_path} --url='#{@url}'" cmd += " --out='#{@folder}/#{@filename}'" cmd += " --max-wait=#{@max_wait}" cmd += " --delay=#{@delay}" if @delay cmd += " --user-agent='#{@user_agent}'" cmd += " --min-width='#{@min_width}'" cmd += " --min-height='#{@min_height}'" if determine_os == :linux ...
Produces the command used to run CutyCapt .
19,248
def parse_config ( data ) config = { 'graph' => { } , 'metrics' => { } } data . each do | l | if l =~ / / key_name , value = l . scan ( / \w \s / ) . flatten config [ 'graph' ] [ key_name ] = value elsif l =~ / \d \. / matches = l . scan ( / \d \. \s / ) . flatten config [ 'metrics' ] [ matches [ 0 ] ] ||= { } config [...
Parse config request
19,249
def parse_error ( lines ) if lines . size == 1 case lines . first when '# Unknown service' then raise UnknownService when '# Bad exit' then raise BadExit end end end
Detect error from output
19,250
def parse_config_args ( args ) result = { } args . scan ( / \- \_ \s \d \s / ) . each do | arg | result [ arg . first ] = arg . last end { 'raw' => args , 'parsed' => result } end
Parse configuration arguments
19,251
def register ( token , email , granted_to_email , access_count , expire ) save_config ( token , { email : email , granted_to_email : granted_to_email , access_count : access_count } ) @redis . expire ( token , expire ) token end
register one time token for given user in redis the generated token will have a field email in order to identify the associated user later
19,252
def access ( token , email ) config = load_config ( token ) return false unless config return false unless config [ :email ] . to_s == email . to_s return false unless config [ :access_count ] > 0 save_config ( token , config . merge ( access_count : config [ :access_count ] - 1 ) ) true end
accesses token for given email if it is allowed
19,253
def wgs84_to_google ActiveSupport :: Deprecation . warn "use Point geometry which supports srid" self . class . from_pro4j Proj4 :: Projection . wgs84 . transform Proj4 :: Projection . google , self . proj4_point ( Math :: PI / 180 ) . x , self . proj4_point ( Math :: PI / 180 ) . y end
DEPRECATED Use Point geometry which supports srid
19,254
def print return unless $stdout . tty? return if recently_fetched? resp = fetch_server_message update_fetched puts resp unless resp . empty? end
Checks if the server has a message and prints it if not empty . We will only check this once a day and won t print anything if the quiet option is set or if we output to a file .
19,255
def render content_tag ( :ul ) do html = "\n" if show_first_page? html += content_tag ( :li , :class => "first_page" ) do link_to_page collection . first_page , 'paginate.first_page_label' end html += "\n" end if show_previous_page? html += content_tag ( :li , :class => "previous_page" ) do link_to_page collection . pr...
render html for pagination
19,256
def namespace ( namespace = nil , options = { } ) return @namespace unless namespace @namespace = namespace . to_sym if namespace @base_namespace = options [ :base ] . to_sym if options [ :base ] end
Sets and returns + namespace + . If called without parameters returns + namespace + .
19,257
def source ( source = nil , options = { } ) return @source unless source @source = source @parser = options [ :parser ] @type = options [ :type ] @type ||= source . is_a? ( Hash ) ? :hash : File . extname ( @source ) [ 1 .. - 1 ] . to_sym end
Sets + source + for the configuration If called without parameters returns + source + .
19,258
def settings ( & block ) @settings ||= setup settings = instance_variable_defined? ( :@namespace ) ? @settings . get_value ( @namespace ) : @settings if block_given? block . arity == 0 ? settings . instance_eval ( & block ) : block . call ( settings ) end settings end
Loaded configuration stored in Settings class . Accepts + block + as parameter .
19,259
def setup return Squire :: Settings . new unless @source parser = Squire :: Parser . of ( @type ) hash = parser . parse ( source ) . with_indifferent_access if base_namespace hash . except ( base_namespace ) . each do | key , values | hash [ key ] = hash [ base_namespace ] . deep_merge ( values ) { | _ , default , valu...
Sets up the configuration based on + namespace + and + source + . If + base_namespace + provided merges it s values with other namespaces for handling nested overriding of values .
19,260
def count_range ( hash_a , hash_b , cmd_options = { } ) hg_to_array ( [ %Q[log -r ?:? --template "{node}\n"] , hash_a , hash_b ] , { } , cmd_options ) do | line | line end . size end
Count changesets in the range from hash_a to hash_b in the repository .
19,261
def create_link data body = http_get URL_API , { key : @key , uid : @uid } . merge ( data ) raise ArgumentError if body . nil? || body . empty? body end
Create instance to use API adfly
19,262
def field ( name , * params ) @model . translated_attribute_names . push name . to_sym @model . translated_attr_accessor ( name ) @model . translation_class . field name , * params end
Initializes new istance of FieldsBuilder . Param Class Creates new field in translation document . Param String or Symbol Other params are the same as for Mongoid s + field +
19,263
def report ( coverage_path , sticky : true ) if File . exist? coverage_path coverage_json = JSON . parse ( File . read ( coverage_path ) , symbolize_names : true ) metrics = coverage_json [ :metrics ] percentage = metrics [ :covered_percent ] lines = metrics [ :covered_lines ] total_lines = metrics [ :total_lines ] for...
Parse a JSON code coverage file and report that information as a message in Danger .
19,264
def individual_coverage_message ( covered_files ) require 'terminal-table' message = "### Code Coverage\n\n" table = Terminal :: Table . new ( headings : %w( File Coverage ) , style : { border_i : '|' } , rows : covered_files . map do | file | [ file [ :filename ] , "#{format('%.02f', file[:covered_percent])}%" ] end )...
Builds the markdown table displaying coverage on individual files
19,265
def validate_args if name_args . size < 1 ui . error ( 'No cookbook has been specified' ) show_usage exit 1 end if name_args . size > 2 ui . error ( 'Too many arguments are being passed. Please verify.' ) show_usage exit 1 end end
Ensure argumanets are valid assign values of arguments
19,266
def validate_repo_clean @gitrepo = Grit :: Repo . new ( @repo_root ) status = @gitrepo . status if ! status . changed . nil? || status . changed . size != 0 status . changed . each do | file | case file [ 1 ] . sha_index when '0' * 40 ui . error 'There seem to be unstaged changes in your repo. Either stash or add them....
Inspect the cookbook directory s git status is good to push . Any existing tracked files should be staged otherwise error & exit . Untracked files are warned about but will allow continue . This needs more testing .
19,267
def validate_no_existing_tag ( tag_string ) existing_tags = [ ] @gitrepo . tags . each { | tag | existing_tags << tag . name } if existing_tags . include? ( tag_string ) ui . error 'This version tag has already been committed to the repo.' ui . error "Are you sure you haven't released this already?" exit 6 end end
Ensure that there isn t already a git tag for this version .
19,268
def validate_target_remote_branch remote_path = File . join ( config [ :remote ] , config [ :branch ] ) remotes = [ ] @gitrepo . remotes . each { | remote | remotes << remote . name } unless remotes . include? ( remote_path ) ui . error 'The remote/branch specified does not seem to exist.' exit 7 end end
Ensure that the remote and branch are indeed valid . We provide defaults in options .
19,269
def nodes nodes = [ ] cache 'nodes' do connection . send_data ( "nodes" ) while ( ( line = connection . read_line ) != "." ) nodes << line end nodes end end
Get a list of all available nodes
19,270
def list ( node = "" ) cache "list_#{node.empty? ? 'default' : node}" do connection . send_data ( "list #{node}" ) if ( line = connection . read_line ) != "." line . split else connection . read_line . split end end end
Get a list of all available metrics
19,271
def config ( services , raw = false ) unless [ String , Array ] . include? ( services . class ) raise ArgumentError , "Service(s) argument required" end results = { } names = [ services ] . flatten . uniq if names . empty? raise ArgumentError , "Service(s) argument required" end key = 'config_' + Digest :: MD5 . hexdig...
Get a configuration information for service
19,272
def fetch ( services ) unless [ String , Array ] . include? ( services . class ) raise ArgumentError , "Service(s) argument required" end results = { } names = [ services ] . flatten if names . empty? raise ArgumentError , "Service(s) argument required" end names . each do | service | begin connection . send_data ( "fe...
Get all service metrics values
19,273
def get_value ( key , & block ) key = key . to_sym value = @table [ key ] if block_given? block . arity == 0 ? value . instance_eval ( & block ) : block . call ( value ) end value end
Returns a value for + key + from settings table . Yields + value + of + key + if + block + provided .
19,274
def to_hash result = :: Hash . new @table . each do | key , value | if value . is_a? Settings value = value . to_hash end result [ key ] = value end result end
Dumps settings as hash .
19,275
def choices extracted_choices = [ ] unless self . qp_answers . nil? self . qp_answers . each do | choice | extracted_choices . push ( Choice . new ( choice ) ) end end return extracted_choices end
Extract the choices from the hashes stored inside qp_answers attribute .
19,276
def filter ids : nil , tags : nil , dom : nil id_s = tag_s = dom_s = "" id_s = process_ids ( ids ) unless ids . nil? tag_s = process_tags ( tags ) unless tags . nil? dom_s = process_dom ( dom ) unless dom . nil? return "#{id_s} #{tag_s} #{dom_s}" . strip end
Converts ids tags and dom queries to a single string ready to pass directly to task .
19,277
def process_ids ids case ids when Range return id_range_to_s ( ids ) when Array return id_a_to_s ( ids ) when String return ids . delete ( " " ) when Fixnum return ids end end
Converts arbitrary id input to a task safe string
19,278
def process_tags tags case tags when String tags . split ( " " ) . map { | t | process_tag t } . join ( " " ) when Array tags . map { | t | process_tags t } . join ( " " ) end end
Convert a tag string or an array of strings to a space separated string
19,279
def json? value begin return false unless value . is_a? String MultiJson . load ( value ) true rescue MultiJson :: ParseError false end end
Can the input be coerced to a JSON object without losing information?
19,280
def cast_value ( parent , value ) raise "An array inside an array cannot be casted, use CastedModel" if value . is_a? ( Array ) value = typecast_value ( value , self ) associate_casted_value_to_parent ( parent , value ) end
Cast an individual value not an array
19,281
def type_class return String unless casted return @type_class unless @type_class . nil? base = @type . is_a? ( Array ) ? @type . first : @type base = String if base . nil? base = TrueClass if base . is_a? ( String ) && base . downcase == 'boolean' @type_class = base . is_a? ( Class ) ? base : base . constantize end
Always provide the basic type as a class . If the type is an array the class will be extracted .
19,282
def fasta_iterator ( first_line , next_lines ) current_fasta_header = first_line . chomp next_lines . each_slice ( batch_size ) . with_index do | slice , i | fasta_mapper = [ ] input_set = Set . new slice . each do | line | line . chomp! if fasta? line current_fasta_header = line else fasta_mapper << [ current_fasta_he...
Splits the input lines in fasta format into slices based on the batch_size of the current command . Executes the given block for each of the batches .
19,283
def properties convert_map_to_hash ( @device . getProperties ) do | hash , key , value | hash [ key . toString ] = value . toString end end
Returns the device properties . It contains the whole output of getprop
19,284
def shell ( command , & block ) capture = CommandCapture . new ( block_given? ? block : nil ) receiver = Rjb :: bind ( capture , 'com.android.ddmlib.IShellOutputReceiver' ) @device . executeShellCommand ( command . to_s , receiver ) block_given? ? self : capture . to_s end
Executes a shell command on the device and receives the result .
19,285
def push ( localfile , remotefile ) raise ArgumentError , "Not found #{localfile}" unless File . exist? ( localfile ) if remotefile . end_with? ( '/' ) remotefile = "#{remotefile}#{File.basename(localfile)}" end @device . pushFile ( localfile , remotefile ) self end
Pushes a file to the device .
19,286
def pull ( remotefile , localfile ) if localfile . end_with? ( '/' ) || File . directory? ( localfile ) localdir = localfile . chomp ( '/' ) localfilename = nil else localdir = File . dirname ( localfile ) localfilename = File . basename ( localfile ) end unless File . exist? ( localdir ) FileUtils . mkdir_p ( localdir...
Pulls a file from the device .
19,287
def raster_work parents . select do | parent | parent . class . included_modules . include? ( :: GeoWorks :: RasterWorkBehavior ) end . to_a end
Retrieve the Raster Work of which this Object is a member
19,288
def pixel ( x , y ) Pixel . new ( x , y , @image . getARGB ( point_to_index ( x , y ) ) ) end
Returns pixel content
19,289
def each_pixel ( ) return to_enum :each_pixel unless block_given? @image . height . times do | y | @image . width . times do | x | yield pixel ( x , y ) end end self end
Calls block once for each pixel in data passing that device as a parameter . If no block is given an enumerator is returned instead .
19,290
def options { id : self . survey_id , surveyID : self . survey_id , responseID : self . response_id , resultMode : self . result_mode , startDate : self . start_date , userID : self . user_id , endDate : self . end_date , startingResponseCounter : self . starting_response_counter , emailGroupID : self . email_group_id ...
Transform the object to the acceptable json format by questionpro .
19,291
def list_surveys url = ApiRequest . base_path ( "questionpro.survey.getAllSurveys" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] surveys = [ ] result_surveys = result [ 'response' ] [ 'surveys' ] result_surveys . each do | survey | survey...
Get all the surveys that belongs to the api key s owner .
19,292
def get_survey url = ApiRequest . base_path ( "questionpro.survey.getSurvey" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] survey = Survey . new ( result [ 'response' ] ) return survey end
Get a specific survey . Survey ID must be set inside the api request object .
19,293
def get_survey_responses url = ApiRequest . base_path ( "questionpro.survey.surveyResponses" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] survey_responses = [ ] result_responses = result [ 'response' ] [ 'responses' ] result_responses . ...
Get list of survey Responses . Survey ID must be set inside the api request object .
19,294
def get_survey_reponse url = ApiRequest . base_path ( "questionpro.survey.surveyResponse" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] response = SurveyResponse . new ( result [ 'response' ] [ 'surveyResponse' ] ) return response end
Get a specific survey Response . Survey ID must be set inside the api request object . Response ID must be set inside the api request object .
19,295
def get_survey_response_count url = ApiRequest . base_path ( "questionpro.survey.responseCount" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] response_count = SurveyResponseCount . new ( result [ 'response' ] ) return response_count end
Get a specific survey Response Statistics . Survey ID must be set inside the api request object .
19,296
def delete_response url = ApiRequest . base_path ( "questionpro.survey.deleteResponse" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] self . success = result [ 'response' ] [ 'success' ] return self end
Delete a specific survey response . Survey ID must be set inside the api request object . Response ID must be set inside the api request object .
19,297
def get_email_lists url = ApiRequest . base_path ( "questionpro.survey.getEmailLists" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] email_lists = [ ] result_email_lists = result [ 'response' ] [ 'emailLists' ] result_email_lists . each do...
Get Email Lists related to a specific survey . Survey ID must be set inside the api request object .
19,298
def get_email_list url = ApiRequest . base_path ( "questionpro.survey.getEmailList" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] email_list = EmailList . new ( result [ 'response' ] [ 'emailList' ] ) return email_list end
Get Specific Email List . Email Group ID must be set inside the api request object .
19,299
def get_email_templates url = ApiRequest . base_path ( "questionpro.survey.getEmailTemplates" ) result = self . class . get ( url , body : self . options ) self . full_response = result self . status = result [ 'status' ] email_templates = [ ] result_email_templates = result [ 'response' ] [ 'emailTemplates' ] result_e...
Get Templates related to a specific survey . Survey ID must be set inside the api request object .