Class: Ytterb::StockMarketLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/ytterb/stock_symbol_loader.rb

Instance Method Summary collapse

Constructor Details

#initializeStockMarketLoader

Returns a new instance of StockMarketLoader.



49
50
51
52
53
54
55
56
57
58
# File 'lib/ytterb/stock_symbol_loader.rb', line 49

def initialize
  @stock_symbols = []
  path = File.join(File.expand_path(File.dirname(__FILE__)),"raw_symbol_data")
  Dir.entries(path).select {|f| !File.directory?(f) and /companylist_[a-zA-Z]+\.csv/ =~ f }.each do |file_to_process|
    market = /companylist_(?<market>[a-zA-Z]+)\.csv/.match(file_to_process)[:market]
    StockSymbolLoader.new(File.join(path,file_to_process),market).parse do |stock_symbol|
      @stock_symbols << stock_symbol
    end
  end
end

Instance Method Details

#industriesObject



60
61
62
63
64
65
66
67
# File 'lib/ytterb/stock_symbol_loader.rb', line 60

def industries
  return @industries if @industries
  @raw_industries = {}
  @stock_symbols.each do |stock_symbol|
    @raw_industries[stock_symbol.industry] = 1
  end
  @industries = @raw_industries.keys
end

#sectorsObject



69
70
71
72
73
74
75
76
# File 'lib/ytterb/stock_symbol_loader.rb', line 69

def sectors
  return @sectors if @sectors
  @raw_sectors = {}
  @stock_symbols.each do |stock_symbol|
    @raw_sectors[stock_symbol.sector] = 1
  end
  @sectors = @raw_sectors.keys
end

#stock_symbolsObject



78
79
80
# File 'lib/ytterb/stock_symbol_loader.rb', line 78

def stock_symbols
  @stock_symbols
end