Sha256: e56e6513a0d2ce5cf27b79d5ad572ed279a2382e80859bd7065909e78ca211c2

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class StockIndex

  class Component

    require 'cik'

    def initialize(symbol, market, wikipedia)
      @symbol = symbol
      @market = market
      @wikipedia = wikipedia
    end

    def attributes
      cache_lookup || attributes_lookup
    end

    def valid?
      @market && @symbol
    end

    def cache_lookup
      store = PStore.new('cache/data.pstore')
      store.transaction { store[@symbol] }
    end

    def cache_write(a)
      store = PStore.new('cache/data.pstore')
      store.transaction do
        store[@symbol] = a
      end
      a
    end

    def attributes_lookup
      bsym = StockIndex::BsymSearch.find(@symbol)
      if bsym.nil?
        puts "bsym --> #{@symbol}"
        return
      else
        edgar = Cik.lookup(SymbolParser.new(@symbol).bsym_to_cik)
        if edgar.nil?
          puts "cik --> #{@symbol}"
        else
          a = {market: @market, symbol: @symbol, name: bsym[:name], wikipedia: @wikipedia, cik: edgar[:cik], bbgid: bsym[:bbgid]}
          cache_write(a)
        end
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stock_index-0.6.0 lib/stock_index/component.rb