Class: YahooStock::ScripSymbol

Inherits:
Base
  • Object
show all
Defined in:
lib/yahoo_stock/scrip_symbol.rb

Overview

DESCRIPTION:

This class provides the ability to find out the stock /scrip symbols for a company used in stock exchanges.

It uses Yahoo finance.yahoo.com/lookup page to find, screen scrape / parse the returned results.

USAGE:

  • If you want to use the symbols in your existing code then:

    symbol = YahooStock::ScripSymbol.new('company name')
    
    symbol.find #will return a string
    
    symbol.results :to_array, #will return an array of values instead of a string
    

will give you an array of arrays where each outer array is the different option for the company name you provided and the inner array includes stock symbol, full company name, stock price, exchange symbol so that you can decide easily what symbol you can use.

  • If you just want to print the results on your console screen

    YahooStock::ScripSymbol.print_options('company name')
    
  • If you just want to store the results in file to use it later

You can pass in any number of companies in the parameter

YahooStock::ScripSymbol.save_options_to_file('path/to/filename','company1', 'company2')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#find, #results, #symbols

Constructor Details

#initialize(company_name) ⇒ ScripSymbol

Returns a new instance of ScripSymbol.



41
42
43
44
# File 'lib/yahoo_stock/scrip_symbol.rb', line 41

def initialize(company_name)
  @company = company_name
  @interface = YahooStock::Interface::ScripSymbol.new(@company)
end

Instance Attribute Details

#companyObject

Initialize with the name of the company as parameter for which stock symbol is needed

symbol = YahooStock::ScripSymbol.new('company name')

symbol.find


39
40
41
# File 'lib/yahoo_stock/scrip_symbol.rb', line 39

def company
  @company
end

Class Method Details

.results(*companies) ⇒ Object

get stock symbols for multilple companies



55
56
57
58
# File 'lib/yahoo_stock/scrip_symbol.rb', line 55

def self.results(*companies)
  res = companies.inject('') { |options, company| options + new(company).results.output + "\n" }
  YahooStock::Result.new(res)
end

Instance Method Details

#data_attributesObject



50
51
52
# File 'lib/yahoo_stock/scrip_symbol.rb', line 50

def data_attributes
  ['Symbol', 'Name', 'Last Trade', 'Type', 'Industry Category', 'Exchange']
end