idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
12,300 | def to_m ( * attrs ) m = Matrix . build ( self . row_size , self . column_size ) { nil } self . each_with_index do | x , row , col | if attrs . size == 0 || attrs . nil? m [ row , col ] = x . value end end return m end | The to_m method returns a simple Matrix object filled with the raw values of the original Sheet object . |
12,301 | def body ( klass = Builder ) builder = klass . new ( body_content , input_body_content_type ) yield builder if block_given? builder end | Build the body of the envelope |
12,302 | def header ( klass = Builder ) builder = klass . new ( header_content , input_header_content_type ) yield builder if block_given? builder end | Build the header of the envelope |
12,303 | def search_exception ( exception , delegate = nil ) query = ExceptionHound . new ( exception ) . query search_query ( query , delegate ) end | Init function with orta project Will do some magic to try and pull out a reasonable search query for an exception then searches with that |
12,304 | def search_query ( query , delegate = nil ) delegate ||= Evidence . new sidekick . search ( query , delegate ) end | Queries for an specific search string |
12,305 | def type ( namespace , name ) if @allow_abstract_types @types . fetch ( [ namespace , name ] ) { abstract_type ( namespace , name ) } else @types . fetch ( [ namespace , name ] ) { NullType . new } end end | Get a single type or a NullType if the type doesn t exist |
12,306 | def fault @fault ||= begin node = doc . at_xpath ( '/soap:Envelope/soap:Body/soap:Fault' , 'soap' => soap_namespace ) Fault . new ( request , node ) if node end end | SOAP fault if any |
12,307 | def search ( query , delegate ) validate_delegate ( delegate ) delegate . inspector_started_query ( query , inspector ) url = url_for_request query begin results = get_api_results ( url ) rescue Timeout :: Error , Errno :: EINVAL , Errno :: ECONNRESET , EOFError , Net :: HTTPBadResponse , Net :: HTTPHeaderSyntaxError ,... | Searches for a query with a UI delegate |
12,308 | def url_for_request ( query , sort_by : nil , order : nil ) url = "https://api.github.com/search/issues?q=" url += ERB :: Util . url_encode ( query ) url += "+repo:#{repo_owner}/#{repo_name}" url += "&sort=#{sort_by}" if sort_by url += "&order=#{order}" if order url end | Generates a URL for the request |
12,309 | def get_api_results ( url ) uri = URI . parse ( url ) puts "URL: #{url}" if self . verbose http = Net :: HTTP . new ( uri . host , uri . port ) http . use_ssl = true request = Net :: HTTP :: Get . new ( uri . request_uri ) response = http . request ( request ) JSON . parse ( response . body ) end | Gets the search results |
12,310 | def parse_results ( query , results ) report = InspectionReport . new report . url = "https://github.com/#{repo_owner}/#{repo_name}/search?q=#{ERB::Util.url_encode(query)}&type=Issues&utf8=✓" report . query = query report . total_results = results [ 'total_count' ] report . issues = results [ 'items' ] . map { | item |... | Converts a GitHub search JSON into a InspectionReport |
12,311 | def name_for_comment ( comment ) if comment . website? link_to ( comment . name , comment . website , class : "blogit_comment__name_link" ) else comment . name end + " " + t ( 'wrote' , scope : "blogit.comments" ) end | The commenter s name for a Comment . When the Comment has a website includes an html link containing their name . Otherwise just shows the name as a String . |
12,312 | def draw ( graph_options = { } ) name = graph_options . delete ( :name ) || "#{owner_class.name}_#{self.name}" draw_options = { :human_name => false } draw_options [ :human_name ] = graph_options . delete ( :human_names ) if graph_options . include? ( :human_names ) graph = Graph . new ( name , graph_options ) states .... | Draws a directed graph of the machine for visualizing the various events states and their transitions . |
12,313 | def div_tag_with_default_class ( default_class , content_or_options , options , & block ) if block_given? options = content_or_options content = capture ( & block ) else content = content_or_options end options [ :class ] = Array ( options [ :class ] ) + [ default_class ] content_tag ( :div , content , options ) end | Creates an HTML div with a default class value added |
12,314 | def validate_options! raise PosInvalid . new ( 'Missing pos_id parameter' ) if pos_id . nil? || pos_id == 0 raise PosInvalid . new ( 'Missing pos_auth_key parameter' ) if pos_auth_key . nil? || pos_auth_key == '' raise PosInvalid . new ( 'Missing key1 parameter' ) if key1 . nil? || key1 == '' raise PosInvalid . new ( '... | Creates new Pos instance |
12,315 | def new_transaction ( options = { } ) options = options . dup options . merge! ( { :pos_id => @pos_id , :pos_auth_key => @pos_auth_key , :gateway_url => options [ :gateway_url ] || @gateway_url , :key1 => @key1 , :encoding => encoding , :variant => variant } ) if ! options . has_key? ( :add_signature ) options [ :add_s... | Creates new transaction |
12,316 | def payu_hidden_fields ( transaction ) html = "" %w( pos_id pos_auth_key pay_type session_id amount amount_netto desc order_id desc2 trsDesc first_name last_name street street_hn street_an city post_code country email phone language client_ip js payback_login sig ts ) . each do | field | value = transaction . send ( fi... | Generates form fields for specified transaction object |
12,317 | def payu_verify_params ( params ) pos_id = params [ 'pos_id' ] pos = Payu [ pos_id ] Signature . verify! ( params [ 'sig' ] , params [ 'pos_id' ] , params [ 'session_id' ] , params [ 'ts' ] , pos . key2 ) end | Verifies signature of passed parameters from Payu request |
12,318 | def request ( method : , url_path : , body : nil , params : { } , header_overrides : { } ) spec = body . nil? ? { } : { body_type : :json } endpoint_spec = Smartsheet :: API :: EndpointSpec . new ( method , [ url_path ] , ** spec ) request_spec = Smartsheet :: API :: RequestSpec . new ( header_overrides : header_overri... | Create a custom request using a provided method and URL path |
12,319 | def request_with_file ( method : , url_path : , file : , file_length : , filename : , content_type : '' , params : { } , header_overrides : { } ) endpoint_spec = Smartsheet :: API :: EndpointSpec . new ( method , [ url_path ] , body_type : :file ) request_spec = Smartsheet :: API :: RequestSpec . new ( header_overrides... | Create a custom request using a provided method URL path and file details |
12,320 | def request_with_file_from_path ( method : , url_path : , path : , filename : nil , content_type : '' , params : { } , header_overrides : { } ) endpoint_spec = Smartsheet :: API :: EndpointSpec . new ( method , [ url_path ] , body_type : :file ) request_spec = Smartsheet :: API :: RequestSpec . new ( header_overrides :... | Create a custom request using a provided method URL path and filepath details |
12,321 | def list ( options = { } ) site = Octopress . site ( options ) Plugins . register options = { 'minimal' => true } if options . empty? message = "Octopress Ink - v#{VERSION}\n" if plugins . size > 0 plugins . each do | plugin | message += plugin . list ( options ) end else message += "You have no plugins installed." end... | Prints a list of plugins and details |
12,322 | def copy_doc ( source , dest , permalink = nil ) contents = File . open ( source ) . read contents . sub! ( / / , "#{doc_yaml('\1', permalink).strip}" ) FileUtils . mkdir_p File . dirname ( dest ) File . open ( dest , 'w' ) { | f | f . write ( contents ) } puts "Updated #{dest} from #{source}" end | Makes it easy for Ink plugins to copy README and CHANGELOG files to doc folder to be used as a documentation asset file |
12,323 | def connect ( async = false ) @connection_thread = Thread . new do @connection = TestConnection . new @global_channel . dispatch ( 'pusher:connection_established' , JSON . dump ( { 'socket_id' => '123abc' } ) ) end @connection_thread . run @connection_thread . join unless async return self end | Simulate a connection being established |
12,324 | def authorize ( channel , callback ) if is_private_channel ( channel . name ) auth_data = get_private_auth ( channel ) elsif is_presence_channel ( channel . name ) auth_data = get_presence_auth ( channel ) end callback . call ( channel , auth_data , channel . user_data ) end | auth for private and presence |
12,325 | def console client_setup ( { } , true , true ) puts "Console Connected to #{@client.url}" puts "HINT: The @client object is available to you\n\n" rescue puts "WARNING: Couldn't connect to #{@options['url'] || ENV['ONEVIEWSDK_URL']}\n\n" ensure require 'pry' Pry . config . prompt = proc { '> ' } Pry . plugins [ 'stack_e... | Open a Ruby console with a connection to OneView |
12,326 | def env data = { } OneviewSDK :: ENV_VARS . each { | k | data [ k ] = ENV [ k ] } if @options [ 'format' ] == 'human' data . each do | key , value | value = "'#{value}'" if value && ! %w[ true false ] . include? ( value ) printf "%-#{data.keys.max_by(&:length).length}s = %s\n" , key , value || 'nil' end else output ( p... | Show environment variables for oneview - sdk - ruby |
12,327 | def show ( type , name ) resource_class = parse_type ( type ) client_setup matches = resource_class . find_by ( @client , name : name ) fail_nice 'Not Found' if matches . empty? data = matches . first . data if options [ 'attribute' ] data = select_attributes ( options [ 'attribute' ] , data ) end output data end | Show resource details |
12,328 | def rest ( method , uri ) log_level = @options [ 'log_level' ] == :warn ? :error : @options [ 'log_level' ] . to_sym client_setup ( 'log_level' => log_level ) uri_copy = uri . dup uri_copy . prepend ( '/' ) unless uri_copy . start_with? ( '/' ) if @options [ 'data' ] begin data = { body : JSON . parse ( @options [ 'dat... | Make REST call to the OneView API |
12,329 | def update ( type , name ) resource_class = parse_type ( type ) client_setup fail_nice 'Must set the hash or json option' unless @options [ 'hash' ] || @options [ 'json' ] fail_nice 'Must set the hash OR json option. Not both' if @options [ 'hash' ] && @options [ 'json' ] begin data = @options [ 'hash' ] || JSON . pars... | Update resource by name |
12,330 | def delete ( type , name ) resource_class = parse_type ( type ) client_setup matches = resource_class . find_by ( @client , name : name ) fail_nice ( 'Not Found' , 2 ) if matches . empty? resource = matches . first return unless options [ 'force' ] || agree ( "Delete '#{name}'? [Y/N] " ) begin resource . delete puts 'D... | Delete resource by name |
12,331 | def delete_from_file ( file_path ) client_setup resource = OneviewSDK :: Resource . from_file ( @client , file_path ) fail_nice ( "#{resource.class.name.split('::').last} '#{resource[:name] || resource[:uri]}' Not Found" , 2 ) unless resource . retrieve! return unless options [ 'force' ] || agree ( "Delete '#{resource[... | Delete resource defined in file |
12,332 | def to_file ( type , name ) file = File . expand_path ( options [ 'path' ] ) resource_class = parse_type ( type ) client_setup resource = resource_class . find_by ( @client , name : name ) . first fail_nice "#{resource_class.name.split('::').last} '#{name}' not found" unless resource resource . to_file ( file , options... | Save resource details to file |
12,333 | def cert ( type , url = ENV [ 'ONEVIEWSDK_URL' ] ) case type . downcase when 'check' fail_nice 'Must specify a url' unless url puts "Checking certificate for '#{url}' ..." if OneviewSDK :: SSLHelper . check_cert ( url ) puts 'Certificate is valid!' else fail_nice 'Certificate Validation Failed!' end when 'import' fail_... | Check import or list OneView certs |
12,334 | def scmb client_setup connection = OneviewSDK :: SCMB . new_connection ( @client ) q = OneviewSDK :: SCMB . new_queue ( connection , @options [ 'route' ] ) puts 'Subscribing to OneView messages. To exit, press Ctrl + c' q . subscribe ( block : true ) do | _delivery_info , _properties , payload | data = JSON . parse ( p... | Subscribe to the OneView SCMB |
12,335 | def parse_type ( type ) api_ver = ( @options [ 'api_version' ] || ENV [ 'ONEVIEWSDK_API_VERSION' ] || OneviewSDK . api_version ) . to_i unless OneviewSDK :: SUPPORTED_API_VERSIONS . include? ( api_ver ) valid_api_ver = OneviewSDK :: SUPPORTED_API_VERSIONS . select { | x | x <= api_ver } . max || OneviewSDK :: SUPPORTED... | Get resource class from given string |
12,336 | def select_attributes ( attributes , data = { } ) attributes = attributes . split ( ',' ) . map ( & :strip ) . reject ( & :empty? ) . map { | a | a . split ( '.' ) } if attributes . is_a? ( String ) r_data = data . is_a? ( Hash ) ? data : data . data temp = { } attributes . each do | attr | temp_level = temp attr = [ a... | Select a subset of attributes from a given resource |
12,337 | def select_attributes_from_multiple ( attributes , data = [ ] ) attributes = attributes . split ( ',' ) . map ( & :strip ) . reject ( & :empty? ) . map { | a | a . split ( '.' ) } if attributes . is_a? ( String ) result = [ ] data . each do | r | result . push ( r [ 'name' ] => select_attributes ( attributes , r ) ) en... | Select a subset of attributes from a given set of resources |
12,338 | def get_all ( type , api_ver = @api_version , variant = nil ) klass = OneviewSDK . resource_named ( type , api_ver , variant ) raise TypeError , "Invalid resource type '#{type}'. OneviewSDK::API#{api_ver} does not contain a class like it." unless klass klass . get_all ( self ) end | Get array of all resources of a specified type |
12,339 | def wait_for ( task_uri ) raise ArgumentError , 'Must specify a task_uri!' if task_uri . nil? || task_uri . empty? loop do task_uri . gsub! ( %r{ \/ } , '/rest' ) task = rest_get ( task_uri ) body = JSON . parse ( task . body ) case body [ 'taskState' ] . downcase when 'completed' return body when 'warning' @logger . w... | Wait for a task to complete |
12,340 | def appliance_api_version options = { 'Content-Type' => :none , 'X-API-Version' => :none , 'auth' => :none } response = rest_api ( :get , '/rest/version' , options ) version = response_handler ( response ) [ 'currentVersion' ] raise ConnectionError , "Couldn't get API version" unless version version = version . to_i if... | Get current api version from the OneView appliance |
12,341 | def login ( retries = 2 ) options = { 'body' => { 'userName' => @user , 'password' => @password , 'authLoginDomain' => @domain } } response = rest_post ( '/rest/login-sessions' , options ) body = response_handler ( response ) return body [ 'sessionID' ] if body [ 'sessionID' ] raise ConnectionError , "\nERROR! Couldn't... | Log in to OneView appliance and return the session token |
12,342 | def rest_api ( type , path , options = { } , api_ver = @api_version , redirect_limit = 3 ) @logger . debug "Making :#{type} rest call to #{@url}#{path}" raise InvalidRequest , 'Must specify path' unless path uri = URI . parse ( Addressable :: URI . escape ( @url + path ) ) http = build_http_object ( uri ) request = bui... | in seconds 5 minutes Makes a restful API request to OneView |
12,343 | def upload_file ( file_path , path , options = { } , timeout = READ_TIMEOUT ) raise NotFound , "ERROR: File '#{file_path}' not found!" unless File . file? ( file_path ) options = Hash [ options . map { | k , v | [ k . to_s , v ] } ] body_params = options [ 'body' ] || { } headers_params = options [ 'header' ] || { } he... | Uploads a file to a specific uri |
12,344 | def download_file ( path , local_drive_path ) uri = URI . parse ( Addressable :: URI . escape ( @url + path ) ) http_request = build_http_object ( uri ) req = build_request ( :get , uri , { } , @api_version . to_s ) http_request . start do | http | http . request ( req ) do | res | response_handler ( res ) unless res .... | Download a file from a specific uri |
12,345 | def response_handler ( response , wait_on_task = true ) case response . code . to_i when RESPONSE_CODE_OK begin return JSON . parse ( response . body ) rescue JSON :: ParserError => e @logger . warn "Failed to parse JSON response. #{e}" return response . body end when RESPONSE_CODE_CREATED JSON . parse ( response . bod... | Handles the response from a rest call . If an asynchronous task was started this waits for it to complete . |
12,346 | def build_http_object ( uri ) http = Net :: HTTP . new ( uri . host , uri . port ) http . use_ssl = true if uri . scheme == 'https' if @ssl_enabled http . cert_store = @cert_store if @cert_store else http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE end http . read_timeout = @timeout if @timeout http . open_timeout = ... | Builds a http object using the data given |
12,347 | def build_request ( type , uri , options , api_ver ) case type . downcase . to_sym when :get request = Net :: HTTP :: Get . new ( uri . request_uri ) when :post request = Net :: HTTP :: Post . new ( uri . request_uri ) when :put request = Net :: HTTP :: Put . new ( uri . request_uri ) when :patch request = Net :: HTTP ... | Builds a request object using the data given |
12,348 | def doorkeeper_authorize! ( * scopes ) scopes = Doorkeeper . configuration . default_scopes if scopes . empty? unless valid_doorkeeper_token? ( * scopes ) if ! doorkeeper_token || ! doorkeeper_token . accessible? error = Doorkeeper :: OAuth :: InvalidTokenResponse . from_access_token ( doorkeeper_token ) raise WineBoun... | This method handles the authorization raises errors if authorization has failed . |
12,349 | def exists? ( header = self . class :: DEFAULT_REQUEST_HEADER ) retrieval_keys = self . class :: UNIQUE_IDENTIFIERS . reject { | k | @data [ k ] . nil? } raise IncompleteResource , "Must set resource #{self.class::UNIQUE_IDENTIFIERS.join(' or ')} before trying to retrieve!" if retrieval_keys . empty? retrieval_keys . e... | Check if a resource exists |
12,350 | def deep_merge! ( other_data , target_data = @data ) raise 'Both arguments should be a object Hash' unless other_data . is_a? ( Hash ) && target_data . is_a? ( Hash ) other_data . each do | key , value | value_target = target_data [ key . to_s ] if value_target . is_a? ( Hash ) && value . is_a? ( Hash ) deep_merge! ( v... | Merges the first hash data structure with the second |
12,351 | def set_all ( params = self . class :: DEFAULT_REQUEST_HEADER ) params = params . data if params . class <= Resource params = Hash [ params . map { | ( k , v ) | [ k . to_s , v ] } ] params . each { | key , value | set ( key . to_s , value ) } self end | Set the given hash of key - value pairs as resource data attributes |
12,352 | def set ( key , value ) method_name = "validate_#{key}" send ( method_name . to_sym , value ) if respond_to? ( method_name . to_sym ) @data [ key . to_s ] = value end | Set a resource attribute with the given value and call any validation method if necessary |
12,353 | def create ( header = self . class :: DEFAULT_REQUEST_HEADER ) ensure_client options = { } . merge ( header ) . merge ( 'body' => @data ) response = @client . rest_post ( self . class :: BASE_URI , options , @api_version ) body = @client . response_handler ( response ) set_all ( body ) self end | Create the resource on OneView using the current data |
12,354 | def create! ( header = self . class :: DEFAULT_REQUEST_HEADER ) temp = self . class . new ( @client , @data ) temp . delete ( header ) if temp . retrieve! ( header ) create ( header ) end | Delete the resource from OneView if it exists then create it using the current data |
12,355 | def refresh ( header = self . class :: DEFAULT_REQUEST_HEADER ) ensure_client && ensure_uri response = @client . rest_get ( @data [ 'uri' ] , header , @api_version ) body = @client . response_handler ( response ) set_all ( body ) self end | Updates this object using the data that exists on OneView |
12,356 | def update ( attributes = { } , header = self . class :: DEFAULT_REQUEST_HEADER ) set_all ( attributes ) ensure_client && ensure_uri options = { } . merge ( header ) . merge ( 'body' => @data ) response = @client . rest_put ( @data [ 'uri' ] , options , @api_version ) @client . response_handler ( response ) self end | Set data and save to OneView |
12,357 | def delete ( header = self . class :: DEFAULT_REQUEST_HEADER ) ensure_client && ensure_uri response = @client . rest_delete ( @data [ 'uri' ] , header , @api_version ) @client . response_handler ( response ) true end | Delete resource from OneView |
12,358 | def to_file ( file_path , format = :json ) format = :yml if %w[ .yml .yaml ] . include? File . extname ( file_path ) temp_data = { type : self . class . name , api_version : @api_version , data : @data } case format . to_sym when :json File . open ( file_path , 'w' ) { | f | f . write ( JSON . pretty_generate ( temp_da... | Save resource to json or yaml file |
12,359 | def recursive_like? ( other , data = @data ) raise "Can't compare with object type: #{other.class}! Must respond_to :each" unless other . respond_to? ( :each ) other . each do | key , val | return false unless data && data . respond_to? ( :[] ) if val . is_a? ( Hash ) return false unless data . class == Hash && recursi... | Recursive helper method for like? Allows comparison of nested hash structures |
12,360 | def amount_ok? ( order_amount , order_discount = BigDecimal . new ( '0.0' ) ) BigDecimal . new ( gross ) == order_amount && BigDecimal . new ( discount . to_s ) == order_discount end | Order amount should be equal to gross - discount |
12,361 | def payment_form_for_payu ( key , salt , options = { } ) if ! options . is_a? ( Hash ) || ! key . is_a? ( String ) || ! salt . is_a? ( String ) concat ( "Something Wrong! params order -> key (String), salt (String), options (Hash) " ) nil else form_options = options . delete ( :html ) || { } service = PayuIndia :: Help... | This Helper creates form with all parameters added . |
12,362 | def template ( src , context = binding ) eruby = Erubis :: Eruby . new ( src ) eruby . result ( context ) rescue Object => e raise Sprinkle :: Errors :: TemplateError . new ( e , src , context ) end | render src as ERB |
12,363 | def render ( filename , context = binding ) contents = File . read ( expand_filename ( filename ) ) template ( contents , context ) end | read in filename and render it as ERB |
12,364 | def load_from_id ( gid , pid ) @gid = gid @pid = pid @position = 'P' @xml_data = GamedayFetcher . fetch_pitcher ( gid , pid ) @xml_doc = REXML :: Document . new ( @xml_data ) @team_abbrev = @xml_doc . root . attributes [ "team" ] @first_name = @xml_doc . root . attributes [ "first_name" ] @last_name = @xml_doc . root .... | Loads a Pitcher object given a game id and a player id |
12,365 | def get_all_starts ( year ) results = [ ] app = get_all_appearances ( year ) if app . start == true results << app end end | Returns an array of PitchingAppearance objects for all of the pitchers starts |
12,366 | def get_vs_ab results = [ ] abs = get_game . get_atbats abs . each do | ab | if ab . pitcher_id == @pid results << ab end end results end | Returns an array of the atbats against this pitcher during this game |
12,367 | def get_pitches results = [ ] ab = get_vs_ab ab . each do | ab | results << ab . pitches end results . flatten end | Returns an array of pitches thrown by this pitcher during this game |
12,368 | def load_from_id ( gid ) @gid = gid @xml_data = GamedayFetcher . fetch_boxscore ( gid ) @xml_doc = REXML :: Document . new ( @xml_data ) if @xml_doc . root @game = Game . new ( @gid ) @game . boxscore = self set_basic_info @linescore = LineScore . new @linescore . init ( @xml_doc . root . elements [ "linescore" ] ) @ho... | Loads the boxscore XML from the MLB gameday server and parses it using REXML |
12,369 | def to_html ( template_filename ) gameday_info = GamedayUtil . parse_gameday_id ( 'gid_' + gid ) template = ERB . new File . new ( File . expand_path ( File . dirname ( __FILE__ ) + "/" + template_filename ) ) . read , nil , "%" return template . result ( binding ) end | Converts the boxscore into a formatted HTML representation . Relies on the boxscore . html . erb template for describing the layout |
12,370 | def set_basic_info @game_id = @xml_doc . root . attributes [ "game_id" ] @game_pk = @xml_doc . root . attributes [ "game_pk" ] @home_sport_code = @xml_doc . root . attributes [ "home_sport_code" ] @away_team_code = @xml_doc . root . attributes [ "away_team_code" ] @home_team_code = @xml_doc . root . attributes [ "home_... | Retrieves basic game data from the XML root element and sets in object |
12,371 | def set_pitchers @pitchers , away_pitchers , home_pitchers = [ ] , [ ] , [ ] count = 1 @xml_doc . elements . each ( "boxscore/pitching[@team_flag='away']/pitcher" ) { | element | pitcher = PitchingAppearance . new pitcher . init ( @gid , element , count ) count += 1 away_pitchers . push pitcher } count = 1 @xml_doc . e... | Sets an array of hashes where each hash holds data for a pitcher whom appeared in the game . Specify either home or away team pitchers . |
12,372 | def set_batters @batters , away_batters , home_batters = [ ] , [ ] , [ ] @xml_doc . elements . each ( "boxscore/batting[@team_flag='away']/batter" ) { | element | batter = BattingAppearance . new batter . init ( element ) away_batters . push batter } @xml_doc . elements . each ( "boxscore/batting[@team_flag='home']/bat... | Sets an array of hashes where each hash holds data for a batter whom appeared in the game . Specify either home or away team batters . |
12,373 | def all_games ( year ) if ! @games puts 'Finding all games for team...' results = [ ] ( START_MONTH .. END_MONTH ) . each do | month | puts "Month: " + month . to_s month_s = GamedayUtil . convert_digit_to_string ( month ) ( 1 .. 31 ) . each do | date | if ! GamedayUtil . is_date_valid ( month , date ) next end date_s ... | Returns an array of all games for this team for the specified season |
12,374 | def all_home_games ( year ) games = all_games ( year ) results = games . select { | g | g . home_team_abbrev == @abrev } end | Returns an array of all home games for this team for the specified season |
12,375 | def all_away_games ( year ) games = all_games ( year ) results = games . select { | g | g . visit_team_abbrev == @abrev } end | Returns an array of all away games for this team for the specified season |
12,376 | def games_for_date ( year , month , day ) games_page = GamedayFetcher . fetch_games_page ( year , month , day ) gids = find_gid_for_date ( year , month , day , games_page ) if gids results = gids . collect { | gid | Game . new ( gid ) } else results = nil end results end | Returns an array of the team s game objects for the date passed in . |
12,377 | def get_leadoff_hitters_by_year ( year ) results = [ ] games = all_games ( year ) games . each do | game | boxscore = game . get_boxscore leadoffs = boxscore . get_leadoff_hitters if game . home_team_abbrev == @abrev results << leadoffs [ 1 ] else results << leadoffs [ 0 ] end end results end | Returns an array of BattingAppearance containing the leadoff hitters for each game of the specified season . |
12,378 | def get_leadoff_hitters_unique ( year ) hitters = get_leadoff_hitters_by_year ( year ) h = { } hitters . each { | hitter | h [ hitter . batter_name ] = hitter } h . values end | Returns an array of BattingAppearance of all hitters who have led off at least one game during the specified season |
12,379 | def get_cleanup_hitters_by_year ( year ) results = [ ] games = all_games ( year ) games . each do | game | boxscore = game . get_boxscore hitters = boxscore . get_cleanup_hitters if game . home_team_abbrev == @abrev results << hitters [ 1 ] else results << hitters [ 0 ] end end results end | Returns an array containing the cleanup hitters for each game of the specified season . The cleanup hitter is the 4th hitter in the batting order |
12,380 | def get_starters_unique ( year ) pitchers = get_start_pitcher_appearances_by_year ( year ) h = { } pitchers . each { | pitcher | h [ pitcher . pitcher_name ] = pitcher } h . values end | Returns an array of all pitchers who have started at least one game during the specified season |
12,381 | def get_closers_unique ( year ) pitchers = get_close_pitcher_appearances_by_year ( year ) h = { } pitchers . each { | pitcher | h [ pitcher . pitcher_name ] = pitcher } h . values end | Returns an array of all pitchers who have closed at least one game during the specified season |
12,382 | def quality_starts_count ( year ) count = 0 games = all_games ( year ) games . each do | game | starters = game . get_starting_pitchers if game . home_team_abbrev == @abrev if starters [ 1 ] . quality_start? count = count + 1 end else if starters [ 0 ] . quality_start? count = count + 1 end end end count end | Returns a count of the number of quality starts for this team for the specified year . |
12,383 | def get_opening_day_game ( year ) schedule = Schedule . new ( year ) oday = schedule . get_opening_day oday_array = GamedayUtil . parse_date_string ( oday ) games = games_for_date ( oday_array [ 0 ] , oday_array [ 1 ] , oday_array [ 2 ] ) if games [ 0 ] == nil games = games_for_date ( oday_array [ 0 ] , oday_array [ 1 ... | Returns a game object representing the opening day game for this team for the season passed in . |
12,384 | def opening_day_roster ( year ) game = get_opening_day_game ( year ) rosters = game . get_rosters rosters [ 0 ] . team_name == city + ' ' + name ? rosters [ 0 ] : rosters [ 1 ] end | Returns a Roster object representing the opening day roster for this team for the specified year . |
12,385 | def get_all_gids_for_date ( year , month , day ) begin gids = [ ] url = GamedayUtil . build_day_url ( year , month , date ) connection = GamedayUtil . get_connection ( url ) if connection @hp = Hpricot ( connection ) a = @hp . at ( 'ul' ) ( a / "a" ) . each do | link | if link . inner_html . include? ( 'gid' ) str = li... | Returns an array of game id s for the given date |
12,386 | def load_from_id ( gid , pid ) @gid = gid @pid = pid @xml_data = GamedayFetcher . fetch_players ( gid ) @xml_doc = REXML :: Document . new ( @xml_data ) pelement = @xml_doc . root . elements [ "team/player[@id=#{pid}]" ] init ( pelement , gid ) end | Initializes a Player object by reading the player data from the players . xml file for the player specified by game id and player id . |
12,387 | def init_pitcher_from_scoreboard ( element ) @first = element . attributes [ 'first' ] @last = element . attributes [ 'last' ] @wins = element . attributes [ 'wins' ] @losses = element . attributes [ 'losses' ] @era = element . attributes [ 'era' ] end | Initializes pitcher info from data read from the masterscoreboard . xml file |
12,388 | def at_bats_count gameday_info = GamedayUtil . parse_gameday_id ( @gid ) appearances = get_all_appearances ( gameday_info [ "year" ] ) count = appearances . inject ( 0 ) { | sum , a | sum + a . ab . to_i } end | Returns the number of at bats over the entire season for this player |
12,389 | def init ( element , gid ) @gid = gid @pid = element . attributes [ 'id' ] @first = element . attributes [ 'first' ] @last = element . attributes [ 'last' ] @num = element . attributes [ 'num' ] @boxname = element . attributes [ 'boxname' ] @rl , = element . attributes [ 'rl' ] @position = element . attributes [ 'posit... | Initialize a player object by reading data from the players . xml file |
12,390 | def download_all_for_game ( gid ) download_xml_for_game ( gid ) download_batters_for_game ( gid ) download_inning_for_game ( gid ) download_media_for_game ( gid ) download_notification_for_game ( gid ) download_onbase_for_game ( gid ) download_pitchers_for_game ( gid ) end | Downloads all data files associated with the game specified by the game id passed in . |
12,391 | def write_file ( file_path , gd_data ) if gd_data && ! File . exists? ( file_path ) FileUtils . mkdir_p ( File . dirname ( file_path ) ) File . open ( file_path , "wb" ) do | data | data << gd_data end end end | Writes the gameday data to the file specified . Does not overwrite existing files . |
12,392 | def load_from_scoreboard ( element ) @away_innings = [ ] @home_innings = [ ] @scoreboard_game_id = element . attributes [ 'id' ] @ampm = element . attributes [ 'ampm' ] @venue = element . attributes [ 'venue' ] @game_pk = element . attributes [ 'game_pk' ] @time = element . attributes [ 'time' ] @time_zone = element . ... | Setup a Game object from data read from the master_scoreboard . xml file |
12,393 | def set_status ( element ) element . elements . each ( "status" ) { | status | @status = GameStatus . new @status . status = status . attributes [ 'status' ] @status . ind = status . attributes [ 'ind' ] @status . reason = status . attributes [ 'reason' ] @status . inning = status . attributes [ 'inning' ] @status . to... | Sets the game status from data in the master_scoreboard . xml file |
12,394 | def set_innings ( element ) element . elements . each ( "linescore/inning" ) { | element | @away_innings << element . attributes [ 'away' ] @home_innings << element . attributes [ 'home' ] } end | Sets the away and home innings array containing scores by inning from data in the master_scoreboard . xml file |
12,395 | def set_homeruns ( element ) @homeruns = [ ] element . elements . each ( "home_runs/player" ) do | hr | player = Player . new player . last = hr . attributes [ 'last' ] player . first = hr . attributes [ 'first' ] player . hr = hr . attributes [ 'hr' ] player . std_hr = hr . attributes [ 'std_hr' ] player . team_code =... | Sets a list of players who had homeruns in this game from data in the master_scoreboard . xml file |
12,396 | def get_pitchers ( home_or_away ) if self . gid bs = get_boxscore if home_or_away == 'away' bs . pitchers [ 0 ] else bs . pitchers [ 1 ] end else puts "No data for input specified" end end | Returns an array of all pitchers for either the home team or the away team . The values in the returned array are PitchingAppearance instances |
12,397 | def get_pitches ( pid ) results = [ ] atbats = get_atbats atbats . each do | ab | if ab . pitcher_id == pid results << ab . pitches end end results . flatten end | Returns an array of pitches from this game for the pitcher identified by pid |
12,398 | def get_batters ( home_or_away ) if self . gid bs = get_boxscore if home_or_away == 'away' bs . batters [ 0 ] else bs . batters [ 1 ] end else puts "No data for input specified" end end | Returns an array of either home or away batters for this game home_or_away must be a string with value home or away The values in the returned array are BattingAppearance instances |
12,399 | def get_winner ls = get_boxscore . linescore if ls . home_team_runs > ls . away_team_runs return home_team_abbrev else return visit_team_abbrev end end | Returns the team abreviation of the winning team |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.