idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
4,500 | def [] ( * input_indexes ) positions = @index . pos ( * input_indexes ) return @data [ positions ] if positions . is_a? Numeric Daru :: Vector . new ( positions . map { | loc | @data [ loc ] } , name : @name , index : @index . subset ( * input_indexes ) , dtype : @dtype ) end | Get one or more elements with specified index or a range . |
4,501 | def at * positions original_positions = positions positions = coerce_positions ( * positions ) validate_positions ( * positions ) if positions . is_a? Integer @data [ positions ] else values = positions . map { | pos | @data [ pos ] } Daru :: Vector . new values , index : @index . at ( * original_positions ) , dtype : ... | Returns vector of values given positional values |
4,502 | def set_at positions , val validate_positions ( * positions ) positions . map { | pos | @data [ pos ] = val } update_position_cache end | Change value at given positions |
4,503 | def concat element , index raise IndexError , 'Expected new unique index' if @index . include? index @index |= [ index ] @data [ @index [ index ] ] = element update_position_cache end | Append an element to the vector by specifying the element and index |
4,504 | def cast opts = { } dt = opts [ :dtype ] raise ArgumentError , "Unsupported dtype #{opts[:dtype]}" unless %i[ array nmatrix gsl ] . include? ( dt ) @data = cast_vector_to dt unless @dtype == dt end | Cast a vector to a new data type . |
4,505 | def delete_at index @data . delete_at @index [ index ] @index = Daru :: Index . new ( @index . to_a - [ index ] ) update_position_cache end | Delete element by index |
4,506 | def index_of element case dtype when :array then @index . key ( @data . index { | x | x . eql? element } ) else @index . key @data . index ( element ) end end | Get index of element |
4,507 | def uniq uniq_vector = @data . uniq new_index = uniq_vector . map { | element | index_of ( element ) } Daru :: Vector . new uniq_vector , name : @name , index : new_index , dtype : @dtype end | Keep only unique elements of the vector alongwith their indexes . |
4,508 | def sort_by_index opts = { } opts = { ascending : true } . merge ( opts ) _ , new_order = resort_index ( @index . each_with_index , opts ) . transpose reorder new_order end | Sorts the vector according to it s Index values . Defaults to ascending order sorting . |
4,509 | def recode! dt = nil , & block return to_enum ( :recode! ) unless block_given? @data . map! ( & block ) . data @data = cast_vector_to ( dt || @dtype ) self end | Destructive version of recode! |
4,510 | def delete_if return to_enum ( :delete_if ) unless block_given? keep_e , keep_i = each_with_index . reject { | n , _i | yield ( n ) } . transpose @data = cast_vector_to @dtype , keep_e @index = Daru :: Index . new ( keep_i ) update_position_cache self end | Delete an element if block returns true . Destructive . |
4,511 | def verify ( 0 ... size ) . map { | i | [ i , @data [ i ] ] } . reject { | _i , val | yield ( val ) } . to_h end | Reports all values that doesn t comply with a condition . Returns a hash with the index of data and the invalid data . |
4,512 | def lag k = 1 case k when 0 then dup when 1 ... size copy ( [ nil ] * k + data . to_a ) when - size .. - 1 copy ( data . to_a [ k . abs ... size ] ) else copy ( [ ] ) end end | Lags the series by k periods . |
4,513 | def to_matrix axis = :horizontal if axis == :horizontal Matrix [ to_a ] elsif axis == :vertical Matrix . columns ( [ to_a ] ) else raise ArgumentError , "axis should be either :horizontal or :vertical, not #{axis}" end end | Convert Vector to a horizontal or vertical Ruby Matrix . |
4,514 | def to_nmatrix axis = :horizontal unless numeric? && ! include? ( nil ) raise ArgumentError , 'Can not convert to nmatrix' 'because the vector is numeric' end case axis when :horizontal NMatrix . new [ 1 , size ] , to_a when :vertical NMatrix . new [ size , 1 ] , to_a else raise ArgumentError , 'Invalid axis specified.... | Convert vector to nmatrix object |
4,515 | def object_summary nval = count_values ( * Daru :: MISSING_VALUES ) summary = "\n factors: #{factors.to_a.join(',')}" "\n mode: #{mode.to_a.join(',')}" "\n Distribution\n" data = frequencies . sort . each_with_index . map do | v , k | [ k , v , '%0.2f%%' % ( ( nval . zero? ? 1 : v . quo ( nval ) ) * 100 ) ] end summ... | Displays summary for an object type Vector |
4,516 | def numeric_summary summary = "\n median: #{median}" + "\n mean: %0.4f" % mean if sd summary << "\n std.dev.: %0.4f" % sd + "\n std.err.: %0.4f" % se end if count_values ( * Daru :: MISSING_VALUES ) . zero? summary << "\n skew: %0.4f" % skew + "\n kurtosis: %0.4f" % kurtosis end summary end | Displays summary for an numeric type Vector |
4,517 | def inspect spacing = 20 , threshold = 15 row_headers = index . is_a? ( MultiIndex ) ? index . sparse_tuples : index . to_a "#<#{self.class}(#{size})#{':category' if category?}>\n" + Formatters :: Table . format ( to_a . lazy . map { | v | [ v ] } , headers : @name && [ @name ] , row_headers : row_headers , threshold :... | Over rides original inspect for pretty printing in irb |
4,518 | def reindex! new_index values = [ ] each_with_index do | val , i | values [ new_index [ i ] ] = val if new_index . include? ( i ) end values . fill ( nil , values . size , new_index . size - values . size ) @data = cast_vector_to @dtype , values @index = new_index update_position_cache self end | Sets new index for vector . Preserves index - > value correspondence . Sets nil for new index keys absent from original index . |
4,519 | def only_valid as_a = :vector , _duplicate = true new_index = @index . to_a - indexes ( * Daru :: MISSING_VALUES ) new_vector = new_index . map { | idx | self [ idx ] } if as_a == :vector Daru :: Vector . new new_vector , index : new_index , name : @name , dtype : dtype else new_vector end end | Creates a new vector consisting only of non - nil data |
4,520 | def only_numerics numeric_indexes = each_with_index . select { | v , _i | v . is_a? ( Numeric ) || v . nil? } . map ( & :last ) self [ * numeric_indexes ] end | Returns a Vector with only numerical data . Missing data is included but non - Numeric objects are excluded . Preserves index . |
4,521 | def db_type case when @data . any? { | v | v . to_s =~ DATE_REGEXP } 'DATE' when @data . any? { | v | v . to_s =~ / / } 'VARCHAR (255)' when @data . any? { | v | v . to_s =~ / \. / } 'DOUBLE' else 'INTEGER' end end | Returns the database type for the vector according to its content |
4,522 | def to_category opts = { } dv = Daru :: Vector . new to_a , type : :category , name : @name , index : @index dv . ordered = opts [ :ordered ] || false dv . categories = opts [ :categories ] if opts [ :categories ] dv end | Converts a non category type vector to category type vector . |
4,523 | def cut partitions , opts = { } close_at , labels = opts [ :close_at ] || :right , opts [ :labels ] partitions = partitions . to_a values = to_a . map { | val | cut_find_category partitions , val , close_at } cats = cut_categories ( partitions , close_at ) dv = Daru :: Vector . new values , index : @index , type : :cat... | Partition a numeric variable into categories . |
4,524 | def valid_value? ( v ) v . respond_to? ( :nan? ) && v . nan? || v . nil? ? false : true end | Helper method returning validity of arbitrary value |
4,525 | def prepare_bootstrap ( estimators ) h_est = estimators h_est = [ h_est ] unless h_est . is_a? ( Array ) || h_est . is_a? ( Hash ) if h_est . is_a? Array h_est = h_est . map do | est | [ est , -> ( v ) { Daru :: Vector . new ( v ) . send ( est ) } ] end . to_h end bss = h_est . keys . map { | v | [ v , [ ] ] } . to_h [... | For an array or hash of estimators methods returns an array with three elements 1 . - A hash with estimators names as keys and lambdas as values 2 . - An array with estimators names 3 . - A Hash with estimators names as keys and empty arrays as values |
4,526 | def coerce_positions * positions if positions . size == 1 case positions . first when Integer positions . first when Range size . times . to_a [ positions . first ] else raise ArgumentError , 'Unkown position type.' end else positions end end | coerce ranges integers and array in appropriate ways |
4,527 | def row_at * positions original_positions = positions positions = coerce_positions ( * positions , nrows ) validate_positions ( * positions , nrows ) if positions . is_a? Integer row = get_rows_for ( [ positions ] ) Daru :: Vector . new row , index : @vectors else new_rows = get_rows_for ( original_positions ) Daru :: ... | Retrive rows by positions |
4,528 | def set_row_at positions , vector validate_positions ( * positions , nrows ) vector = if vector . is_a? Daru :: Vector vector . reindex @vectors else Daru :: Vector . new vector end raise SizeError , 'Vector length should match row length' if vector . size != @vectors . size @data . each_with_index do | vec , pos | vec... | Set rows by positions |
4,529 | def at * positions if AXES . include? positions . last axis = positions . pop return row_at ( * positions ) if axis == :row end original_positions = positions positions = coerce_positions ( * positions , ncols ) validate_positions ( * positions , ncols ) if positions . is_a? Integer @data [ positions ] . dup else Daru ... | Retrive vectors by positions |
4,530 | def set_at positions , vector if positions . last == :row positions . pop return set_row_at ( positions , vector ) end validate_positions ( * positions , ncols ) vector = if vector . is_a? Daru :: Vector vector . reindex @index else Daru :: Vector . new vector end raise SizeError , 'Vector length should match index len... | Set vectors by positions |
4,531 | def get_sub_dataframe ( keys , by_position : true ) return Daru :: DataFrame . new ( { } ) if keys == [ ] keys = @index . pos ( * keys ) unless by_position sub_df = row_at ( * keys ) sub_df = sub_df . to_df . transpose if sub_df . is_a? ( Daru :: Vector ) sub_df end | Extract a dataframe given row indexes or positions |
4,532 | def dup_only_valid vecs = nil rows_with_nil = @data . map { | vec | vec . indexes ( * Daru :: MISSING_VALUES ) } . inject ( & :concat ) . uniq row_indexes = @index . to_a ( vecs . nil? ? self : dup ( vecs ) ) . row [ * ( row_indexes - rows_with_nil ) ] end | Creates a new duplicate dataframe containing only rows without a single missing value . |
4,533 | def reject_values ( * values ) positions = size . times . to_a - @data . flat_map { | vec | vec . positions ( * values ) } if positions . size == 1 pos = positions . first row_at ( pos .. pos ) else row_at ( * positions ) end end | Returns a dataframe in which rows with any of the mentioned values are ignored . |
4,534 | def uniq ( * vtrs ) vecs = vtrs . empty? ? vectors . to_a : Array ( vtrs ) grouped = group_by ( vecs ) indexes = grouped . groups . values . map { | v | v [ 0 ] } . sort row [ * indexes ] end | Return unique rows by vector specified or all vectors |
4,535 | def collect_matrix return to_enum ( :collect_matrix ) unless block_given? vecs = vectors . to_a rows = vecs . collect { | row | vecs . collect { | col | yield row , col } } Matrix . rows ( rows ) end | Generate a matrix based on vector names of the DataFrame . |
4,536 | def delete_row index idx = named_index_for index raise IndexError , "Index #{index} does not exist." unless @index . include? idx @index = Daru :: Index . new ( @index . to_a - [ idx ] ) each_vector do | vector | vector . delete_at idx end set_size end | Delete a row |
4,537 | def bootstrap ( n = nil ) n ||= nrows Daru :: DataFrame . new ( { } , order : @vectors ) . tap do | df_boot | n . times do df_boot . add_row ( row [ rand ( n ) ] ) end df_boot . update end end | Creates a DataFrame with the random data of n size . If n not given uses original number of rows . |
4,538 | def filter_vector vec , & block Daru :: Vector . new ( each_row . select ( & block ) . map { | row | row [ vec ] } ) end | creates a new vector with the data of a given field which the block returns true |
4,539 | def filter_rows return to_enum ( :filter_rows ) unless block_given? keep_rows = @index . map { | index | yield access_row ( index ) } where keep_rows end | Iterates over each row and retains it in a new DataFrame if the block returns true for that row . |
4,540 | def filter_vectors & block return to_enum ( :filter_vectors ) unless block_given? dup . tap { | df | df . keep_vector_if ( & block ) } end | Iterates over each vector and retains it in a new DataFrame if the block returns true for that vector . |
4,541 | def order = ( order_array ) raise ArgumentError , 'Invalid order' unless order_array . sort == vectors . to_a . sort initialize ( to_h , order : order_array ) end | Reorder the vectors in a dataframe |
4,542 | def missing_values_rows missing_values = [ nil ] number_of_missing = each_row . map do | row | row . indexes ( * missing_values ) . size end Daru :: Vector . new number_of_missing , index : @index , name : "#{@name}_missing_rows" end | Return a vector with the number of missing values in each row . |
4,543 | def nest * tree_keys , & _block tree_keys = tree_keys [ 0 ] if tree_keys [ 0 ] . is_a? Array each_row . each_with_object ( { } ) do | row , current | * keys , last = tree_keys current = keys . inject ( current ) { | c , f | c [ row [ f ] ] ||= { } } name = row [ last ] if block_given? current [ name ] = yield ( row , c... | Return a nested hash using vector names as keys and an array constructed of hashes with other values . If block provided is used to provide the values with parameters + row + of dataset + current + last hash on hierarchy and + name + of the key to include |
4,544 | def vector_mean max_missing = 0 mean_vec = Daru :: Vector . new [ 0 ] * @size , index : @index , name : "mean_#{@name}" each_row_with_index . each_with_object ( mean_vec ) do | ( row , i ) , memo | memo [ i ] = row . indexes ( * Daru :: MISSING_VALUES ) . size > max_missing ? nil : row . mean end end | Calculate mean of the rows of the dataframe . |
4,545 | def concat other_df vectors = ( @vectors . to_a + other_df . vectors . to_a ) . uniq data = vectors . map do | v | get_vector_anyways ( v ) . dup . concat ( other_df . get_vector_anyways ( v ) ) end Daru :: DataFrame . new ( data , order : vectors ) end | Concatenate another DataFrame along corresponding columns . If columns do not exist in both dataframes they are filled with nils |
4,546 | def set_index new_index_col , opts = { } if new_index_col . respond_to? ( :to_a ) strategy = SetMultiIndexStrategy new_index_col = new_index_col . to_a else strategy = SetSingleIndexStrategy end uniq_size = strategy . uniq_size ( self , new_index_col ) raise ArgumentError , 'All elements in new index must be unique.' i... | Set a particular column as the new DF |
4,547 | def rename_vectors name_map existing_targets = name_map . reject { | k , v | k == v } . values & vectors . to_a delete_vectors ( * existing_targets ) new_names = vectors . to_a . map { | v | name_map [ v ] ? name_map [ v ] : v } self . vectors = Daru :: Index . new new_names end | Renames the vectors |
4,548 | def summary summary = "= #{name}" summary << "\n Number of rows: #{nrows}" @vectors . each do | v | summary << "\n Element:[#{v}]\n" summary << self [ v ] . summary ( 1 ) end summary end | Generate a summary of this DataFrame based on individual vectors in the DataFrame |
4,549 | def pivot_table opts = { } raise ArgumentError , 'Specify grouping index' if Array ( opts [ :index ] ) . empty? index = opts [ :index ] vectors = opts [ :vectors ] || [ ] aggregate_function = opts [ :agg ] || :mean values = prepare_pivot_values index , vectors , opts raise IndexError , 'No numeric vectors to aggregate'... | Pivots a data frame on specified vectors and applies an aggregate function to quickly generate a summary . |
4,550 | def one_to_many ( parent_fields , pattern ) vars , numbers = one_to_many_components ( pattern ) DataFrame . new ( [ ] , order : [ * parent_fields , '_col_id' , * vars ] ) . tap do | ds | each_row do | row | verbatim = parent_fields . map { | f | [ f , row [ f ] ] } . to_h numbers . each do | n | generated = one_to_many... | Creates a new dataset for one to many relations on a dataset based on pattern of field names . |
4,551 | def create_sql ( table , charset = 'UTF8' ) sql = "CREATE TABLE #{table} (" fields = vectors . to_a . collect do | f | v = self [ f ] f . to_s + ' ' + v . db_type end sql + fields . join ( ",\n " ) + ") CHARACTER SET=#{charset};" end | Create a sql basen on a given Dataset |
4,552 | def to_html ( threshold = 30 ) table_thead = to_html_thead table_tbody = to_html_tbody ( threshold ) path = if index . is_a? ( MultiIndex ) File . expand_path ( '../iruby/templates/dataframe_mi.html.erb' , __FILE__ ) else File . expand_path ( '../iruby/templates/dataframe.html.erb' , __FILE__ ) end ERB . new ( File . r... | Convert to html for IRuby . |
4,553 | def transpose Daru :: DataFrame . new ( each_vector . map ( & :to_a ) . transpose , index : @vectors , order : @index , dtype : @dtype , name : @name ) end | Transpose a DataFrame tranposing elements and row column indexing . |
4,554 | def aggregate ( options = { } , multi_index_level = - 1 ) if block_given? positions_tuples , new_index = yield ( @index ) else positions_tuples , new_index = group_index_for_aggregation ( @index , multi_index_level ) end colmn_value = aggregate_by_positions_tuples ( options , positions_tuples ) Daru :: DataFrame . new ... | Function to use for aggregating the data . |
4,555 | def validate_positions * positions , size positions . each do | pos | raise IndexError , "#{pos} is not a valid position." if pos >= size end end | Raises IndexError when one of the positions is not a valid position |
4,556 | def coerce_vector vector case vector when Daru :: Vector vector . reindex @vectors when Hash Daru :: Vector . new ( vector ) . reindex @vectors else Daru :: Vector . new vector end end | Accepts hash enumerable and vector and align it properly so it can be added |
4,557 | def valid? * indexes indexes . all? { | i | to_a . include? ( i ) || ( i . is_a? ( Numeric ) && i < size ) } end | Returns true if all arguments are either a valid category or position |
4,558 | def sort opts = { } opts = { ascending : true } . merge ( opts ) new_index = @keys . sort new_index = new_index . reverse unless opts [ :ascending ] self . class . new ( new_index ) end | Sorts a Index according to its values . Defaults to ascending order sorting . |
4,559 | def [] * key return slice ( * key ) if key . size != 1 key = key [ 0 ] case key when Numeric key when DateTime Helper . find_index_of_date ( @data , key ) when Range get_by_range ( key . first , key . last ) else raise ArgumentError , "Key #{key} is out of bounds" if Helper . key_out_of_bounds? ( key , @data ) slice ( ... | Retreive a slice or a an individual index number from the index . |
4,560 | def slice first , last if first . is_a? ( Integer ) && last . is_a? ( Integer ) DateTimeIndex . new ( to_a [ first .. last ] , freq : @offset ) else first = Helper . find_date_string_bounds ( first ) [ 0 ] if first . is_a? ( String ) last = Helper . find_date_string_bounds ( last ) [ 1 ] if last . is_a? ( String ) slic... | Retrive a slice of the index by specifying first and last members of the slice . |
4,561 | def shift distance distance . is_a? ( Integer ) && distance < 0 and raise IndexError , "Distance #{distance} cannot be negative" _shift ( distance ) end | Shift all dates in the index by a positive number in the future . The dates are shifted by the same amount as that specified in the offset . |
4,562 | def lag distance distance . is_a? ( Integer ) && distance < 0 and raise IndexError , "Distance #{distance} cannot be negative" _shift ( - distance ) end | Shift all dates in the index to the past . The dates are shifted by the same amount as that specified in the offset . |
4,563 | def include? date_time return false unless date_time . is_a? ( String ) || date_time . is_a? ( DateTime ) if date_time . is_a? ( String ) date_precision = Helper . determine_date_precision_of date_time date_time = Helper . date_time_from date_time , date_precision end result , = @data . bsearch { | d | d [ 0 ] >= date_... | Check if a date exists in the index . Will be inferred from string in case you pass a string . Recommened specifying the full date as a DateTime object . |
4,564 | def initialize_category data , opts = { } @type = :category initialize_core_attributes data if opts [ :categories ] validate_categories ( opts [ :categories ] ) add_extra_categories ( opts [ :categories ] - categories ) order_with opts [ :categories ] end @ordered = opts [ :ordered ] || false @coding_scheme = :dummy @b... | Initializes a vector to store categorical data . |
4,565 | def count category = UNDEFINED return @cat_hash . values . map ( & :size ) . inject ( & :+ ) if category == UNDEFINED raise ArgumentError , "Invalid category #{category}" unless categories . include? ( category ) @cat_hash [ category ] . size end | Returns frequency of given category |
4,566 | def at * positions original_positions = positions positions = coerce_positions ( * positions ) validate_positions ( * positions ) return category_from_position ( positions ) if positions . is_a? Integer Daru :: Vector . new positions . map { | pos | category_from_position ( pos ) } , index : @index . at ( * original_po... | Returns vector for positions specified . |
4,567 | def set_at positions , val validate_positions ( * positions ) positions . map { | pos | modify_category_at pos , val } self end | Modifies values at specified positions . |
4,568 | def rename_categories old_to_new old_categories = categories data = to_a . map do | cat | old_to_new . include? ( cat ) ? old_to_new [ cat ] : cat end initialize_core_attributes data self . categories = ( old_categories - old_to_new . keys ) | old_to_new . values self . base_category = old_to_new [ base_category ] if o... | Rename categories . |
4,569 | def remove_unused_categories old_categories = categories initialize_core_attributes to_a self . categories = old_categories & categories self . base_category = @cat_hash . keys . first unless categories . include? base_category self end | Removes the unused categories |
4,570 | def sort! assert_ordered :sort old_index = @index . to_a new_index = @cat_hash . values . map do | positions | old_index . values_at ( * positions ) end . flatten @index = @index . class . new new_index @cat_hash = categories . inject ( [ { } , 0 ] ) do | acc , cat | hash , count = acc cat_count = @cat_hash [ cat ] . s... | Sorts the vector in the order specified . |
4,571 | def reindex! idx idx = Daru :: Index . new idx unless idx . is_a? Daru :: Index raise ArgumentError , 'Invalid index specified' unless idx . to_a . sort == index . to_a . sort old_categories = categories data = idx . map { | i | self [ i ] } initialize_core_attributes data self . categories = old_categories self . inde... | Sets new index for vector . Preserves index - > value correspondence . |
4,572 | def count_values ( * values ) values . map { | v | @cat_hash [ v ] . size if @cat_hash . include? v } . compact . inject ( 0 , :+ ) end | Count the number of values specified |
4,573 | def indexes ( * values ) values &= categories index . to_a . values_at ( * values . flat_map { | v | @cat_hash [ v ] } . sort ) end | Return indexes of values specified |
4,574 | def progress ( msg , nontty_log = :debug ) send ( nontty_log , msg ) if nontty_log return unless show_progress icon = "" if defined? ( :: Encoding ) icon = PROGRESS_INDICATORS [ @progress_indicator ] + " " end @mutex . synchronize do print ( "\e[2K\e[?25l\e[1m#{icon}#{msg}\e[0m\r" ) @progress_msg = msg if Time . now - ... | Displays a progress indicator for a given message . This progress report is only displayed on TTY displays otherwise the message is passed to the + nontty_log + level . |
4,575 | def backtrace ( exc , level_meth = :error ) return unless show_backtraces send ( level_meth , "#{exc.class.class_name}: #{exc.message}" ) send ( level_meth , "Stack trace:" + exc . backtrace [ 0 .. 5 ] . map { | x | "\n\t#{x}" } . join + "\n" ) end | Prints the backtrace + exc + to the logger as error data . |
4,576 | def tag_is_directive? ( tag_name ) list = %w( attribute endgroup group macro method scope visibility ) list . include? ( tag_name ) end | Backward compatibility to detect old tags that should be specified as directives in 0 . 8 and onward . |
4,577 | def call ( object ) return true if object . is_a? ( CodeObjects :: Proxy ) modify_nilclass @object = object retval = __execute ? true : false unmodify_nilclass retval end | Tests the expressions on the object . |
4,578 | def inheritance_tree ( include_mods = false ) list = ( include_mods ? mixins ( :instance , :class ) : [ ] ) if superclass . is_a? ( Proxy ) || superclass . respond_to? ( :inheritance_tree ) list += [ superclass ] unless superclass == P ( :Object ) || superclass == P ( :BasicObject ) end [ self ] + list . map do | m | n... | Returns the inheritance tree of the object including self . |
4,579 | def meths ( opts = { } ) opts = SymbolHash [ :inherited => true ] . update ( opts ) list = super ( opts ) list += inherited_meths ( opts ) . reject do | o | next ( false ) if opts [ :all ] list . find { | o2 | o2 . name == o . name && o2 . scope == o . scope } end if opts [ :inherited ] list end | Returns the list of methods matching the options hash . Returns all methods if hash is empty . |
4,580 | def inherited_meths ( opts = { } ) inheritance_tree [ 1 .. - 1 ] . inject ( [ ] ) do | list , superclass | if superclass . is_a? ( Proxy ) list else list += superclass . meths ( opts ) . reject do | o | next ( false ) if opts [ :all ] child ( :name => o . name , :scope => o . scope ) || list . find { | o2 | o2 . name =... | Returns only the methods that were inherited . |
4,581 | def constants ( opts = { } ) opts = SymbolHash [ :inherited => true ] . update ( opts ) super ( opts ) + ( opts [ :inherited ] ? inherited_constants : [ ] ) end | Returns the list of constants matching the options hash . |
4,582 | def inherited_constants inheritance_tree [ 1 .. - 1 ] . inject ( [ ] ) do | list , superclass | if superclass . is_a? ( Proxy ) list else list += superclass . constants . reject do | o | child ( :name => o . name ) || list . find { | o2 | o2 . name == o . name } end end end end | Returns only the constants that were inherited . |
4,583 | def superclass = ( object ) case object when Base , Proxy , NilClass @superclass = object when String , Symbol @superclass = Proxy . new ( namespace , object ) else raise ArgumentError , "superclass must be CodeObject, Proxy, String or Symbol" end if name == @superclass . name && namespace != YARD :: Registry . root &&... | Sets the superclass of the object |
4,584 | def collect_namespaces ( object ) return [ ] unless object . respond_to? ( :inheritance_tree ) nss = object . inheritance_tree ( true ) if object . respond_to? ( :superclass ) nss |= [ P ( 'Object' ) ] if object . superclass != P ( 'BasicObject' ) nss |= [ P ( 'BasicObject' ) ] end nss end | Collects and returns all inherited namespaces for a given object |
4,585 | def update ( opts ) opts = opts . to_hash if Options === opts opts . each do | key , value | self [ key ] = value end self end | Updates values from an options hash or options object on this object . All keys passed should be key names defined by attributes on the class . |
4,586 | def each instance_variables . each do | ivar | name = ivar . to_s . sub ( / / , '' ) yield ( name . to_sym , send ( name ) ) end end | Yields over every option key and value |
4,587 | def reset_defaults names_set = { } self . class . ancestors . each do | klass | defaults = klass . instance_variable_defined? ( "@defaults" ) && klass . instance_variable_get ( "@defaults" ) next unless defaults defaults . each do | key , value | next if names_set [ key ] names_set [ key ] = true self [ key ] = Proc ==... | Resets all values to their defaults . |
4,588 | def link_object ( obj , title = nil ) return title if title case obj when YARD :: CodeObjects :: Base , YARD :: CodeObjects :: Proxy obj . title when String , Symbol P ( obj ) . title else obj end end | Links to an object with an optional title |
4,589 | def link_file ( filename , title = nil , anchor = nil ) return filename . filename if CodeObjects :: ExtraFileObject === filename filename end | Links to an extra file |
4,590 | def setup self . class . load_yard if File . exist? ( @doc_dir ) raise Gem :: FilePermissionError , @doc_dir unless File . writable? ( @doc_dir ) else FileUtils . mkdir_p @doc_dir end end | Prepares the spec for documentation generation |
4,591 | def scope = ( v ) reregister = @scope ? true : false if v == :module other = self . class . new ( namespace , name ) other . visibility = :private @visibility = :public @module_function = true @path = nil end YARD :: Registry . delete ( self ) @path = nil @scope = v . to_sym @scope = :class if @scope == :module YARD ::... | Creates a new method object in + namespace + with + name + and an instance or class + scope + |
4,592 | def is_attribute? info = attr_info if info read_or_write = name . to_s =~ / / ? :write : :read info [ read_or_write ] ? true : false else false end end | Tests if the object is defined as an attribute in the namespace |
4,593 | def sep if scope == :class namespace && namespace != YARD :: Registry . root ? CSEP : NSEP else ISEP end end | Override separator to differentiate between class and instance methods . |
4,594 | def put ( key , value ) if key == '' @object_types [ :root ] = [ :root ] @store [ :root ] = value else @notfound . delete ( key . to_sym ) ( @object_types [ value . type ] ||= [ ] ) << key . to_s if @store [ key . to_sym ] @object_types [ @store [ key . to_sym ] . type ] . delete ( key . to_s ) end @store [ key . to_sy... | Associates an object with a path |
4,595 | def load_all return unless @file return if @loaded_objects >= @available_objects log . debug "Loading entire database: #{@file} ..." objects = [ ] all_disk_objects . sort_by ( & :size ) . each do | path | obj = @serializer . deserialize ( path , true ) objects << obj if obj end objects . each do | obj | put ( obj . pat... | Loads all cached objects into memory |
4,596 | def save ( merge = true , file = nil ) if file && file != @file @file = file @serializer = Serializers :: YardocSerializer . new ( @file ) end destroy unless merge sdb = Registry . single_object_db if sdb == true || sdb . nil? @serializer . serialize ( @store ) else values ( false ) . each do | object | @serializer . s... | Saves the database to disk |
4,597 | def destroy ( force = false ) if ( ! force && file =~ / \. / ) || force if File . file? ( @file ) File . unlink ( @file ) elsif File . directory? ( @file ) FileUtils . rm_rf ( @file ) end true else false end end | Deletes the . yardoc database on disk |
4,598 | def summary resolve_reference return @summary if defined? ( @summary ) && @summary stripped = gsub ( / \r \n \r \n / , ' ' ) . strip num_parens = 0 idx = length . times do | index | case stripped [ index , 1 ] when "." next_char = stripped [ index + 1 , 1 ] . to_s break index - 1 if num_parens <= 0 && next_char =~ / \s... | Gets the first line of a docstring to the period or the first paragraph . |
4,599 | def to_raw tag_data = tags . map do | tag | case tag when Tags :: OverloadTag tag_text = "@#{tag.tag_name} #{tag.signature}\n" unless tag . docstring . blank? tag_text += "\n " + tag . docstring . all . gsub ( / \r \n / , "\n " ) end when Tags :: OptionTag tag_text = "@#{tag.tag_name} #{tag.name}" tag_text += ' [' + ... | Reformats and returns a raw representation of the tag data using the current tag and docstring data not the original text . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.