class Psei::Index
Public Class Methods
new(headers={},parser=nil)
click to toggle source
# File lib/psei/index.rb, line 3 def initialize(headers={},parser=nil) @parser = parser || Psei::Parser.new(Psei::SOURCE_URL, headers) @parsed = @parser.process @formatter = Psei::Formatter.new end
Public Instance Methods
date()
click to toggle source
# File lib/psei/index.rb, line 23 def date Psei::Date.new(@parsed).get end
symbols()
click to toggle source
# File lib/psei/index.rb, line 9 def symbols indices_hash.keys end
value(symbol)
click to toggle source
Returns the last value of an index
# File lib/psei/index.rb, line 19 def value symbol index symbol end
values()
click to toggle source
Returns a Hash of last values of indices
# File lib/psei/index.rb, line 14 def values symbols.collect{ |x| value x } end
Private Instance Methods
find_by_symbol(symbol)
click to toggle source
# File lib/psei/index.rb, line 29 def find_by_symbol symbol indices = indices_filter indices.detect{ |s| s['securitySymbol'] == symbol.to_s } end
index(sym)
click to toggle source
# File lib/psei/index.rb, line 50 def index sym ind = indices_filter.select{|x| x['securitySymbol'] == sym }.first @formatter.process ind end
indices_array()
click to toggle source
# File lib/psei/index.rb, line 44 def indices_array @ind_array ||= indices_filter.collect do |item| [item['securitySymbol'], item['lastTradedPrice'].to_f] end end
indices_filter()
click to toggle source
# File lib/psei/index.rb, line 34 def indices_filter @ind_filter ||= @parsed.select do |x| (Psei::INDEX_ALIASES).include?(x['securityAlias']) && x['securitySymbol'] != Psei::HEADING_ALIAS end end
indices_hash()
click to toggle source
# File lib/psei/index.rb, line 40 def indices_hash @ind_hash ||= Hash[indices_array] end