idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
17,600 | def filter ( parent , indent ) return unless ( filter_name = accept :filter ) atts = attributes ( shorthand_attributes ) || { } error :fiter unless accept ( :line_feed ) . strip . empty? parent [ @children ] << [ :filter , filter_name [ 1 .. - 1 ] . to_sym , atts , get_indented_lines ( indent ) , indent ] end | Check if we match an compile time filter |
17,601 | def plain ( node , indent ) value = node [ @options ] [ :value ] if @settings [ :pretty ] indentation = ' ' * indent inline = @sibling_stack [ - 1 ] [ - 1 ] && @sibling_stack [ - 1 ] [ - 1 ] [ 0 ] == :node && Settings :: INLINE_NODE . include? ( @sibling_stack [ - 1 ] [ - 1 ] [ 1 ] ) @sibling_stack [ - 1 ] << [ node [ ... | Generate the code for a standard text node |
17,602 | def include_file ( _parent , indent ) return unless accept :include name = accept :line_feed || '' name . strip! Logger . error :parse , @code , @i , @j , :include_end if name . empty? include_path = File . expand_path name , File . dirname ( @file [ - 1 ] [ 0 ] ) include_path += Settings :: FILE_EXTENSION if File . ex... | Check if we have an include node which will include a new file inside of the current one to be parsed |
17,603 | def parse_timestamps @created_time = created_time . to_i if created_time . is_a? String @created_time = Time . at ( created_time ) if created_time end | Parses UNIX timestamps and creates Time objects . |
17,604 | def node ( node , indent ) if @settings [ :pretty ] indentation = ' ' * indent inline = Settings :: INLINE_NODE . include? node [ @value ] indentate = proc do if @in_definition buffer "' ' * (indent + #{indent})" else buffer_freeze indentation end end if inline inline_last_sibling = @sibling_stack [ - 1 ] [ - 1 ] ? Set... | Generate the code for a standard node element with closing tags or self enclosing elements |
17,605 | def _flex_columns_before_save! self . class . _all_flex_column_names . each do | flex_column_name | klass = self . class . _flex_column_class_for ( flex_column_name ) if klass . requires_serialization_on_save? ( self ) _flex_column_object_for ( flex_column_name ) . before_save! end end end | Before we save this model make sure each flex column has a chance to serialize itself up and assign itself properly to this model object . Note that we only need to call through to flex - column objects that have actually been instantiated since by definition there s no way the contents of any other flex columns could ... |
17,606 | def _flex_column_owned_object_for ( column_name , create_if_needed = true ) column_name = self . class . _flex_column_normalize_name ( column_name ) out = _flex_column_objects [ column_name ] if ( ! out ) && create_if_needed out = _flex_column_objects [ column_name ] = self . class . _flex_column_class_for ( column_nam... | Returns the correct flex - column object for the given column name . This simply creates an instance of the appropriate flex - column class and saves it away so it will be returned again if someone requests the object for the same column later . |
17,607 | def define ( parent , indent ) return unless accept ( :def ) Logger . error :parse , @code , @i , @j , :definition if parent [ @type ] != :root name = accept ( :node , :* ) . to_sym definition = [ :def , name , { parameters : attributes ( { } , true ) } , [ ] , indent ] root definition , indent @definitions [ name ] = ... | Check if we match a new node definition to use within our page . |
17,608 | def encode_env ( env ) env = env . dup env . keep_if { | k , v | k =~ / / } env . to_yaml ( :Encoding => :Utf8 ) end | Convert the environment hash to yaml so it can be unserialized later |
17,609 | def webpack_asset_paths ( source , extension : nil ) return "" unless source . present? paths = Repack :: Manifest . asset_paths ( source ) paths = paths . select { | p | p . ends_with? ".#{extension}" } if extension host = :: Rails . configuration . repack . dev_server . host port = :: Rails . configuration . repack .... | Return asset paths for a particular webpack entry point . |
17,610 | def has_source? ( source , segment , cookbook = nil ) cookbook ||= cookbook_name begin run_context . cookbook_collection [ cookbook ] . send ( :find_preferred_manifest_record , run_context . node , segment , source ) rescue Chef :: Exceptions :: FileNotFound nil end end | Checks for existence of a cookbook file or template source in a cookbook . |
17,611 | def process_events while ( event = @_actable . mailbox . obtain_and_shift ) event_handler ( event ) end rescue Exception => exception cleanup_handler ( exception ) exception_handler ( exception ) ensure @_actable . mailbox . release do process_events end nil end | All system commands are prefixed with an underscore . |
17,612 | def evaluate ( code , & block ) begin eval code , @binding , & block rescue NameError => variable Compiler . error :binding , variable , code end end | Create a context from the environment binding extended with the locals given as arguments |
17,613 | def extend_locals ( locals ) locals . each do | key , value | begin @binding . local_variable_set key . to_sym , value rescue NameError => variable Compiler . error :variable_name , variable , key end end end | Extend the call context with a Hash String or other Object |
17,614 | def extend_nonlocals ( bind ) bind . eval ( 'instance_variables' ) . each do | var | @binding . eval ( 'self' ) . instance_variable_set var , bind . eval ( var . to_s ) end bind . eval ( 'self.class.class_variables' ) . each do | var | @binding . eval ( 'self' ) . class_variable_set var , bind . eval ( var . to_s ) end... | Extend instance class and global variables for use in definitions |
17,615 | def attributes ( * fields_name , ** options , & block ) if options . include? :except @fields = resolve_model_reflections . reject do | field | options [ :except ] . include? field . to_sym end elsif options . include? :append @fields += options [ :append ] else @fields = fields_name . map ( & :to_s ) unless fields_nam... | Allow user to specify an array of model attributes to be used in respected section . For example attributes to show as header columns in index section |
17,616 | def fetch_index_objects scope = index_properties . default_scope puts "<<<<<<<" * 100 , scope if ! scope . nil? if scope . respond_to? :call scope = scope . call else scope = self . send ( scope ) end else scope = model . all end scope = scope . order ( 'created_at DESC' ) . page ( params [ :page ] ) policy_scope ( sco... | Fetch all or part of the corresponding resource from data base with respect to scope DSL . |
17,617 | def matches? ( instance ) self . instance = instance fields . each { | field | instance . send ( "#{field}=" , invalid_value ) } instance . send ( sanitizer ) rescue nil fields . all? { | field | valid_value == instance . send ( field ) } end | Actual match code |
17,618 | def control ( parent , indent ) return unless ( structure = accept ( :control ) ) structure = structure . to_sym condition = accept ( :line_feed ) . strip if structure == :each unless condition . match Tokens [ :each_pattern ] Logger . error :parse , @code , @i , @j , :each_arguments end condition = [ Regexp . last_mat... | Match an if - else control structure |
17,619 | def delay! ( uri ) delay = delay ( uri ) sleep delay - ( Time . now - @last_accessed ) if delay @last_accessed = Time . now end | Sleep for the amount of time necessary to obey the Crawl - Delay specified by the server |
17,620 | def get_url ( route_name , id = nil , engine = Rails . application ) return route_name . call if id . nil? return route_name . call ( id ) unless id . nil? end | Translate route name to url dynamically |
17,621 | def authenticate! if u = user_class . send ( config [ :authenticate_method ] , * required_param_values ) success! ( u ) else fail! ( config [ :error_message ] ) end end | The workhorse . Will pass all requred_param_values to the configured authenticate_method |
17,622 | def create! super do raise 'can not create without a domain' if invalid_domain? raise 'can not create wihtout a charge account' if invalid_charge_account? Invoice . post_charge_accounts_invoices ( domain , charge_account , attributes ) end reload_attributes! ( Helpers . extract_uuid ( last_response . headers [ :locatio... | Creates current invoice at API . |
17,623 | def payments reset_errors! response = Http . get ( "/invoices/#{uuid}/payments/" , domain . token ) return [ ] if response . code != 200 MultiJson . decode ( response . body ) end | List all payments for an invoice |
17,624 | def billet_url return if unpersisted? response = Http . get ( "/invoices/#{uuid}/billet/" , domain . token ) return if response . code != 200 MultiJson . decode ( response . body ) [ "billet" ] rescue nil end | Returns a String with the temporary URL for print current invoice . |
17,625 | def participants ( resource_id ) http . get ( participants_endpoint ( resource_id ) ) do | response | Rexpense :: Entities :: UserCollection . build response end end | Get resource participants tags |
17,626 | def update_attribute! ( attribute , value , should_reload_attributes = true ) execute_and_capture_raises_at_errors ( 204 ) do @last_response = Http . patch ( "/charge-accounts/#{uuid}/" , domain . token , etag , attribute => value ) end reload_attributes! if should_reload_attributes end | Update an attribute on charge account at API . |
17,627 | def memberships ( organization_id ) http . get ( membership_endpoint ( organization_id ) ) do | response | Rexpense :: Entities :: MembershipCollection . build response end end | Get organization memberships |
17,628 | def create_membership ( organization_id , params ) http . post ( membership_endpoint ( organization_id ) , body : params ) do | response | response . parsed_body end end | Create organization membership |
17,629 | def update_membership ( organization_id , membership_id , params ) http . put ( "#{membership_endpoint(organization_id)}/#{membership_id}" , body : params ) do | response | Rexpense :: Entities :: Membership . new response . parsed_body end end | Update organization membership |
17,630 | def attachments ( resource_id ) http . get ( attachment_endpoint ( resource_id ) ) do | response | Rexpense :: Entities :: AttachmentCollection . build response end end | Get resource attachments |
17,631 | def find_attachment ( resource_id , attachment_id ) http . get ( "#{attachment_endpoint(resource_id)}/#{attachment_id}" ) do | response | Rexpense :: Entities :: Attachment . new response . parsed_body end end | Get resource attachment |
17,632 | def comments ( resource_id ) http . get ( comment_endpoint ( resource_id ) ) do | response | Rexpense :: Entities :: CommentCollection . build response end end | Get resource comments |
17,633 | def find_comment ( resource_id , comment_id ) http . get ( "#{comment_endpoint(resource_id)}/#{comment_id}" ) do | response | Rexpense :: Entities :: Comment . new response . parsed_body end end | Get resource comment |
17,634 | def create_comment ( resource_id , params ) http . post ( comment_endpoint ( resource_id ) , body : params ) do | response | Rexpense :: Entities :: Comment . new response . parsed_body end end | Create resource comment |
17,635 | def update_comment ( resource_id , comment_id , params ) http . put ( "#{comment_endpoint(resource_id)}/#{comment_id}" , body : params ) do | response | Rexpense :: Entities :: Comment . new response . parsed_body end end | Update resource comment |
17,636 | def sync_auth_info ( options = { } ) opts = { "RunSynchAutoInfo" => 'True' , "EmailEPP" => 'True' } opts [ "EmailEPP" ] = 'True' if options [ :email ] Client . request ( { "Command" => "SynchAuthInfo" , "SLD" => sld , "TLD" => tld } . merge ( opts ) ) return self end | synchronize EPP key with Registry and optionally email it to owner |
17,637 | def get_extended_domain_attributes sld , tld = name . split ( "." ) attributes = Client . request ( "Command" => "GetDomainInfo" , "SLD" => sld , "TLD" => tld ) [ "interface_response" ] [ "GetDomainInfo" ] set_extended_domain_attributes ( attributes ) end | Make another API call to get all domain info . Often necessary when domains are found using Domain . all instead of Domain . find . |
17,638 | def restore restore_class = self . revisionable_type . constantize sti_type = self . revision_attributes [ restore_class . inheritance_column ] if sti_type begin if ! restore_class . store_full_sti_class && ! sti_type . start_with? ( "::" ) sti_type = "#{restore_class.parent.name}::#{sti_type}" end restore_class = sti_... | Restore the revision to the original record . If any errors are encountered restoring attributes they will be added to the errors object of the restored record . |
17,639 | def restore_record ( record , attributes ) primary_key = record . class . primary_key primary_key = [ primary_key ] . compact unless primary_key . is_a? ( Array ) primary_key . each do | key | record . send ( "#{key.to_s}=" , attributes [ key . to_s ] ) end attrs , association_attrs = attributes_and_associations ( reco... | Restore a record and all its associations . |
17,640 | def parse! unless raw . has_key? ( :sales_orders ) raw [ :sales_orders ] = { } end orders = raw [ :sales_orders ] . fetch ( :sales_order_summary , { } ) unless orders . kind_of? ( Array ) raw [ :sales_orders ] [ :sales_order_summary ] = [ orders ] end if raw . has_key? ( :count_more_sales_orders_available ) convert_to_... | Standardizes the XML response by converting fields to integers and forcing the order summaries into an array . |
17,641 | def call ( operation , locals = { } ) locals [ 'Security' ] = ShipCompliant . configuration . credentials response = savon_call ( operation , message : { 'Request' => locals } ) get_result_from_response ( operation , response ) end | Adds the required security credentials and formats the message to match the ShipCompliant structure . |
17,642 | def confirm_message cluster = Cluster . new case self . type when 'Elasticrawl::ParseJob' message = segment_list else message = [ ] end message . push ( 'Job configuration' ) message . push ( self . job_desc ) message . push ( '' ) message . push ( cluster . cluster_desc ) message . join ( "\n" ) end | Displays a confirmation message showing the configuration of the Elastic MapReduce job flow and cluster . |
17,643 | def run_job_flow ( emr_config ) cluster = Cluster . new job_flow = cluster . create_job_flow ( self , emr_config ) job_steps . each do | step | job_flow . add_step ( step . job_flow_step ( job_config ) ) end begin job_flow . run rescue StandardError => e raise ElasticMapReduceAccessError , e . message end end | Calls the Elastic MapReduce API to create a Job Flow . Returns the Job Flow ID . |
17,644 | def draw ( svg , coords , options = { } ) options . merge! ( @options ) if options [ :shadow ] svg . g ( :class => 'shadow' , :transform => "translate(#{relative(0.5)}, #{relative(0.5)})" ) { coords . each { | coord | svg . circle ( :cx => coord . first , :cy => coord . last + relative ( 0.9 ) , :r => relative ( 2 ) , ... | Renders scatter graph . |
17,645 | def draw ( svg , coords , options = { } ) points_value = "0,#{height} #{stringify_coords(coords).join(' ')} #{width},#{height}" svg . g ( :transform => "translate(0, -#{relative(2)})" ) { svg . polygon ( :points => points_value , :style => "fill: black; stroke: black; fill-opacity: 0.06; stroke-opacity: 0.06;" ) } svg ... | Render area graph . |
17,646 | def create params . require ( :user ) . permit! user = User . new ( params [ :user ] ) if user . valid? user . save flash . now [ :success ] = t ( 'landing_page.subscribed' ) render :create else @user = user render :new end end | Register a new user or show errors |
17,647 | def build_environment_hash parsed_variables = { } @env . each do | env_row | variables = extract_variables ( env_row ) variables . each do | variables_with_values | variables_with_values . each do | key , value | parsed_variables [ key ] = value end end end @override_envs . each do | env | parsed_variables = parsed_var... | Build the environment hash by extracting the environment variables from the provided travis environment and merging with any provided overrides |
17,648 | def extract_variables ( variable ) return [ variable ] if variable . is_a? Hash return extract_variables_from_string ( variable ) if variable . is_a? String [ ] end | Extract environment variables from a value The value is expected to be either a hash or a string with one or more key value pairs on the form KEY = VALUE |
17,649 | def extract_variables_from_string ( string ) string . split ( / / ) . map do | defintion | match = defintion . match STRING_REG_EX next nil unless match { match [ 1 ] => match [ 2 ] } end . reject ( & :nil? ) end | Extract variables from a string on the form KEY1 = VALUE1 KEY2 = VALUE2 Optional quoting around the value is allowed |
17,650 | def _monkey_patch_old_chef! require 'chef/event_dispatch/dispatcher' instance = self orig_method = Chef :: EventDispatch :: Dispatcher . instance_method ( :library_file_loaded ) Chef :: EventDispatch :: Dispatcher . send ( :define_method , :library_file_loaded ) do | filename | instance . events = self instance . monke... | Inject this instance for Chef < 12 . 3 . Don t call this on newer Chef . |
17,651 | def rescue_http_error ( exception ) body = self . render_http_error ( exception ) [ exception . status , exception . headers , body ] end | redefine this method for your controller if you want to provide custom error pages returns response array for rack if you need to change just body of error message define render_http_error method |
17,652 | def _build_clusters ( tile ) used_ids = [ ] clusters = [ ] _adapter . in_tile ( * tile . children ) . find_each do | child | cluster = _adapter . build_from ( tile . depth , child ) clusters << cluster used_ids << child . id end return [ used_ids , clusters ] end | return the record IDs used |
17,653 | def restore_revision ( id , revision_number ) revision_record = revision ( id , revision_number ) return revision_record . restore if revision_record end | Load a revision for a record with a particular id . Associations added since the revision was created will still be in the restored record . If you want to save a revision with associations properly use restore_revision! |
17,654 | def restore_revision! ( id , revision_number ) record = restore_revision ( id , revision_number ) if record record . store_revision do save_restorable_associations ( record , revisionable_associations ) end end return record end | Load a revision for a record with a particular id and save it to the database . You should always use this method to save a revision if it has associations . |
17,655 | def restore_last_revision! ( id ) record = restore_last_revision ( id ) if record record . store_revision do save_restorable_associations ( record , revisionable_associations ) end end return record end | Load the last revision for a record with the specified id and save it to the database . You should always use this method to save a revision if it has associations . |
17,656 | def revisionable_associations ( options = acts_as_revisionable_options [ :associations ] ) return nil unless options options = [ options ] unless options . kind_of? ( Array ) associations = { } options . each do | association | if association . kind_of? ( Symbol ) associations [ association ] = true elsif association .... | Returns a hash structure used to identify the revisioned associations . |
17,657 | def store_revision if new_record? || @revisions_disabled return yield else retval = nil revision = nil begin revision_record_class . transaction do begin read_only = self . class . first ( :conditions => { self . class . primary_key => self . id } , :readonly => true ) if read_only revision = read_only . create_revisio... | Call this method to implement revisioning . The object changes should happen inside the block . |
17,658 | def create_revision! revision_options = self . class . acts_as_revisionable_options revision = revision_record_class . new ( self , revision_options [ :encoding ] ) if revision_options [ :meta ] . is_a? ( Hash ) revision_options [ :meta ] . each do | attribute , value | set_revision_meta_attribute ( revision , attribut... | Create a revision record based on this record and save it to the database . |
17,659 | def set_revision_meta_attribute ( revision , attribute , value ) case value when Symbol value = self . send ( value ) when Proc value = value . call ( self ) end revision . send ( "#{attribute}=" , value ) end | Set an attribute based on a meta argument |
17,660 | def errors return [ ] if success? @errors ||= Array . wrap ( response [ :errors ] ) . map do | error | ErrorResult . new ( error [ :error ] ) end end | An array of + ErrorResult + items or an empty array if the response was successful . |
17,661 | def render ( options = { } ) options [ :theme ] ||= theme options [ :value_formatter ] ||= value_formatter options [ :key_formatter ] ||= key_formatter options [ :point_markers ] ||= point_markers options [ :point_markers_rotation ] ||= point_markers_rotation options [ :point_markers_ticks ] ||= point_markers_ticks opt... | Writer defined below Returns a new Graph . You can optionally pass in a default graph type and an options hash . |
17,662 | def render ( svg , options = { } ) current_points = points layers . each do | layer | real_points = layer . points layer . points = current_points layer_options = options . dup layer_options [ :color ] = layer . preferred_color || layer . color || options [ :theme ] . next_color layer . render ( svg , layer_options ) o... | Returns new Stacked graph . |
17,663 | def legend_data if relevant_data? retval = [ ] layers . each do | layer | retval << layer . legend_data end retval else nil end end | A stacked graph has many data sets . Return legend information for all of them . |
17,664 | def render ( options = { } ) options [ :graph_id ] ||= 'scruffy_graph' options [ :complexity ] ||= ( global_complexity || :normal ) rendertime_renderer = self . clone rendertime_renderer . instance_eval { before_render if respond_to? ( :before_render ) } svg = Builder :: XmlMarkup . new ( :indent => 2 ) unless options ... | Renders the graph and all components . |
17,665 | def set_segments ( crawl_segments , max_files = nil ) self . job_name = set_job_name self . job_desc = set_job_desc ( crawl_segments , max_files ) self . max_files = max_files crawl_segments . each do | segment | self . job_steps . push ( create_job_step ( segment ) ) end end | Populates the job from the list of segments to be parsed . |
17,666 | def run emr_config = job_config [ 'emr_config' ] job_flow_id = run_job_flow ( emr_config ) if job_flow_id . present? self . job_flow_id = job_flow_id self . job_steps . each do | step | segment = step . crawl_segment segment . parse_time = DateTime . now segment . save end self . save self . result_message end end | Runs the job by calling Elastic MapReduce API . If successful the parse time is set for each segment . |
17,667 | def segment_list segments = [ 'Segments' ] job_steps . each do | job_step | if job_step . crawl_segment . present? segment = job_step . crawl_segment segments . push ( segment . segment_desc ) end end segments . push ( '' ) end | Return list of segment descriptions . |
17,668 | def set_job_desc ( segments , max_files ) if segments . count > 0 crawl_name = segments [ 0 ] . crawl . crawl_name if segments [ 0 ] . crawl . present? file_desc = max_files . nil? ? 'all files' : "#{max_files} files per segment" end "Crawl: #{crawl_name} Segments: #{segments.count} Parsing: #{file_desc}" end | Sets the job description which forms part of the Elastic MapReduce job flow name . |
17,669 | def old_to_s ( format = :default ) format = FORMATS [ format ] if format . is_a? ( Symbol ) result = format . dup FORMAT_METHODS . each_pair do | key , value | result . gsub! ( key , value . call ( self ) ) if result . include? key end lead_trim = ( year != 0 && format . lstrip . start_with? ( "%Y" ) ) ? / \A \/ \, \s ... | Here for the moment for benchmark comparisons |
17,670 | def draw ( svg , coords , options = { } ) options . merge! ( @options ) stroke_width = ( options [ :relativestroke ] ) ? relative ( options [ :stroke_width ] ) : options [ :stroke_width ] style = ( options [ :style ] ) ? options [ :style ] : '' if options [ :shadow ] svg . g ( :class => 'shadow' , :transform => "transl... | Renders line graph . |
17,671 | def status total = self . crawl_segments . count remaining = CrawlSegment . where ( :crawl_id => self . id , :parse_time => nil ) . count parsed = total - remaining status = self . crawl_name status += " Segments: to parse #{remaining}, " status += "parsed #{parsed}, total #{total}" end | Returns the status of the current crawl . |
17,672 | def create_segments file_paths = warc_paths ( self . crawl_name ) segments = parse_segments ( file_paths ) save if segments . count > 0 segments . keys . each do | segment_name | file_count = segments [ segment_name ] CrawlSegment . create_segment ( self , segment_name , file_count ) end segments . count end | Creates crawl segments from the warc . paths file for this crawl . |
17,673 | def reset segments = CrawlSegment . where ( 'crawl_id = ? and parse_time is not null' , self . id ) segments . map { | segment | segment . update_attribute ( :parse_time , nil ) } status end | Resets parse time of all parsed segments to null so they will be parsed again . Returns the updated crawl status . |
17,674 | def warc_paths ( crawl_name ) s3_path = [ Elasticrawl :: COMMON_CRAWL_PATH , crawl_name , Elasticrawl :: WARC_PATHS ] . join ( '/' ) begin s3 = AWS :: S3 . new bucket = s3 . buckets [ Elasticrawl :: COMMON_CRAWL_BUCKET ] object = bucket . objects [ s3_path ] uncompress_file ( object ) rescue AWS :: Errors :: Base => s3... | Gets the WARC file paths from S3 for this crawl if it exists . |
17,675 | def uncompress_file ( s3_object ) result = '' if s3_object . exists? io = StringIO . new io . write ( s3_object . read ) io . rewind gz = Zlib :: GzipReader . new ( io ) result = gz . read gz . close end result end | Takes in a S3 object and returns the contents as an uncompressed string . |
17,676 | def parse_segments ( warc_paths ) segments = Hash . new 0 warc_paths . split . each do | warc_path | segment_name = warc_path . split ( '/' ) [ 3 ] segments [ segment_name ] += 1 if segment_name . present? end segments end | Parses the segment names and file counts from the WARC file paths . |
17,677 | def draw ( svg , coords , options = { } ) color_count = nil if @area_colors && @area_colors . size > 0 area_color = @area_colors [ 0 ] color_count = 1 else puts "Never Set Area Color" area_color = color end draw_poly ( svg , coords , area_color , options = { } ) if @baselines puts "Drawing Baselines" @baselines . sort!... | Render Multi Area graph . |
17,678 | def normalize_numbers ( _numbers ) numbers = _numbers . map ( & :to_i ) min = numbers . min numbers . map do | n | n - min end end | Returns the normalized equivalent of a given list |
17,679 | def parse_ambit_value feature , v , dataset v . delete "unit" if v . keys == [ "textValue" ] add_feature feature , v [ "textValue" ] , dataset elsif v . keys == [ "loValue" ] add_feature feature , v [ "loValue" ] , dataset elsif v . keys . size == 2 and v [ "errorValue" ] add_feature feature , v [ "loValue" ] , dataset... | Parse values from Ambit database |
17,680 | def substances @substances ||= data_entries . keys . collect { | id | OpenTox :: Substance . find id } . uniq @substances end | Get all substances |
17,681 | def features @features ||= data_entries . collect { | sid , data | data . keys . collect { | id | OpenTox :: Feature . find ( id ) } } . flatten . uniq @features end | Get all features |
17,682 | def values substance , feature substance = substance . id if substance . is_a? Substance feature = feature . id if feature . is_a? Feature if data_entries [ substance . to_s ] and data_entries [ substance . to_s ] [ feature . to_s ] data_entries [ substance . to_s ] [ feature . to_s ] else [ nil ] end end | Get all values for a given substance and feature |
17,683 | def add ( substance , feature , value ) substance = substance . id if substance . is_a? Substance feature = feature . id if feature . is_a? Feature data_entries [ substance . to_s ] ||= { } data_entries [ substance . to_s ] [ feature . to_s ] ||= [ ] data_entries [ substance . to_s ] [ feature . to_s ] << value end | Writers Add a value for a given substance and feature |
17,684 | def folds n len = self . substances . size indices = ( 0 .. len - 1 ) . to_a . shuffle mid = ( len / n ) chunks = [ ] start = 0 1 . upto ( n ) do | i | last = start + mid last = last - 1 unless len % n >= i test_idxs = indices [ start .. last ] || [ ] test_substances = test_idxs . collect { | i | substances [ i ] } tra... | Dataset operations Split a dataset into n folds |
17,685 | def to_csv ( inchi = false ) CSV . generate ( ) do | csv | compound = substances . first . is_a? Compound if compound csv << [ inchi ? "InChI" : "SMILES" ] + features . collect { | f | f . name } else csv << [ "Name" ] + features . collect { | f | f . name } end substances . each do | substance | if compound name = ( i... | Serialisation Convert dataset to csv format including compound smiles as first column other column headers are feature names |
17,686 | def inspect ( * args ) if args . first . is_a? ( Hash ) && args . length . eql? ( 1 ) args . first . each do | name , value | self . debug ( "#{name}: #{value.inspect}" ) end else args = args . map { | arg | arg . inspect } self . debug ( * args ) end end | Project . logger . inspect ( |
17,687 | def add ( frame ) return false if max_size && queue . length >= max_size return false if seen . include? ( frame . gid ) seen . add ( frame . gid ) idx = random_idx ? rand ( queue . length + 1 ) : queue . length queue . insert ( idx , frame ) true end | Initialize a new Queue . |
17,688 | def add_gid ( gid , parent = nil ) frame = Frame . new ( self , gid , parent ) add ( frame ) end | Add a GID to the queue . |
17,689 | def location ( key ) location = locations . select { | l | l [ :fulfillment_location ] == key } . first return { } if location . nil? location end | Finds a location by + FulfillmentLocation + . |
17,690 | def prepare ( opt = { } ) throw :ConfigInstanceAlreadyPrepared if @prepared && ! opt [ :force_reset ] @prepared = true @fullpaths = opt [ :fullpaths ] @project_path = nil @project_generator_path = nil @project_plugin_path = nil @project_template_path = nil @generator_path = [ ] @plugin_path = [ ] @template_path = [ ] @... | Must be called once before using cog . In the context of a command - line invocation this method will be called automatically . Outside of that context for example in a unit test it will have to be called manually . |
17,691 | def taxes_for_shipment ( shipment_key ) shipment = shipment_sales_tax_rates . select { | s | s [ :@shipment_key ] == shipment_key } . first freight = attributes_to_symbols ( shipment [ :freight_sales_tax_rate ] ) products = wrap_products ( shipment [ :product_sales_tax_rates ] ) ShipmentSalesTaxRate . new ( shipment_ke... | Access the tax information for a shipment . Returns an instance of ShipmentSalesTaxRate . |
17,692 | def compliance_rules_for_shipment ( shipment_key ) shipment = shipment_compliance_rules . select { | s | s [ :key ] == shipment_key } . first ShipmentCompliance . new ( shipment ) end | Finds all the compliance rules for a shipment . Returns an instance of ShipmentCompliance . |
17,693 | def gather_from_env ENV . each do | key , value | if key . downcase =~ / / self [ $2 ] = YAML . safe_load ( value ) end end end | Find configuration data in environment variables . This is the only option on Chef 12 . 0 12 . 1 and 12 . 2 . |
17,694 | def gather_from_node return unless defined? ( Chef . node ) ( Chef . node [ 'poise-profiler' ] || { } ) . each do | key , value | self [ key ] = value end end | Find configuration data in node attributes . |
17,695 | def inventory_levels levels = { } product [ :inventory_levels ] [ :inventory_level ] . each do | level | key = level [ :inventory_type ] . underscore . to_sym value = level [ :quantity ] . to_f levels [ key ] = value end levels end | Returns a Hash of inventory levels . |
17,696 | def create_job_flow ( job , emr_config = nil ) config = Config . new Elasticity . configure do | c | c . access_key = config . access_key_id c . secret_key = config . secret_access_key end job_flow = Elasticity :: JobFlow . new job_flow . name = "Job: #{job.job_name} #{job.job_desc}" job_flow . log_uri = job . log_uri ... | Returns a configured job flow to the calling job . |
17,697 | def configure_job_flow ( job_flow ) ec2_key_name = config_setting ( 'ec2_key_name' ) placement = config_setting ( 'placement' ) emr_ami_version = config_setting ( 'emr_ami_version' ) job_flow_role = config_setting ( 'job_flow_role' ) service_role = config_setting ( 'service_role' ) ec2_subnet_id = config_setting ( 'ec2... | Set job flow properties from settings in cluster . yml . |
17,698 | def configure_bootstrap_actions ( job_flow , emr_config = nil ) bootstrap_scripts = config_setting ( 'bootstrap_scripts' ) if bootstrap_scripts . present? bootstrap_scripts . each do | script_uri | action = Elasticity :: BootstrapAction . new ( script_uri , '' , '' ) job_flow . add_bootstrap_action ( action ) end end i... | Configures bootstrap actions that will be run when each instance is launched . EMR config is an XML file of Hadoop settings stored on S3 . There are applied to each node by a bootstrap action . |
17,699 | def relevant_legend_info ( layers , categories = ( @options [ :category ] ? [ @options [ :category ] ] : @options [ :categories ] ) ) legend_info = layers . inject ( [ ] ) do | arr , layer | if categories . nil? || ( categories . include? ( layer . options [ :category ] ) || ( layer . options [ :categories ] && ( categ... | Collects Legend Info from the provided Layers . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.